private void ProcessQueue(string queue, RedisConnection connection)
        {
            // Allowing only one server at a time to process the timed out
            // jobs from the specified queue.
            Logger.DebugFormat("Acquiring the lock for the fetched list of the '{0}' queue...", queue);

            using (RedisLock.Acquire(connection.Redis, _storage.GetRedisKey($"queue:{queue}:dequeued:lock"), _options.FetchedLockTimeout))
            {
                Logger.DebugFormat("Looking for timed out jobs in the '{0}' queue...", queue);

                var jobIds = connection.Redis.ListRange(_storage.GetRedisKey($"queue:{queue}:dequeued"));

                var requeued = 0;

                foreach (var jobId in jobIds)
                {
                    if (RequeueJobIfTimedOut(connection, jobId, queue))
                    {
                        requeued++;
                    }
                }

                if (requeued == 0)
                {
                    Logger.DebugFormat("No timed out jobs were found in the '{0}' queue", queue);
                }
                else
                {
                    Logger.InfoFormat(
                        "{0} timed out jobs were found in the '{1}' queue and re-queued.",
                        requeued,
                        queue);
                }
            }
        }
Пример #2
0
 public override IDisposable AcquireDistributedLock([NotNull] string resource, TimeSpan timeout)
 {
     return(RedisLock.Acquire(Redis, _storage.GetRedisKey(resource), timeout));
 }