예제 #1
0
        private void ErroredWork(string workId, RedisWork <TWork> redisWork)
        {
            using (var redisClient = GetRedisClient())
                using (var redisTransaction = redisClient.CreateTransaction())
                {
                    redisTransaction.QueueCommand(client => client.RemoveItemFromList(_redisWorkerOptions.NamingStrategy.ProcessingName, workId));

                    if (redisWork.RetryCount.Equals(_redisWorkerOptions.Retries))
                    {
                        redisWork.WhenErrored = DateTime.UtcNow;
                        var serializedRedisWork = JsonSerializer.SerializeToString(redisWork);

                        redisTransaction.QueueCommand(client => client.RemoveEntryFromHash(_redisWorkerOptions.NamingStrategy.WorkName, workId));
                        redisTransaction.QueueCommand(client => client.SetEntryInHash(_redisWorkerOptions.NamingStrategy.ErrorName, workId, serializedRedisWork));
                    }
                    else
                    {
                        redisWork.RetryCount++;
                        var serializedRedisWork = JsonSerializer.SerializeToString(redisWork);

                        redisTransaction.QueueCommand(client => client.PushItemToList(_redisWorkerOptions.NamingStrategy.QueueName, workId));
                        redisTransaction.QueueCommand(client => client.SetEntryInHash(_redisWorkerOptions.NamingStrategy.WorkName, workId, serializedRedisWork));
                    }

                    redisTransaction.Commit();
                }
        }
예제 #2
0
        private void CompletedWork(string workId, RedisWork <TWork> redisWork)
        {
            using (var redisClient = GetRedisClient())
                using (var redisTransaction = redisClient.CreateTransaction())
                {
                    redisWork.WhenCompleted = DateTime.UtcNow;
                    var serializedRedisWork = JsonSerializer.SerializeToString(redisWork);

                    redisTransaction.QueueCommand(client => client.RemoveItemFromList(_redisWorkerOptions.NamingStrategy.ProcessingName, workId));
                    redisTransaction.QueueCommand(client => client.RemoveEntryFromHash(_redisWorkerOptions.NamingStrategy.WorkName, workId));

                    if (_redisWorkerOptions.Audit)
                    {
                        redisTransaction.QueueCommand(client => client.SetEntryInHash(_redisWorkerOptions.NamingStrategy.AuditName, workId, serializedRedisWork));
                    }

                    redisTransaction.Commit();
                }
        }
예제 #3
0
        public static void QueueWork <TWork>(this IRedisClient redisClient, TWork work, IRedisWorkerNamingStrategy redisWorkerNamingStrategy)
        {
            var workId = Guid.NewGuid().ToString();

            using (var redisTransaction = redisClient.CreateTransaction())
            {
                var redisWork = new RedisWork <TWork>
                {
                    WhenQueued = DateTime.UtcNow,
                    RetryCount = 0,
                    Work       = work
                };

                var serializedRedisWork = JsonSerializer.SerializeToString(redisWork);

                redisTransaction.QueueCommand(client => client.PushItemToList(redisWorkerNamingStrategy.QueueName, workId));
                redisTransaction.QueueCommand(client => client.SetEntryInHash(redisWorkerNamingStrategy.WorkName, workId, serializedRedisWork));

                redisTransaction.Commit();
            }
        }