public static HangfireRecurringScheduledMessageData Create(ConsumeContext <ScheduleRecurringMessage> context, string jobKey) { var message = new HangfireRecurringScheduledMessageData { JobKey = jobKey, StartTime = context.Message.Schedule.StartTime, EndTime = context.Message.Schedule.EndTime }; SetBaseProperties(message, context, context.Message.Destination); return(message); }
public async Task Consume(ConsumeContext <ScheduleRecurringMessage> context) { var jobKey = GetJobKey(context.Message.Schedule.ScheduleId, context.Message.Schedule.ScheduleGroup); var message = HangfireRecurringScheduledMessageData.Create(context, jobKey); var tz = TimeZoneInfo.Local; if (!string.IsNullOrWhiteSpace(context.Message.Schedule.TimeZoneId) && context.Message.Schedule.TimeZoneId != tz.Id) { tz = _timeZoneResolver.GetTimeZoneById(context.Message.Schedule.TimeZoneId); } _recurringJobManager.AddOrUpdate <ScheduleJob>( jobKey, x => x.SendMessage(message, null), context.Message.Schedule.CronExpression, tz); LogContext.Debug?.Log("Scheduled: {Key}", jobKey); }
public async Task SendMessage(HangfireRecurringScheduledMessageData messageData, PerformContext performContext) { try { IPipe <SendContext> sendPipe = CreateMessageContext(messageData, _bus.Address, messageData.JobKey); var endpoint = await _bus.GetSendEndpoint(messageData.Destination).ConfigureAwait(false); var scheduled = new Scheduled(); await endpoint.Send(scheduled, sendPipe, performContext.CancellationToken.ShutdownToken).ConfigureAwait(false); LogContext.Debug?.Log("Schedule Executed: {JobId}, created at: {CreatedAt}, with range: {StartTime}-{EndTime}", performContext.BackgroundJob.Id, performContext.BackgroundJob.CreatedAt, messageData.StartTime, messageData.EndTime); } catch (Exception ex) { LogContext.Error?.Log(ex, "Failed to send scheduled message: {JobId}, created at: {CreatedAt}, destination: {DestinationAddress}", performContext.BackgroundJob.Id, messageData.Destination, performContext.BackgroundJob.CreatedAt); throw new JobPerformanceException("Job Execution exception", ex); } }