diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index 98176c9d3..b97abb237 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -760,8 +760,21 @@ Cleanup cache id_prefix env files. After successful deployment, move the tmp_env.php file to env.php ready for next deployment +### magento\:queue\:consumers\:stop {#magento-queue-consumers-stop} +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L596) + +Kill running queue consumers. + +Kill running queue consumers, so cron starts them again from the new release. +A consumer only stops after `max_messages` messages. Until then, it runs the code of the previous release. +To use this feature, add the following to your deployer scripts: + ```php + after('deploy:symlink', 'magento:queue:consumers:stop'); + ``` + + ### magento\:cron\:stop {#magento-cron-stop} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L595) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L608) Remove cron from crontab and kill running cron jobs. @@ -773,7 +786,7 @@ To use this feature, add the following to your deployer scripts: ### magento\:cron\:install {#magento-cron-install} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L611) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L625) Install cron in crontab. @@ -785,7 +798,7 @@ To use this feature, add the following to your deployer scripts: ### artifact\:prepare {#artifact-prepare} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L617) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L631) Prepares an artifact on the target server. @@ -805,7 +818,7 @@ This task is group task which contains next tasks: ### artifact\:finish {#artifact-finish} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L630) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L644) Executes the tasks after artifact is released. @@ -821,7 +834,7 @@ This task is group task which contains next tasks: ### artifact\:deploy {#artifact-deploy} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L639) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L653) Actually releases the artifact deployment. diff --git a/recipe/magento2.php b/recipe/magento2.php index 12d612657..eadf80225 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -584,6 +584,19 @@ function magentoDeployAssetsSplit(string $area): void run('{{bin/symlink}} {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); }); +/** + * Kill running queue consumers, so cron starts them again from the new release. + * A consumer only stops after `max_messages` messages. Until then, it runs the code of the previous release. + * To use this feature, add the following to your deployer scripts: + * ```php + * after('deploy:symlink', 'magento:queue:consumers:stop'); + * ``` + */ +desc('Kill running queue consumers'); +task('magento:queue:consumers:stop', function () { + run('pgrep -U "$(id -u)" -f "bin/magento +queue:consumers:start" | xargs -r kill'); +}); + /** * Remove cron from crontab and kill running cron jobs * To use this feature, add the following to your deployer scripts: @@ -597,7 +610,8 @@ function magentoDeployAssetsSplit(string $area): void run('{{bin/php}} {{previous_release}}/{{magento_dir}}/bin/magento cron:remove'); } - run('pgrep -U "$(id -u)" -f "bin/magento +(cron:run|queue:consumers:start)" | xargs -r kill'); + run('pgrep -U "$(id -u)" -f "bin/magento +cron:run" | xargs -r kill'); + invoke('magento:queue:consumers:stop'); }); /**