Register a task
Use the task manager (TaskManager) to register a distributed task, a deferred task, or a chain of tasks from a client such as the Content Management role. Tasks are added to the Message Bus and are eventually executed by workers in the Cortex Processing Engine.
The examples in this topic demonstrate how to register tasks using the base worker options dictionaries: DeferredWorkerOptionsDictionary and DistributedWorkerOptionsDictionary. Although you can register any task in this way, it is standard practice to create a specialized worker options dictionaries for each worker type. Default worker options dictionaries include:
MergeWorkerOptionsDictionaryInteractionProjectionWorkerOptionsDictionaryContactProjectionWorkerOptionsDictionaryInteractionTrainingWorkerOptionsDictionaryContactTrainingWorkerOptionsDictionary
Register a deferred task
Use the RegisterDeferredTaskAsync() method on the TaskManager class to register a deferred task. The following example:
- Uses the
DeferredWorkerOptionsDictionarybase class: - Assumes a
Sitecore.Documentation.SampleDeferredWorkerexists. - Assumes that worker includes logic to handle a key of "testkey" with a value of "testvalue".
Register a distributed task
Use the RegisterDistributedTaskAsync() method on the TaskManager class to register a distributed task. The following example:
-
Uses the
DistributedWorkerOptionsDictionarybase class: -
Assumes a
Sitecore.Documentation.SampleDistributedWorkerexists. -
Assumes that worker includes logic to handle a key of "testkey" with a value of "testvalue".
NoteIt is standard practice to create a specialized worker options dictionary for distributed workers that inherits `DistributedWorkerOptionsDictionary`.
-
Uses the
ContactDataSourceOptionsDictionaryclass, which specifies that the worker should get data via data extraction from xConnect. There are four default data source options. -
Assumes a contact facet with the key "TestFacetKey" exists.
Registering tasks for default workers
Refer to the following documentation for information about how to register tasks for specific workers:
- Training worker
- Projection worker
- Merge worker
Many scenarios, such as model training, includes a chain of tasks that is processed by several different types of workers.