Skip to content

Commit

Permalink
Add feature to stop cron before deployment and start cron after
Browse files Browse the repository at this point in the history
  • Loading branch information
gbobts authored Mar 29, 2024
1 parent 1581813 commit 8f3d615
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions recipe/magento2.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,34 @@ function magentoDeployAssetsSplit(string $area)
run('{{bin/symlink}} {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH);
});

/**
* Remove cron from crontab and kill running cron jobs
* To use this feature, add the following to your deployer scripts:
* ```php
* after('magento:maintenance:enable-if-needed', 'magento:cron:stop');
* ```
*/
desc('Remove cron from crontab and kill running cron jobs');
task('magento:cron:stop', function () {
if (has('previous_release')) {
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');
});

/**
* Install cron in crontab
* To use this feature, add the following to your deployer scripts:
* ```php
* after('magento:upgrade:db', 'magento:cron:install');
* ```
*/
desc('Install cron in crontab');
task('magento:cron:install', function () {
run('cd {{release_or_current_path}}');
run('{{bin/php}} {{bin/magento}} cron:install');
});

desc('Prepares an artifact on the target server');
task('artifact:prepare', [
Expand Down

0 comments on commit 8f3d615

Please sign in to comment.