Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable cron:run when maintenance mode is enabled #21181

Closed
wants to merge 3 commits into from

Conversation

kassner
Copy link
Contributor

@kassner kassner commented Feb 13, 2019

Description

I believe cron jobs should be disabled while setup:upgrade is being run, to avoid concurrent accesses, which can lead to table locks that can make setup upgrade fail, plus we'll be using stale/wrong data for the cron jobs.

Since the maintenance mode makes sure the frontend is inaccessible, avoiding any writes to the database through it, I believe we should disable crons as well, as they have a heavy impact on the database.

Manual testing scenarios

  1. Run php bin/magento maintenance:enable;
  2. Run php bin/magento cron:run;
  3. Cron jobs should not run;

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @kassner. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team magento-engcom-team added Component: Cron Release Line: 2.3 Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner labels Feb 13, 2019
@ihor-sviziev ihor-sviziev self-assigned this Feb 13, 2019
@miguelbalparda
Copy link
Contributor

miguelbalparda commented Feb 13, 2019

Since the maintenance mode makes sure the frontend is inaccessible, avoiding any writes to the database through it, I believe we should disable crons as well, as they have a heavy impact on the database.

This is true only for some cases, I'm not sure if this should be included in the core. Maybe create a config instead of assuming this applies to everybody?

@ihor-sviziev
Copy link
Contributor

Hi @miguelbalparda,
Is there any use case when cron jobs should be running during enabled maintenance mode?

@miguelbalparda
Copy link
Contributor

It depends on how people is using maintenance mode. I've seen admins putting the site in that mode just to do changes on prices or CMS pages or even deploying new code changes while on maintenance, which sometimes require crons to be run.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Feb 13, 2019 via email

@miguelbalparda
Copy link
Contributor

I think that’s no different than disabling Magento_Cron using the bin/magento tool and should have the same effect without adding anything to the core for an use case that’s not super intuitive.

@kassner
Copy link
Contributor Author

kassner commented Feb 13, 2019

Disabling Magento_Cron with module:disable is not the same, as it will prevent future db upgrades while running setup:upgrade.

@miguelbalparda
Copy link
Contributor

Which is consistent with the description of this PR regarding no DB writes while in maintenance, achieving virtually the same objective.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Feb 13, 2019 via email

@kassner
Copy link
Contributor Author

kassner commented Feb 13, 2019

@miguelbalparda no, as I am enabling maintenance mode just because I want to run setup:upgrade without anything else concurrently. I still want to run Magento_Cron's UpgradeData/UpgradeSchema.

@miguelbalparda
Copy link
Contributor

Maintenance windows are very short usually, which means --force can be used to disable Magento_Cron just for the duration of the window without causing much issues. I still don't see why an edge case like this should be considered in the core, the reasoning behind an inclusion should be a broader benefit and I don't see that in this issue. In either case, this should be consulted with an architect IMO.

@sivaschenko
Copy link
Member

I think it is a good idea to disable cron by default during maintenance mode as it appears to be the safes approach. I'd add a command option to maintenance:enable to keep cron jobs running for those who are confident that cron jobs are not going to be affected during maintenance operations.

@ihor-sviziev
Copy link
Contributor

Hi @kandy @buskamuza,
What do you think about such proposal?

if ($this->maintenanceMode->isOn()) {
$output->writeln('<info>' . 'Cron is disabled because the maintenance mode is enabled.' . '</info>');
return;
}
if (!$this->deploymentConfig->get('cron/enabled', 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pay attention to this configuration. You already may disable cron. Add cron/enabled as 0 to configuration file. There is no special CLI command for this setting for now.

@NadiyaS
Copy link
Contributor

NadiyaS commented Feb 13, 2019

Hi,
First, there may be some possible cases when user enables maintenance mode and wants to have cron running.
Also, there may be cases when you want just to disable cron without maintenance mode.
And we already have this possibility. I added comment to the review.
You may add cron/enabled config as 0 to configuration file (e.g. app/etc/env.php) and cron won't be run.
We did not implement CLI command to manage this configuration yet.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Feb 14, 2019

@NadiyaS good catch!
In this case I think would be better to add cli commands cron:enable and cron:disable. @kassner @buskamuza what do you think?

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

As we discussed with Architects in #appdesign - it's better to introduce cron:enable and cron:disable CLI commands, that will fit all needs and will not add backward incompatible changes.

@kassner could you update your PR with these chagnes?

@sidolov
Copy link
Contributor

sidolov commented Mar 28, 2019

@kassner , I am closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for the collaboration!

@sidolov sidolov closed this Mar 28, 2019
@ghost
Copy link

ghost commented Mar 28, 2019

Hi @kassner, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Cron Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner Progress: needs update Release Line: 2.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants