Sync() private method

private Sync ( ) : void
return void
Ejemplo n.º 1
0
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            if (RunCount++ == 0 && !config.OnStartup)
            {
                logger.LogInformation("Task:Sync skipped on startup");
                return;
            }
            logger.LogInformation("Run {RunCount} started", RunCount);

            await update.Sync(config.BatchSize, config.Addons, config.Descriptions, config.Files, config.Changelogs);

            logger.LogInformation("Run {RunCount} finished", RunCount);
        }
        async public Task <IActionResult> GetSync()
        {
            try {
                await Task.Run(() => {});

                var  config       = Config.instance.Value.task.sync;
                int  batchSize    = Request.Query.GetInt("batch").ElementAtOr(0, config.BatchSize);
                bool addons       = Request.Query.GetBool("addons").ElementAtOr(0, config.Addons);
                bool descriptions = Request.Query.GetBool("descriptions").ElementAtOr(0, config.Descriptions);
                bool files        = Request.Query.GetBool("files").ElementAtOr(0, config.Files);
                bool changelogs   = Request.Query.GetBool("changelogs").ElementAtOr(0, config.Changelogs);
                bool gc           = Request.Query.GetBool("gc").ElementAtOr(0, false);

                var task = update.Sync(batchSize, addons, descriptions, files, changelogs, gc);
                if (task == null)
                {
                    return new ContentResult {
                               ContentType = "text/json",
                               StatusCode  = (int)HttpStatusCode.Conflict,
                               Content     = new {
                                   status  = HttpStatusCode.Conflict,
                                   message = "Task:Sync failed to start or so"
                               }.ToPrettyJson()
                    }
                }
                ;
                // await task;
                if (syncTask != null)
                {
                    var oldStatus = syncTask.Status;

                    if (syncTask == task)
                    {
                        return(Json(new { message = "Task:Sync was already running", status = task.Status }));
                    }
                    syncTask = task;
                    return(Json(new { message = "Task:Sync was restarted", status = task.Status, previous = oldStatus }));
                }
                else
                {
                    syncTask = task;
                    return(Json(new { message = "Task:Sync was started", status = task.Status }));
                }
            } catch (Exception e) {
                logger.LogError("{@Exception}", e);
                throw;
            }
        }