What are scheduled tasks?
Scheduled tasks are a way to schedule messages to the queue on time. Shopware uses it to run cleanup tasks, update tasks, and other non-time critical tasks in the background.
Default scheduled tasks
These tasks are registered by default:
|Name||Run interval (seconds)|
Some tasks like
shopware.invalidate_cache are only running when necessary. Elasticsearch task only runs when an Elasticsearch server is configured and enabled.
Creating a scheduled task
The following commands or flags (--no-wait) are available starting with Shopware 22.214.171.124.
List all scheduled tasks
You can list all scheduled tasks with
bin/console scheduled-task:list command.
Running scheduled tasks
To run the scheduled tasks, you must set up a background worker like the Message Queue and run the command
bin/console scheduled-task:run. The command schedules all tasks to the queue and waits until a task needs to be scheduled. It consumes little CPU time or memory.
You can use the flag
--no-wait and run the command from an operating system scheduler like cron. Check your scheduled task interval to determine the best interval to trigger the command. Example:
*/5 * * * * /usr/bin/php /var/www/html/bin/console scheduled-task:run --no-wait
Debugging scheduled tasks
You can directly run a single scheduled task without the queue. This is useful for debugging purposes or to have better control of when and which tasks are executed. You can use
bin/console scheduled-task:run-single <task-name> to run a single task. Example:
bin/console scheduled-task:run-single log_entry.cleanup