Warning
You're browsing the documentation for an old version of Webiny. Consider upgrading your project to Webiny 5.40.x.
Use with caution!
This feature is experimental and is subject to change in future releases.
Can I use this?

This feature is available since Webiny v5.39.0.

What you’ll learn
  • what are available built-in Background Tasks
  • how to run built-in Background Tasks

Built-in Background Tasks
anchor

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
anchor

The test task is a task which is used for testing the Background Task mechanism. Its definition is available hereexternal link.

Elasticsearch Reindexing Task
anchor

Elasticsearch And OpenSearch Only!
This task will only get shipped with Elasticsearch and OpenSearch Webiny system.

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 definitionexternal link and the runnerexternal link code for more information.

The task can be triggered either via code or via the GraphQL API.

Triggering the Task via Code
anchor

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
anchor

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.