pkp / pkp-lib

The library used by PKP's applications OJS, OMP and OPS, open source software for scholarly publishing.
https://pkp.sfu.ca
GNU General Public License v3.0
297 stars 443 forks source link

Scheduled task arithmetic can over/underflow dates #8921

Open jnugent opened 1 year ago

jnugent commented 1 year ago

Describe the bug We've had a client report where the editorial activity report is sent out a few days apart, with each run at the end and then beginning of the next month. For example:

Mar 29 and Apr 1 Dec 31 and Jan 1 Oct 31 and Nov 1 May 31 and Jun 1

Looking at the way the scheduled task parser seems to work, I think that some of the date calculations like strfrtime('-1 month') are pushing the scheduled task tests into a previous month. If the Editorial Report had its own scheduled task we could run it exactly on the month with regular cron and avoid this problem but it isn't a plugin and runs out of the regular registry/scheduledTasks.xml file. The over/underflow problem is documented on the PHP site as a caveat when doing date interval math like this. https://www.php.net/manual/en/datetime.examples-arithmetic.php

I think we should consider using "last day of" or "first day of" syntax when specifying particular intervals as a way to get around this problem, e.g. strfrtime('last day of last month') or strfrtime('first day of last month').

I haven't really worked through all of the logic in the _isInRange method in the ScheduledTaskHelper class yet.

jnugent commented 1 year ago

Adding some additional detail here. This morning a client reached out and said that they received the report for the month of April, not May. I believe that this occurred because the scheduled task was deemed ready to run, and when the date math occurred it picked April as the month to run based on a math underrun. Tomorrow, on June 1, we assume that this task will run again and then send out the report for May. So, this particular issue is causing reports to be sent multiple times, leading to confusion.