Example #1
0
        public string QueueHangfireRecurringJob(RecurringJobRequest request)
        {
            var recurringJobId = Guid.NewGuid().ToString();

            try
            {
                if (!string.IsNullOrEmpty(request.Schedule))
                {
                    request.Validate();
                    log.LogDebug($"Job request validated, starting a new job {JsonConvert.SerializeObject(request)}");
                    RecurringJob.AddOrUpdate(recurringJobId, () => RunHangfireJob(jobManager.GetJobName(request.JobUid), request, false, null, null), request.Schedule, queue: QUEUE_NAME);
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex, $"Can't start scheduled job as the request is invalid");
                return("");
            }
            return(recurringJobId);
        }
Example #2
0
        public ScheduleJobResult RunRecurringJob([FromBody] RecurringJobRequest request)
        {
            Log.LogInformation($"{nameof(RunRecurringJob)}: {JsonConvert.SerializeObject(request)}");
            request.Validate();
            string hangfireJobId;

            try
            {
                hangfireJobId = RecurringJobRunner.QueueHangfireRecurringJob(request);
            }
            catch (Exception e)
            {
                Log.LogError(e, $"Queue VSS job failed with exception {e.Message}");
                throw;
            }

            //Hangfire will substitute a PerformContext automatically
            return(new ScheduleJobResult {
                JobId = hangfireJobId
            });
        }