Task Manager

Current version: 9.1

The task manager is responsible for registering tasks to be picked up by agents in the Cortex Processing Engine (Processing Engine). By default, there are two implementations of ITaskManager:

  • Sitecore.Processing.Tasks.Messaging.TaskManager is used by clients such as the Content Management role to register processing tasks via the Message Bus. This implementation is sometimes known as the task manager proxy.

  • Sitecore.Processing.Engine.TaskManager is used within the Processing Engine to register incoming processing tasks in the Processing Engine Tasks database.

Note

You should always use the task manager proxy to schedule tasks. Do not use the messaging API directly.

The following example describes the data flow for registering a single distributed task from the Content Management role:

  • Use the service locator to get an instance of the ITaskManager:

    RequestResponse
    var taskManager = ServiceLocator.ServiceProvider.GetService<ITaskManager>();

Using the TaskManager in the context of a core role

In the context of a core role such as Content Management, use the service locator to get the task manager:

RequestResponse
var taskManager = ServiceLocator.ServiceProvider.GetService<ITaskManager>();

Using the TaskManager in the context of the Processing Engine

In the context of the Processing Engine, use constructor injection to get an instance of the task manager. The following example shows an instance of ITaskManager being injected into a custom message handler:

RequestResponse
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Sitecore.Framework.Conditions;
using Sitecore.Framework.Messaging;
using Sitecore.Processing.Engine.Abstractions;
using Sitecore.Processing.Engine.Abstractions.Messages;

namespace Sitecore.Documentation.Sample
{
    public abstract class CustomTaskHandler<TRegisterTask> : IMessageHandler<TRegisterTask>
        where TRegisterTask : RegisterTask
    {
        protected CustomTaskHandler(ITaskManager taskManager)
        {
            Condition.Requires(taskManager, nameof(taskManager)).IsNotNull();

            TaskManager = taskManager;
        }
}

Do you have some feedback for us?

If you have suggestions for improving this article,