| The schedule type does not behave correctly with `period => weekly` and `"periodmatch => number`. This results in a gap where the resource should be applied, but cannot due to the underlying logic of the weekly period. The other periods check to ensure that the period is different. For example, the daily period checks to see if the day is not the same as the previous run 09/07 != 09/08. The weekly period, on the other hand, checks to see if the day of the week is less than the previous or 604800 seconds have elapsed. Currently, when using the weekly schedule, resources will not be applied any time on the same day of the week until after 604800 from the previous run. So if the previous run was at 2018-09-07 18:00, the weekly schedule would include the resource any time from 09/10 to 09/13, and after 9/15+ any time. On 09/14, 7 days from the previous run, it could only run after 18:00, so it cannot be run from 00:00-18:00 on 09/14. The deviation comes from https://github.com/puppetlabs/puppet/blob/master/lib/puppet/type/schedule.rb#L226-L235 where the weekly has a proc instead of comparing the week.
ScheduleMethods = { |
:hourly => :hour, |
:daily => :day, |
:monthly => :month, |
:weekly => proc do |prev, now| |
# Run the resource if the previous day was after this weekday (e.g., prev is wed, current is tue) |
# or if it's been more than a week since we ran |
prev.wday > now.wday or (now - prev) > (24 * 3600 * 7) |
end |
} |
|
... |
|
method = ScheduleMethods[value] |
if method.is_a?(Proc) |
return method.call(previous, now) |
else |
# We negate it, because if they're equal we don't run |
return now.send(method) != previous.send(method) |
end
|
Reproduction Using the documentation, one could build a schedule that is set to weekly and the resources may not get scheduled due to this limitation. Below is an example.
schedule { "friday_night": |
period => 'weekly', |
periodmatch => "number", |
range => '18:00 - 23:59', |
weekday => "friday", |
}
|
If the resource is previously applied close to the end of the schedule, it may never get applied the next week. This should be a valid configuration since the current week does not equal the previous week, so it should be able to be applied any time in the Friday period. Since periodmatch => "number", is set, I would expect it to not have to wait the full distance, as when periodmatch => "distance", is set. Suggested Fix Since we do not want to break the previous behavior and want to fix this, we should not just update it to ensure the week is not the same. Below is a potential option.
((prev.wday >= now.wday) && (prev.to_date.cweek != now.to_date.cweek) || (now - prev) > (24 * 3600 * 7))
|
|