- In ScheduledTaskHelper class, in _isInRange function we check whether a scheduled tasks should be executed or not.
$hour = $frequency->getAttribute(‘hour’);
if (isset($hour)) {
$isValid = ScheduledTaskHelper::_isInRange($hour, (int)date(‘G’), $lastRunTime, ‘hour’, strtotime(‘-1 day’));
}
…
…
In the case we set hour as frequency,
The task will be executed on 2 cases, if a day has passed:
if ($cutoffTimestamp > $lastTimestamp) {
// Execute immediately if the cutoff time period has past since the task was last run
$isValid = true;
}
and second if is the exact hour we have set on frequency tag:
for ($i = 0, $count = count($rangeArray); !$isValid && ($i < $count); $i++) {
if ($rangeArray[$i] == ‘*’) {
// Is wildcard
$isValid = true;} if (is_numeric($rangeArray[$i])) { // Is just a value $isValid = ($currentValue == (int)$rangeArray[$i]); } else if (preg_match('/^(\d*)\-(\d*)$/', $rangeArray[$i], $matches)) { // Is a range $isValid = ScheduledTaskHelper::_isInNumericRange($currentValue, (int)$matches[1], (int)$matches[2]); } else if (preg_match('/^(.+)\/(\d+)$/', $rangeArray[$i], $matches)) { // Is a range with a skip factor $skipRangeStr = $matches[1]; $skipFactor = (int)$matches[2]; if ($skipRangeStr == '*') { $isValid = true; } else if (preg_match('/^(\d*)\-(\d*)$/', $skipRangeStr, $matches)) { $isValid = ScheduledTaskHelper::_isInNumericRange($currentValue, (int)$matches[1], (int)$matches[2]); } if ($isValid) { // Check against skip factor $isValid = (strtotime("-$skipFactor $timeCompareStr") > $lastTimestamp); } } }
This will lead the task to execute many times if we call it on that hour.
How can I solve this issue so the task will be executed only once per day.
Thank you in advance.