コード例 #1
0
ファイル: JobsOptions.cs プロジェクト: mylab-task/scheduler
        public static JobOptions FromJobDataMap(JobDataMap map)
        {
            var jobOptions = new JobOptions
            {
                Id   = map.GetString(IdKey),
                Cron = map.GetString(CronKey),
                Host = map.GetString(HostKey),
                Path = map.GetString(PathKey),
                Port = map.GetIntValue(PortKey)
            };

            if (map.TryGetValue(HeadersKey, out var headers))
            {
                var nvc = HttpUtility.ParseQueryString((string)headers);

                var dict = new Dictionary <string, string>();

                foreach (string key in nvc.AllKeys)
                {
                    if (!string.IsNullOrWhiteSpace(key))
                    {
                        dict.Add(key, nvc[key]);
                    }
                }

                jobOptions.Headers = dict;
            }

            return(jobOptions);
        }
コード例 #2
0
ファイル: KickOptions.cs プロジェクト: mylab-task/scheduler
 public KickOptions(JobOptions jobOptions)
 {
     Host = jobOptions.Host;
     Path = jobOptions.Path;
     Port = jobOptions.Port;
     if (jobOptions.Headers != null)
     {
         Headers = new Dictionary <string, string>(jobOptions.Headers);
     }
 }
コード例 #3
0
ファイル: KickTaskJob.cs プロジェクト: mylab-task/scheduler
        public async System.Threading.Tasks.Task Execute(IJobExecutionContext context)
        {
            var opts = JobOptions.FromJobDataMap(context.JobDetail.JobDataMap);

            try
            {
                var kickOptions = new KickOptions(opts);

                var response = await _taskKickerService.KickAsync(kickOptions);

                _logger.Action("Task kicked")
                .AndFactIs("job-id", opts.Id)
                .AndFactIs("task-resp", response)
                .Write();
            }
            catch (Exception e)
            {
                _logger.Error(e)
                .AndFactIs("job-id", opts.Id)
                .Write();
            }
        }
コード例 #4
0
        static void RegisterTaskKickJob(IServiceCollectionQuartzConfigurator configurator, JobOptions jobOptions)
        {
            var jobKey = new JobKey(jobOptions.Id);

            configurator
            .AddJob <KickTaskJob>(c => c
                                  .WithIdentity(jobKey)
                                  .UsingJobData(jobOptions.ToJobDataMap())
                                  )
            .AddTrigger(c => c
                        .ForJob(jobKey)
                        .WithIdentity(jobKey + "-trigger")
                        .WithCronSchedule(jobOptions.Cron)
                        );
        }