Documentation Center

Background tasks

A background task is an application logic that is triggered on certain events, does not require user interaction and runs in a background by a background task service. Typical example is publishing process: it has to be triggered by user, but after it is triggered, it does not require user input neither does it require user to wait. Instead, the publishing process runs in a background, and user can know that it is finished by periodically checking the status of a publication.

Starting background tasks

Typically, background tasks are created by plugins. For example, it is possible to register a plugin that will run when user changes the status of the topic and create the background task. Typically, background task does not start executing immediately after it is created. Instead it is added to the queue from where it can be later picked up by a background task service which executes the task. This allows better distribution of load since the task can be picked up by the service (or server, because background task services can run on different servers) which is less busy.

Executing background tasks

There is only one background tasks queue which is available to every background task service. Under the hood, it is implemented as a database table, which means that once added, task will not get lost. Practically it means that task will survive the server reboot, and even if the task execution fails in the middle, task remains in the queue and can be re-started.

Every background task has an event type it is created for. For example, when you trigger the publish, there will be a background task created with event type EXPORTFORPUBLICATION. Tasks can be picked up by one of the installed background task services. You can limit event types that service is allowed to pick and amount of background tasks with the same event type that can be executed in parallel.

When task fails for one reason or another, it is automatically retried later. You can adjust this behavior by changing the limit of retry attempts.

Monitoring background tasks

Typically, background tasks update the status of the execution by writing to the event log. For example, background task that executes publishing will update the corresponding Publish event.

There is only one queue for background tasks. There can be any number of background task services picking up tasks.