/// <inheritdoc />
        public void Complete(Guid taskId, DateTime timestampUtc)
        {
            Trace.WriteLine("ENTER: Record task '{0}' completed ...".FormatInvariant(taskId));

            string taskIdAsString = RedisConverter.ToString(taskId);

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskIdAsString);

            RedisTaskRuntimeInfo taskInfo = this.GetById(taskId, false);

            taskInfo.Percentage   = 100;
            taskInfo.Status       = TaskStatus.Success;
            taskInfo.CompletedUtc = timestampUtc;

            byte[] content = this.serializer.Serialize(taskInfo);

            using (IRedisTransaction transaction = this.Provider.CreateTransaction())
            {
                transaction.RemoveKey(entityKey);
                transaction.RemoveFromList(RedisTaskRuntimeInfoRepository.ActiveTasksList, taskIdAsString);
                transaction.SetHashValue(RedisTaskRuntimeInfoRepository.ArchiveTasksHash, taskIdAsString, content);

                transaction.Commit();
            }

            Trace.WriteLine("EXIT: Task '{0}' completed recorded.".FormatInvariant(taskId));
        }
        /// <inheritdoc />
        public void Fail(Guid taskId, DateTime timestampUtc, Exception error)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            Trace.WriteLine("ENTER: Record task '{0}' failed with error '{1}' ...".FormatInvariant(taskId, error.Message));

            string taskIdAsString = RedisConverter.ToString(taskId);

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskIdAsString);

            RedisTaskRuntimeInfo taskInfo = this.GetById(taskId, false);

            taskInfo.Status       = TaskStatus.Failed;
            taskInfo.CompletedUtc = timestampUtc;
            taskInfo.Error        = error.ToString();

            byte[] content = this.serializer.Serialize(taskInfo);

            using (IRedisTransaction transaction = this.Provider.CreateTransaction())
            {
                transaction.RemoveKey(entityKey);
                transaction.RemoveFromList(RedisTaskRuntimeInfoRepository.ActiveTasksList, taskIdAsString);
                transaction.AddToList(RedisTaskRuntimeInfoRepository.FailedTasksList, taskIdAsString);
                transaction.SetHashValue(RedisTaskRuntimeInfoRepository.ArchiveTasksHash, taskIdAsString, content);

                transaction.Commit();
            }

            Trace.WriteLine("EXIT: Task '{0}' failed with error '{1}' recorded.".FormatInvariant(taskId, error.Message));
        }
Beispiel #3
0
        /// <inheritdoc />
        public void Update(ITaskProcessorRuntimeInfo taskProcessorInfo)
        {
            if (taskProcessorInfo == null)
            {
                throw new ArgumentNullException("taskProcessorInfo");
            }

            Trace.WriteLine("ENTER: Updating {0} ...".FormatInvariant(taskProcessorInfo));

            string entityKey = RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(taskProcessorInfo.TaskProcessorId);

            IReadOnlyDictionary <string, string> values = RedisTaskProcessorRuntimeInfoRepository.Serialize(taskProcessorInfo);

            using (IRedisTransaction transaction = this.provider.CreateTransaction())
            {
                transaction.RemoveKey(entityKey);

                transaction.SetHashValues(entityKey, values);

                if (this.expiration < TimeSpan.MaxValue)
                {
                    transaction.ExpireKeyIn(entityKey, this.expiration);
                }

                transaction.Commit();
            }

            Trace.WriteLine("EXIT: {0} updated.".FormatInvariant(taskProcessorInfo));
        }
Beispiel #4
0
        /// <inheritdoc />
        public void Delete(Guid taskProcessorId)
        {
            string entityKey = RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(taskProcessorId);

            using (IRedisTransaction transaction = this.provider.CreateTransaction())
            {
                transaction.RemoveFromSet(RedisTaskProcessorRuntimeInfoRepository.EntitySetKey, RedisConverter.ToString(taskProcessorId));

                transaction.RemoveKey(entityKey);

                transaction.Commit();
            }
        }