Jira (PUP-9151) Schedule resource weekly behavior inconsistent with other periods

6 views
Skip to first unread message

Jarret Lavallee (JIRA)

unread,
Sep 18, 2018, 12:35:06 PM9/18/18
to puppe...@googlegroups.com
Jarret Lavallee created an issue
 
Puppet / Bug PUP-9151
Schedule resource weekly behavior inconsistent with other periods
Issue Type: Bug Bug
Affects Versions: PUP 5.5.6
Assignee: Unassigned
Created: 2018/09/18 9:34 AM
Priority: Normal Normal
Reporter: Jarret Lavallee

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))

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Rob Braden (JIRA)

unread,
Jan 22, 2019, 5:56:04 PM1/22/19
to puppe...@googlegroups.com
Rob Braden updated an issue
Change By: Rob Braden
Sprint: Platform Core Coremunity Grooming

Eric Sorenson (JIRA)

unread,
Jan 22, 2019, 5:59:04 PM1/22/19
to puppe...@googlegroups.com
Eric Sorenson commented on Bug PUP-9151
 
Re: Schedule resource weekly behavior inconsistent with other periods

I think we'd take a patch that addresses this, it's not widely used but I understand the logic.

Jo Rhett - you've probably used 'schedule' more than any human on this blue globe - have you run into this before? What do you think about the proposed solution?

Jo Rhett (JIRA)

unread,
Jan 22, 2019, 8:16:03 PM1/22/19
to puppe...@googlegroups.com
Jo Rhett commented on Bug PUP-9151

As it happens, I have run into this I agree completely with his analysis of the problem. Weekly doesn't properly implement number only distance.

I think I recall hacking up a patch for this and then realizing that the current spec is a bit unclear to start with. I believe that Henrik Lindberg looked at it and gave a similar concern: it's kind of hard to fix the type without breaking a lot of working (if idiomatic) implementations.

I believe that the following schedule will meet his needs. Use a daily schedule with a weekday limiter, and he'll get the effect he wants.

schedule { 'friday_night':
  period     => 'daily', 
  range      => '18:00 - 23:59',
  weekday => 'Friday',
  repeat     => 1,
} 

This isn't the first periodmatch => number bug we've seen and I think there's too much cruft in existence to just change the delivery outright. Eric Sorenson for your purposes this is a general backlog thing you need to tackle eventually. I think a clear, testable spec needs to be written. I think it should use a different specification formation so that people can migrate to the new spec without breaking many old catalogs. This specification should be deprecated and eventually removed.

Jo Rhett (JIRA)

unread,
Jan 24, 2019, 2:55:03 PM1/24/19
to puppe...@googlegroups.com
Jo Rhett commented on Bug PUP-9151

I feel like one of the complications with touching this type is that it's used the most by (A) people who don't understand the other declarative approaches and (B) Enterprises who have very specific time bucket constraints... which are the two markets least prepared for a change in behavior

 

Josh Cooper (Jira)

unread,
Aug 3, 2021, 6:13:04 PM8/3/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
 
Change By: Josh Cooper
Sprint: Community PRs
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Josh Cooper (Jira)

unread,
Aug 3, 2021, 6:13:05 PM8/3/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Aug 3, 2021, 6:14:04 PM8/3/21
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages