Пример #1
0
        public IEnumerable <long> GetEnqueuedJobIds(string queue, int @from, int perPage)
        {
            var messageQueue = MemoryQueueBank.Get(_pathPattern, queue);

            return(messageQueue.Skip(from).Take(perPage).Select(x => long.Parse(x.Value.Label)));

            //var result = new List<long>();

            //var current = 0;
            //var end = from + perPage;

            //foreach (var job in messageQueue.GetConsumingEnumerable(CancellationToken.None))
            //{
            //    if (current >= from && current < end)
            //    {
            //        var message = job;
            //        if (message == null) continue;

            //        result.Add(long.Parse(message.Label));
            //    }

            //    if (current >= end) break;

            //    current++;
            //}

            //return result;
        }
Пример #2
0
        public EnqueuedAndFetchedCountDto GetEnqueuedAndFetchedCount(string queue)
        {
            var messageQueue = MemoryQueueBank.Get(_pathPattern, queue);

            return(new EnqueuedAndFetchedCountDto
            {
                EnqueuedCount = messageQueue.Count()
            });
        }
        public void Enqueue(System.Data.Common.DbConnection connection, System.Data.Common.DbTransaction transaction, string queue, string jobId)
        {
            var messageQueue = MemoryQueueBank.Get(_pathPattern, queue);
            var message      = new MemoryQueueMessage {
                Label = jobId, IsTaking = false
            };

            messageQueue.AddOrUpdate(jobId, message, (key, oldValue) =>
            {
                oldValue.IsTaking = false;
                return(oldValue);
            });
        }
        public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
        {
            var    queueIndex = 0;
            string jobId      = null;

            do
            {
                cancellationToken.ThrowIfCancellationRequested();
                MemoryTransaction transaction = null;

                try
                {
                    var messageQueue = MemoryQueueBank.Get(_pathPattern, queues[queueIndex]);
                    transaction = new MemoryTransaction(messageQueue);

                    MemoryQueueMessage message = queueIndex == queues.Length - 1
                        ? transaction.Receive(SyncReceiveTimeout)
                        : transaction.Receive(ReceiveTimeout);

                    if (message != null)
                    {
                        jobId = message.Label;
                        return(new MemoryFetchedJob(transaction, message.Label));
                    }
                }
                catch (Exception ex)
                {
                    // Receive timeout occurred, we should just switch to the next queue
                }
                finally
                {
                    if (jobId == null)
                    {
                        transaction?.Dispose();
                    }
                }

                queueIndex = (queueIndex + 1) % queues.Length;

                Thread.Sleep(1);
            } while (true);
        }