Exemplo n.º 1
0
        public Task Timeout(ScheduledTaskTimeout state, IMessageHandlerContext context)
        {
            MarkAsComplete();
            if (Data.TimeoutIdentifier != state.Identifier)
            {
                return(Task.CompletedTask);
            }
            ;

            var scheduledTask = GetScheduledTask(state.TaskTypeFullName);

            //zombie timeout, no scheduled task matches the timer's task
            if (null == scheduledTask)
            {
                MarkAsComplete(); return(Task.CompletedTask);
            }

            //zombie timeout, scheduled task is not enabled to run
            if (!scheduledTask.IsEnabled)
            {
                return(Task.CompletedTask);
            }

            var noWait = false;

            try
            {
                using (
                    var tx = new TransactionScope(TransactionScopeOption.RequiresNew,
                                                  new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                },
                                                  TransactionScopeAsyncFlowOption.Enabled))
                {
                    noWait = scheduledTask.Run();

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Scheduled task <{0}> has failed with exception: {1}", state.TaskTypeFullName, ex.ToString());
            }

            var timeout = new ScheduledTaskTimeout
            {
                TaskTypeFullName = state.TaskTypeFullName,
            };

            Data.TimeoutIdentifier = timeout.Identifier;

            return(RequestTimeout(context,
                                  noWait ? DateTime.Now : DateTime.Now.AddSeconds(Data.WaitDuration.TotalSeconds),
                                  timeout));
        }
Exemplo n.º 2
0
        public Task Handle(BeginScheduledTask message, IMessageHandlerContext context)
        {
            Data.WaitDuration = message.WaitDuration;

            Data.TaskTypeFullName = message.TaskTypeFullName;

            var timeoutMessage = new ScheduledTaskTimeout
            {
                TaskTypeFullName = message.TaskTypeFullName
            };

            Data.TimeoutIdentifier = timeoutMessage.Identifier;
            return(RequestTimeout <ScheduledTaskTimeout>(context, DateTime.Now, timeoutMessage));
        }