Esempio n. 1
0
        public void Update(UpdateTaskInput input)
        {
            if (input == null)
            {
                Logger.Error($"{nameof(input)} should not be null.");
                return;
            }
            var task = DbContext.Task.FirstOrDefault(a => a.Id == input.Id);

            if (task == null)
            {
                throw new Exception("Unfound task.");
            }
            task.Analysts        = input.Analysts?.Trim();
            task.ApplicationName = input.ApplicationName?.Trim();
            task.Arguments       = input.Arguments?.Trim();

            task.Cron        = input.Cron;
            task.Description = input.Description?.Trim();
            task.Developers  = input.Developers?.Trim();

            task.Name             = input.Name?.Trim();
            task.NodeCount        = input.NodeCount;
            task.NodeRunningCount = input.NodeRunningCount;
            task.Os       = input.Os?.Trim();
            task.Owners   = input.Owners?.Trim();
            task.Tags     = input.Tags?.Trim();
            task.NodeType = input.NodeType;
            task.Package  = input.Package?.Trim();
            task.IsSingle = input.IsSingle;

            if (!input.IsEnabled && task.IsEnabled && task.Cron == Configuration.IngoreCron)
            {
                _schedulerAppService.Delete(task.Id.ToString());
            }

            if (input.IsEnabled)
            {
                var taskId = task.Id.ToString();
                var job    = new SchedulerJobDto
                {
                    Id      = taskId,
                    Name    = task.Name,
                    Cron    = task.Cron,
                    Url     = string.Format(Configuration.SchedulerCallback, taskId),
                    Content = JsonConvert.SerializeObject(new { TaskId = taskId })
                };

                if (!task.Name.StartsWith(job.Group))
                {
                    task.Name = $"[{job.Group}]{task.Name}";
                }

                _schedulerAppService.Update(job);
            }

            task.IsEnabled = input.IsEnabled;
            DbContext.Task.Update(task);
            DbContext.SaveChanges();
        }
 public void UpgradeScheduler()
 {
     foreach (var task in DbContext.Task)
     {
         if (task.Cron == Configuration.IngoreCron)
         {
             _schedulerAppService.Delete(task.Id.ToString());
         }
         else
         {
             var taskId = task.Id.ToString();
             var job    = new SchedulerJobDto
             {
                 Id   = taskId,
                 Name = task.Name,
                 Cron = task.Cron,
                 Url  = string.Format(Configuration.SchedulerCallback, taskId),
                 Data = JsonConvert.SerializeObject(new { TaskId = taskId })
             };
             _schedulerAppService.Create(job);
         }
     }
 }