private void ProcessBroadcastTask(TaskProcessorJob job)
        {
            // Ensure cancellation has not been requested.
            job.ThrowIfCancellationRequested();

            // Update the progress of the task in the task queue.
            this.TaskProcessor.UpdateTaskAsAssignedToProcessor(job);

            // Sanity.
            if (null == job.Data?.Value)
            {
                return;
            }

            // Deserialize the directive.
            EmailByUserPatchDirective dir = TaskQueueDirective.Parse <EmailByUserPatchDirective>(job.Data.Value);

            if (dir.GeneratedFromGuid != CurrentServer.ServerID)
            {
                // Debug Logging.
                if (this.Configuration.LoggingEnabled)
                {
                    SysUtils.ReportInfoToEventLog($"Broadcast processing with task id => {job.Data.Value.Id} on server {CurrentServer.ServerID}.");
                }

                // The task was created on another server, so we should process it on this server.
                AddOrUpdateEmailByUserId(dir.UserAccount, dir.Email);
            }
        }
        /// <summary>
        /// Marks any future executions of this job in this queue as cancelled.
        /// </summary>
        /// <param name="backgroundOperationName">If set, cancels only future executions for the specified background operation.</param>
        /// <param name="remarks">Remarks to set on the cancellation.</param>
        public void CancelFutureExecutions(string backgroundOperationName = null, string remarks = null)
        {
            try
            {
                // Cancel any tasks that are already scheduled.
                var tasksToCancel = TaskQueueAdministrator.FindTasks
                                    (
                    this.VaultApplication.PermanentVault,
                    this.QueueId,
                    t => t.Type == TaskQueueBackgroundOperation.TaskTypeId,
                    new[] { MFTaskState.MFTaskStateWaiting, MFTaskState.MFTaskStateInProgress }
                                    );
                foreach (var task in tasksToCancel.Cast <ApplicationTaskInfo>())
                {
                    var applicationTask = task.ToApplicationTask();

                    // Skip any that are not for this background operation.
                    if (false == string.IsNullOrWhiteSpace(backgroundOperationName))
                    {
                        var backgroundOperationDirective = TaskQueueDirective.Parse <BackgroundOperationTaskQueueDirective>(applicationTask);
                        if (null == backgroundOperationDirective?.BackgroundOperationName)
                        {
                            continue;
                        }
                        if (!backgroundOperationDirective.BackgroundOperationName.Equals(backgroundOperationName))
                        {
                            continue;
                        }
                    }

                    try
                    {
                        // Mark each task as superseded.
                        this.TaskProcessor.UpdateCancelledJobInTaskQueue
                        (
                            applicationTask,
                            string.Empty,
                            remarks
                        );
                    }
                    catch (Exception e)
                    {
                        SysUtils.ReportErrorToEventLog
                        (
                            $"Exception cancelling task {task.TaskID} of type {TaskQueueBackgroundOperation.TaskTypeId} on queue {this.QueueId} to cancel.",
                            e
                        );
                    }
                }
            }
            catch (Exception e)
            {
                SysUtils.ReportErrorToEventLog
                (
                    $"Exception retrieving tasks of type {TaskQueueBackgroundOperation.TaskTypeId} on queue {this.QueueId} to cancel.",
                    e
                );
            }
        }
예제 #3
0
        /// <summary>
        /// Wraps a call to <see cref="TaskQueueDirective.Parse{T}(Common.ApplicationTaskQueue.ApplicationTask)"/>
        /// to extract any directive supplied to the <paramref name="job" />.
        /// </summary>
        /// <typeparam name="TDirective">The type of the directive.</typeparam>
        /// <param name="job">The job to retrieve the directive for.</param>
        /// <returns>The directive, or null if no directive passed.</returns>
        public static TDirective GetTaskQueueDirective <TDirective>(this TaskProcessorJob job)
            where TDirective : TaskQueueDirective
        {
            // Sanity.
            if (null == job?.Data?.Value)
            {
                return(null);
            }

            // Unwrap.
            return(TaskQueueDirective.Parse <TDirective>(job.Data?.Value));
        }
        /// <summary>
        /// Processes a single job.
        /// </summary>
        /// <param name="job">Task processor job.</param>
        private void ProcessSequentialTask(TaskProcessorJob job)
        {
            // Debug Logging.
            if (this.Configuration.LoggingEnabled)
            {
                Debug.WriteLine($"Sequential task processing with task id => {job.Data?.Value.Id}.");
            }

            // Ensure cancellation has not been requested.
            job.ThrowIfCancellationRequested();

            // Update the progress of the task in the task queue.
            this.TaskProcessor.UpdateTaskAsAssignedToProcessor(job);

            // Sanity.
            if (null == job.Data?.Value)
            {
                return;
            }

            // Deserialize the directive.
            var dir = TaskQueueDirective.Parse <ObjVerExTaskQueueDirective>(job.Data?.Value);

            // Sanity.
            if (string.IsNullOrWhiteSpace(dir?.ObjVerEx))
            {
                return;
            }

            // Update the object.
            try
            {
                // Mark that we're updating the object.
                this.TaskProcessor.UpdateTaskInfo
                (
                    job.Data?.Value,
                    MFTaskState.MFTaskStateInProgress,
                    $"Updating object {dir.ObjVerEx}",
                    false
                );

                // Load the object, check it out, update, check it in.
                var objVerEx = ObjVerEx.Parse(job.Vault, dir.ObjVerEx);
                objVerEx.CheckOut();
                objVerEx.SetProperty
                (
                    MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle,
                    MFDataType.MFDatatypeText,
                    DateTime.Now.ToLongTimeString()
                );
                objVerEx.SaveProperties();
                objVerEx.CheckIn();

                // Updated.
                this.TaskProcessor.UpdateTaskInfo
                (
                    job.Data?.Value,
                    MFTaskState.MFTaskStateCompleted,
                    $"Object {dir.ObjVerEx} updated",
                    false
                );
            }
            catch (Exception e)
            {
                // Exception.
                this.TaskProcessor.UpdateTaskInfo
                (
                    job.Data?.Value,
                    MFTaskState.MFTaskStateFailed,
                    e.Message,
                    false
                );
            }
        }
예제 #5
0
        /// <summary>
        /// Marks any future executions of this job in this queue as cancelled.
        /// </summary>
        /// <param name="backgroundOperationName">If set, cancels only future executions for the specified background operation.</param>
        /// <param name="remarks">Remarks to set on the cancellation.</param>
        public void CancelFutureExecutions(string backgroundOperationName = null, string remarks = null)
        {
            try
            {
                // Cancel any tasks that are already scheduled.
                var tasksToCancel = TaskQueueAdministrator.FindTasks
                                    (
                    this.VaultApplication.PermanentVault,
                    this.QueueId,
                    t => t.Type == TaskQueueBackgroundOperation <TSecureConfiguration> .TaskTypeId,
                    new[] { MFTaskState.MFTaskStateWaiting }
                                    );
                foreach (var task in tasksToCancel.Cast <ApplicationTaskInfo>())
                {
                    var applicationTask = task.ToApplicationTask();

                    // Skip any that are not for this background operation.
                    if (false == string.IsNullOrWhiteSpace(backgroundOperationName))
                    {
                        var backgroundOperationDirective = TaskQueueDirective.Parse <BackgroundOperationTaskDirective>(applicationTask);
                        if (null == backgroundOperationDirective?.BackgroundOperationName)
                        {
                            continue;
                        }
                        if (!backgroundOperationDirective.BackgroundOperationName.Equals(backgroundOperationName))
                        {
                            continue;
                        }
                    }

                    try
                    {
                        // Mark each task as superseded.
                        switch (task.State)
                        {
                        case MFTaskState.MFTaskStateInProgress:
                            this.VaultApplication.TaskManager.CancelActiveTask
                            (
                                this.VaultApplication.PermanentVault,
                                task.TaskID
                            );
                            break;

                        case MFTaskState.MFTaskStateWaiting:
                            this.VaultApplication.TaskManager.CancelWaitingTask
                            (
                                this.VaultApplication.PermanentVault,
                                task.TaskID
                            );
                            break;

                        default:
                            // Cannot cancel ones in other states.
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        SysUtils.ReportErrorToEventLog
                        (
                            $"Exception cancelling task {task.TaskID} of type {TaskQueueBackgroundOperation<TSecureConfiguration>.TaskTypeId} on queue {this.QueueId} to cancel.",
                            e
                        );
                    }
                }
            }
            catch (Exception e)
            {
                SysUtils.ReportErrorToEventLog
                (
                    $"Exception retrieving tasks of type {TaskQueueBackgroundOperation<TSecureConfiguration>.TaskTypeId} on queue {this.QueueId} to cancel.",
                    e
                );
            }
        }