示例#1
0
        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
 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
        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();
            }
        }
        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)
                        );
        }