Example #1
0
 public Worker(ILogger <Worker> logger, IOptions <WorkerSchedulerConfiguration> options, ISchedulerFactory schedulerFactory, IJobFactory jobFactory)
 {
     _logger           = logger;
     _schedulerFactory = schedulerFactory;
     _configuration    = options.Value;
     _jobFactory       = jobFactory;
 }
Example #2
0
        private static IReadOnlyDictionary <IJobDetail, IReadOnlyCollection <ITrigger> > GetJobsAndTriggers(WorkerSchedulerConfiguration cfg)
        {
            var dictionary = new Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> >();

            foreach (var job in cfg.Jobs)
            {
                JobDataMap data = new JobDataMap();
                data["apiUrl"]     = cfg.ApiUrl;
                data["requestUrl"] = job.Url;


                IJobDetail jobDetail = JobBuilder
                                       .Create <WorkerJob>()
                                       .WithIdentity($"Job{job.Id}")
                                       .SetJobData(data)
                                       .Build();

                ITrigger everydayTrigger = TriggerBuilder
                                           .Create()
                                           .WithIdentity($"TriggerForJob{job.Id}")
                                           // fires
                                           .WithCronSchedule(job.CronTemplate)
                                           .StartNow()
                                           .Build();

                dictionary.Add(jobDetail, new Collection <ITrigger>(new[] { everydayTrigger }));
            }

            return(dictionary);
        }