[wp-hackers] WP cron and "multi-threading"
mark.wordpress at txfx.net
Mon Oct 9 03:15:07 GMT 2006
On Oct 8, 2006, at 6:50 PM, Robert Deaton wrote:
> I've run into this before in testing and I've thought a lot about the
> best way to handle the race condition. The best I can think of, and I
> think it may work, is in wp-cron.php, we set an option that says "we
> are busy doing the cron" along with some random hash. Then we sleep
> for 500 usecs, and check the value of the option.
I was talking with Michael Hampton (io_error) about this for
something he was doing, and that was the solution I gave him as well,
with slightly different details.
You need to expire the "cron_is_running" option, in case your winning
race candidate dies before it gets to unset it. You could set a
separate timestamp option "cron_start_time" and have WP autoload and
check that, deleting both options if 15 minutes or so have passed
(it's just for emergencies).
I'm not really privy to the details of how the cron works, you can
decide if this makes sense:
you need to mark the cron as having been run BEFORE the wait time
begins, to avoid another race, or do another wait after marking the
cron as run but before erasing "cron_is_running"
More information about the wp-hackers