public void Execute(SlashCommand command) { try { Entities.Merge merge = Slack.MessageParser.ForMerge(command); merge.Verify(); Entities.Queue queue = new Entities.Queue() { MaxWokers = 1, Name = merge.Target }; queueBLL.Insert(queue); long enqueuedCount = Hangfire.JobStorage.Current.GetMonitoringApi().EnqueuedCount(queue.Name); IBackgroundJobClient client = new BackgroundJobClient(); IState state = new EnqueuedState(queue.Name); client.Create<BusinessLogic.Merge.Base.ITrigger>(x => x.Execute(command), state); if(enqueuedCount > 0) { slackBLL.DirectMessage(command, $"There {(enqueuedCount > 1 ? "are" : "is")} {enqueuedCount} {(enqueuedCount > 1 ? "merges" : "merge")} ahead of yours."); } } catch(ArgumentException ex) { slackBLL.DirectMessage(command, $"Failed to schedule merge: {ex.Message}"); } }
public void CreateInEnqueuedState() { #region EnqueuedState #1 var client = new BackgroundJobClient(); var state = new EnqueuedState("critical"); // Use the "critical" queue client.Create(() => Console.WriteLine("Hello!"), state); #endregion }
public void CreateInScheduledState() { #region ScheduledState var client = new BackgroundJobClient(); var state = new ScheduledState(TimeSpan.FromHours(2)); client.Create(() => Console.WriteLine("Hello!"), state); #endregion }