public void Create(CreateTaskInput input) { if (input == null) { Logger.Error($"{nameof(input)} should not be null."); return; } var task = Mapper.Map <Core.Entities.Task>(input); input.ApplicationName = input.ApplicationName.Trim(); input.Arguments = input.Arguments?.Trim(); input.Cron = input.Cron.Trim(); input.Package = input.Package.Trim(); input.Name = input.Name.Trim(); if (input.Cron != Configuration.IngoreCron) { var job = new SchedulerJobDto { Id = task.Id, Name = task.Name, Cron = input.Cron, Url = string.Format(Configuration.SchedulerCallback, task.Id), Data = JsonConvert.SerializeObject(new { TaskId = task.Id }) }; _schedulerAppService.Create(job); } DbContext.Task.Add(task); DbContext.SaveChanges(); }
public void Register() { Domain.Entities.Task scanRunningTask = DbContext.Task.FirstOrDefault(t => t.Name.StartsWith(ScanRunningTaskName)); if (scanRunningTask == null) { scanRunningTask = new Domain.Entities.Task { ApplicationName = "DotnetSpider.Enterprise", Cron = $"0/15 * * * *", IsEnabled = true, IsDeleted = true, Developers = "DotnetSpider", Owners = "DotnetSpider", Arguments = "", NodeCount = 1, NodeRunningCount = 0, Name = ScanRunningTaskName, Version = "0001", NodeType = 1 }; DbContext.Task.Add(scanRunningTask); DbContext.SaveChanges(); } var taskId = scanRunningTask.Id.ToString(); var job = new SchedulerJobDto { Id = taskId, Name = scanRunningTask.Name, Cron = "0/15 * * * *", Url = string.Format(Configuration.SchedulerCallback, taskId), Data = JsonConvert.SerializeObject(new { TaskId = taskId }) }; _schedulerAppService.Create(job); }
/// <summary> /// 添加一个任务 /// </summary> /// <param name="input"></param> public void Create(CreateTaskInput input) { if (input == null) { Logger.Error($"{nameof(input)} should not be null."); return; } //映射到任务对象 var task = Mapper.Map <Core.Entities.Task>(input); input.ApplicationName = input.ApplicationName.Trim(); input.Arguments = input.Arguments?.Trim(); input.Cron = input.Cron.Trim(); input.Package = input.Package.Trim(); input.Name = input.Name.Trim(); //表示要创建议计划? if (input.Cron != Configuration.IngoreCron) { //计划工作 var job = new SchedulerJobDto { Id = task.Id, Name = task.Name, Cron = input.Cron, Url = string.Format(Configuration.SchedulerCallback, task.Id), //设置回调 Content = JsonConvert.SerializeObject(new { TaskId = task.Id }) }; if (!task.Name.StartsWith(job.Group)) { task.Name = $"[{job.Group}]{task.Name}"; } _schedulerAppService.Create(job); //创建计划 } DbContext.Task.Add(task); //添加任务 DbContext.SaveChanges(); }
public void Create(CreateTaskInput input) { if (input == null) { Logger.LogError($"{nameof(input)} should not be null."); return; } var task = Mapper.Map <Domain.Entities.Task>(input); input.ApplicationName = input.ApplicationName.Trim(); input.Arguments = input.Arguments?.Trim(); input.Cron = input.Cron.Trim(); input.Version = input.Version.Trim(); input.Name = input.Name.Trim(); var cron = task.Cron; task.Cron = DotnetSpiderConsts.UnTriggerCron; DbContext.Task.Add(task); DbContext.SaveChanges(); if (cron != DotnetSpiderConsts.UnTriggerCron) { var taskId = task.Id.ToString(); var job = new SchedulerJobDto { Id = taskId, Name = task.Name, Cron = cron, Url = string.Format(Configuration.SchedulerCallback, taskId), Data = JsonConvert.SerializeObject(new { TaskId = taskId }) }; _schedulerAppService.Create(job); task.Cron = cron; 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); } } }