Example #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();
                }
        }
Example #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();
                }
        }
        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();
            }
        }