Magento – Cron does not reschedule currency_rates_update job until Cache Storage is flushed

cachecroncurrency-ratesee-1.11

One problem I have been assigned to investigate is to the updating of currency rates via the cron job.

I was able to get it to update fine, but when I went to run it again after changing the time (by about 2 minutes) the currency_rates_update job was not rescheduled in the cron_schedule table.

After experimenting I have found something strange. After changing the time for the currency rates to be updated I had to click on the Flush Cache Storage button in Cache Management before the cron would create the currency_rates_update entry. Once it has been created, it will work fine after that.

This is what I do to change the time:

  1. Go to System > Configuration > General > Currency Setup
  2. Change Start Time in Scheduled Import Settings to be 3 – 5 minutes ahead of my current time and save
  3. Go to System > Cache Management
  4. Select all the caches, set Actions to refresh and click on submit
  5. Go to cron.php

After all of this the currency_rates_update isn't created, it's only created after I click on Flush Cache Storage button in cache management. I am wondering if I am missing a step that doesn't involve flushing the cache storage when I change the time.

NOTE: As a further test, I went onto a different build with a different database and turned off all the caches and cleared everything in cron_schedule before running cron.php, nothing was recreated until I flushed the cache storage.

Best Answer

Under System -> Configuration -> System you'll find a setting which dictates the frequency of the cron schedule generation. When the cron schedule is generated, the time stamp is stored in a cache record outside the scope of any defined cache tags, meaning it is not gotten rid of unless the storage is flushed vs flushing the tagged cache records. The time stamp in this cache record is checked on each run to determine if enough time has elapsed for a schedule generation to run.

So in short: it's working as intended. :)

The reason the cron schedule is not calculated on each execution cycle is for performance reasons. It's far less computationally expensive to dump a precalculated schedule into the cron_schedule table and execute based on what is is found in there on each run. This same table is consequently also used for placing a lock on each job.

If you are needing to refresh the conversion rates manually, you can do it from the currency rates management page on the click of a button. If you are just wanting to effect a change in the timing of the refresh, change the setting and check back later, it will be picked up the next time the cron schedule is generated prior to the set time. Or just flush the cache storage to see it take effect immediately... ;)

Related Topic