Jump to content

Timing of Lazy Cron


Robin S
 Share

Recommended Posts

If I have a Lazy Cron hook with an interval of "everyDay", when during the day does the hook fire? Is it every 24 hours from whenever the hook is first set or is it tied to a particular time of day such as midnight every day?

Link to comment
Share on other sites

The modules does save timestamps of the last execution for each of it's hookable timeframes (site/assets/cache/LazyCron.cache). For each page-request it checks each timestamp if it's bygone by more than the corresponding timeframe and if so it triggers the function and updates the timeframe. Therefore the hook will always run if the last execution was anytime longer ago than the timeframe's timespan itself. As this does depend on actual page views this cannot be timed to a specific time of the day or alike, e.g. everyDay could be: 24h gap, 26h gap, 25,5h gap, 24h gap, 48h gap (nobody visited the second day). 

  • Like 5
Link to comment
Share on other sites

Thanks. Still not quite clear on when the first execution will fire. Let's leave aside the issue of page views and assume my site continuously gets page views every second. If I create a new hook for "everyDay" and happen to save this hook in my ready.php at 2pm, does 24 hours elapse before the first execution, and then the hook fires again 24 hours after that, at 2pm every day?

If that is so, how can I arrange for an everyDay hook to fire at a given time (approximately)? Say 1am. Because even if I follow the suggestion in the lazy cron docs and set a normal cron job to load a page at 1am, if 24 hours has not yet elapsed it's not going to trigger my lazy cron. That's just going to keep on firing at 2pm isn't it?

Link to comment
Share on other sites

As I said it depends on the timestamp in the LazyCron.cache file. This does determine when the everyDay hook is triggered (e.g. all everyDay hooks at once). If you're using a cron anyways I'd rather suggest not using LazyCron at all in that case. It's nice if you just want to ensure LazyCron to run, but if you want it to run at the cron execution just let it run 'php /some/path/cron.php' with this:

<?php
// cron.php

include 'index.php';

//Trigger anything needed
  • Like 3
Link to comment
Share on other sites

Yes, I probably will do a normal cron, but I'd like to get my head around Lazy Cron just so I understand how it works.

And I must be thick because I'm still not getting it. I think I understand about how it depends on the timestamp in LazyCron.cache, but when is the first timestamp set. Because doesn't everything depend on that?

Presumably before any Lazy Cron hooks are added there is no timestamp at all. Then I add my first hook, and it's an "everyDay" hook. Does this set the timestamp...

a) On the next page load immediately after I save the hook (let's say it's 2pm when I happen to save this hook). Then my hook will forever fire at approximately 2pm every day, give or take depending on page loads.

b) It has nothing to do with when I save the hook, but rather it's fixed to some standard time such as midnight. So I save my hook at 2pm, but it first fires at midnight (same day? following day?) and then will forever fire at approximately midnight every day, give or take depending on page loads.

Edit: I also understand that by nature a lazy cron will drift in time because the variations in page loads accumulate with every execution, but I'm still interested in when that first execution takes place.

Thanks for your patience.

Link to comment
Share on other sites

The cache file is regenerated on each pageview, where the file is no found. E.g. when installing the module or if you remove the file manually, where the last one is not a good solution for resetting, as it's removing all timestamps, therefore all hooks would automatically run on the next request.

Also LazyCron does not care for specific hooks. It just runs the everyDay function if it's due no matter how many things might be hooked into it.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...