Esempio n. 1
0
        public void Schedule(HandlerRequestBase message, Guid jobId, string cron)
        {
            var job = _dbContext.JobRequest.FirstOrDefault(f => f.Id == jobId);

            if (job.IsNull())
            {
                job = new JobRequest
                {
                    Id   = jobId,
                    Body = JsonConvert.SerializeObject(message, new JsonSerializerSettings()
                    {
                        TypeNameHandling = TypeNameHandling.All
                    }),
                    Type = "RecurringJob",
                    Cron = cron
                };
                _dbContext.JobRequest.Add(job);
            }
            else
            {
                job.Body = JsonConvert.SerializeObject(message, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.All
                });
                job.Cron = cron;
            }

            _dbContext.SaveChanges();
            RecurringJob.AddOrUpdate(job.Id.ToString(), () => Excute(job.Id), cron);
        }
Esempio n. 2
0
        public void Queue(HandlerRequestBase message)
        {
            var jobRequest = new JobRequest
            {
                Id   = Guid.NewGuid(),
                Body = JsonConvert.SerializeObject(message, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.All
                }),
                Type = "BackgroundJob",
            };

            _dbContext.JobRequest.Add(jobRequest);
            _dbContext.SaveChanges();
            BackgroundJob.Enqueue <JobHandler>(m => m.Excute(jobRequest.Id));
        }