Schedule Symfony Commands in your Sylius admin panel.
synolia:scheduler-run
)Launch a command
button) Version | |
---|---|
PHP | ^8.0 |
Sylius | ^1.10 |
Add the bundle and dependencies in your composer.json :
composer config extra.symfony.allow-contrib true
composer req synolia/sylius-scheduler-command-plugin
Apply migrations to your database:
bin/console doctrine:migrations:migrate
Launch Run command in your Crontab
* * * * * /_PROJECT_DIRECTORY_/bin/console synolia:scheduler-run
(optional) Showing humanized cron expression
composer require lorisleiva/cron-translator
Till symfony/recipes-contrib
is updated for the v3, you must add sylius_scheduler_command.yaml
from install/Application/config/{packages,routes}
to your project by respecting the same folder architecture.
cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/packages/* config/packages/
cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/routes/* config/routes/
Scheduled commands
in the Scheduled commands section in main menu to manage your Scheduled commandsScheduled commands history
in the Scheduled commands section in main menu to see history of commandsInside sylius fixture file config/packages/sylius_fixtures.yaml
you can add scheduled command fixtures to your suite.
sylius_fixtures:
suites:
my_fixture_suite:
fixtures:
scheduler_command:
options:
scheduled_commands:
-
name: 'Reset Sylius'
command: 'sylius:fixtures:load'
cronExpression: '0 0 * * *'
logFilePrefix: 'reset'
priority: 0
enabled: true
-
name: 'Cancel Unpaid Orders'
command: 'sylius:cancel-unpaid-orders'
cronExpression: '0 0 * * *'
priority: 1
enabled: false
Execute scheduled commands.
Run all scheduled commands : php bin/console synolia:scheduler-run
Run one scheduled command : php bin/console synolia:scheduler-run --id=5
Purge scheduled command history greater than {X} days old.
Example to remove all finished and in error scheduled commands after 7 days :
php bin/console synolia:scheduler:purge-history --state=finished --state=error --days=7
services:
...
# By enabling this service, it will be requested to vote after the other EveryMinuteIsDueChecker checker.
# Using some cloud providers, even if the master cron is set to run every minute, it is actually not run that often
# This service allows you to set a soft threshold limit, so if your provider is actually running the master cron every 5 minutes
# This service will execute the cron if we are still in the threshold limit ONLY IF it was not already executed another time in the same range.
#
# CONFIGURATION SCENARIO: cron set to be run at 01:07 in the scheduler command plugin
#
# SCENARIO CASES AT 1 CRON PASS EVERY 5 MINUTES FROM THE PROVIDER
# cron passes at 01:04 - 1..5 minutes: IS NOT DUE
# cron passes at 01:05 - 1..5 minutes: IS NOT DUE
# cron passes at 01:06 - 1..5 minutes: IS NOT DUE
# cron passes at 01:07 - 1..5 minutes: IS DUE (but it should already be handled by EveryMinuteIsDueChecker)
# cron passes at 01:08 - 1..5 minutes: IS DUE
# cron passes at 01:09 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
# cron passes at 01:10 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
# cron passes at 01:11 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
# cron passes at 01:12 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
# cron passes at 01:13 - 1..5 minutes: IS NOT DUE
Synolia\SyliusSchedulerCommandPlugin\Checker\SoftLimitThresholdIsDueChecker:
tags:
- { name: !php/const Synolia\SyliusSchedulerCommandPlugin\Checker\IsDueCheckerInterface::TAG_ID }
#optionnal, default value is 5 minutes
arguments:
$threshold: 5 #soft limit threshold in minutes
See How to contribute.
This library is under the MIT license.
Developed by Synolia.