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

Timezones in cron will change between Magento 2.1.x and 2.2.x, how to handle this change? #296

Closed
hostep opened this issue Jun 16, 2017 · 4 comments
Labels

Comments

@hostep
Copy link
Contributor

hostep commented Jun 16, 2017

Hi guys

Recently a Pull Request: magento/magento2#9943 was accepted and it will be released in Magento 2.2.0: magento/magento2#4237 (comment)

This fixes an issue with wrong timezones being used when inserting and reading times in/from the cron_schedule table.

The problem is, that n98-magerun2 also has some functionality which uses the wrong timezones for running and scheduling cronjobs:

So I think this bug should get fixed in magerun2 as well.
The question is: how will this be handled? Since magerun2 will be used both in Magento 2.1.x versions as well as Magento 2.2.x versions.

Should we check for the current version of Magento in use and then change the behavior of the code, or will magerun2 create a new version which won't be backwards compatible anymore with Magento 2.1.x for example?
Also: maybe the above PR will get backported to Magento 2.1.x one day, it might happen...

These are just some things which popped into my head.

Thanks!

@ktomk
Copy link
Collaborator

ktomk commented Jun 16, 2017

Thanks for pointing this out!

If I understood you right, it should be enough to use the correct time-stamp string values.

So if timestamp creating is extracted and moved into an abstract method in the base class, the decision on version can be implemented there.

$this->timezone->scopeTimeStamp() -> $this->getTimeStamp()

And then changing AbstractCronCommand::getTimeStamp() according to the needs (check magento version to branch timestamp creation).

In case this is backported, all that changes is the magento version to compare against.

This would be quite straight forward for the changes.

It would be much greater however if there are classes / model in Magento 2 which would allow to to the run / shedule cron operations in a more API friendly way. In such a case we would automatically benefit from upstream changes. But I smell that these are not available. Last time I looked (ca. 4-5 month ago) cron handling code was pretty spread out and there was little to no API for it.

@ktomk ktomk added the bug label Jun 16, 2017
@hostep
Copy link
Contributor Author

hostep commented Jun 16, 2017

This sounds like a good solution :)

API-wise, I doesn't look like much has changed unfortunately, most of the useful functionality is part of the ProcessCronQueueObserve class, which only has one public method.

ktomk added a commit that referenced this issue Jun 16, 2017
Preparation for upcoming changes in Magento 2.2.0.

Note: There is no branch on version yet, this needs future
      implementation.

Refs:

- #296
@ktomk ktomk closed this as completed in 2485021 Jun 16, 2017
@ktomk
Copy link
Collaborator

ktomk commented Jun 16, 2017

That's what I thought of, this one big Moloch handling "all the things" :)

Anyway thanks again for report and review, I just pushed some changes that should handle it: 854d598...2485021


We believe that the bug reported is fixed in the development version. It can be upgraded to it using the self-update command with the --unstable switch.

@hostep
Copy link
Contributor Author

hostep commented Jun 16, 2017

Wow nice one, this went a lot quicker then I expected, tnx! :)

cmuench referenced this issue in cmuench/n98-magerun2 Oct 11, 2017
Preparation for upcoming changes in Magento 2.2.0.

Note: There is no branch on version yet, this needs future
      implementation.

Refs:

- #296
cmuench referenced this issue in cmuench/n98-magerun2 Oct 11, 2017
Since Magento 2.2.0 the cron database tables will use GMT timestamps,
before that version Magento has used timestamps in a different timezone.

Fix is to branch based on Magento version:

a) Use GMT timestamps from version 2.2.0 or above.

b) Use local timestamps up to version 2.2.0

Refs:

- Command: sys:cron:run

- Command: sys:cron:schedule

- #296

- magento/magento2#9943
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants