Core Development Concepts > Background Tasks
Built-in Background Tasks
You will learn about Background Tasks, how to create new definitions, how to trigger them and how to handle the task run.
This feature is available since Webiny v5.39.0.
- what are available built-in Background Tasks
- how to run built-in Background Tasks
Built-in Background Tasks
Webiny ships with a few of built-in Background Tasks. Some of them are used only internally (like clearing Cloudfront file cache), and some of them can be used publicly (Elasticsearch reindexing).
Test Task
The test task is a task which is used for testing the Background Task mechanism. Its definition is available here.
Elasticsearch Reindexing Task
The Elasticsearch/OpenSearch Reindexing is the first task we implemented via the Background Task mechanism. Basically, it is a task which scans through the DynamoDB Elasticsearch table and pushes the data into the specific Elasticsearch/OpenSearch index. Internally it is a bit more than that, but this is the basic idea. You can check the definition and the runner code for more information.
The task can be triggered either via code or via the GraphQL API.
Triggering the Task via Code
Let’s say that you have a Page Builder lifecycle event hook which triggers the task when the page is published, but only on index which contains the word page
in its name.
Triggering the Task via GraphQL API
The task can be triggered via the GraphQL API, with the following mutation:
The task disables indexing on all matching indexes, and enables it when the task is finished. This is done to reduce the strain on the Elasticsearch/OpenSearch cluster as the reindexing operation is a heavy one.