Ejemplo n.º 1
0
        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}");
            }
        }
Ejemplo n.º 2
0
        public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
        {
            int index = 0;

            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();
                lock (syncLock)
                {
                    using (new AzureDocumentDbDistributedLock(dequeueLockKey, defaultLockTimeout, storage))
                    {
                        string queue = queues.ElementAt(index);

                        Entities.Queue data = storage.Client.CreateDocumentQuery <Entities.Queue>(storage.Collections.QueueDocumentCollectionUri, QueryOptions)
                                              .Where(q => q.Name == queue && q.DocumentType == Entities.DocumentTypes.Queue)
                                              .AsEnumerable()
                                              .FirstOrDefault();

                        if (data != null)
                        {
                            storage.Client.DeleteDocumentWithRetriesAsync(data.SelfLink).GetAwaiter().GetResult();
                            return(new FetchedJob(storage, data));
                        }
                    }
                }

                Thread.Sleep(checkInterval);
                index = (index + 1) % queues.Length;
            }
        }
 public FetchedJob(AzureDocumentDbStorage storage, Entities.Queue data)
 {
     this.storage = storage;
     Id           = data.Id;
     JobId        = data.JobId;
     Queue        = data.Name;
     SelfLink     = data.SelfLink;
 }
Ejemplo n.º 4
0
 public void Enqueue(string queue, string jobId)
 {
     Entities.Queue data = new Entities.Queue
     {
         Name  = queue,
         JobId = jobId
     };
     storage.Client.CreateDocumentWithRetriesAsync(storage.Collections.QueueDocumentCollectionUri, data).GetAwaiter().GetResult();
 }
 public void Requeue()
 {
     Entities.Queue data = new Entities.Queue
     {
         Id    = Id,
         Name  = Queue,
         JobId = JobId
     };
     storage.Client.UpsertDocumentAsync(storage.Collections.QueueDocumentCollectionUri, data).GetAwaiter().GetResult();
 }