Parent

BackgrounDRb::CronTrigger

Constants

WDAYS
(Not documented)
LeapYearMonthDays
(Not documented)
CommonYearMonthDays
(Not documented)

Attributes

cron_expr[R]

(Not documented)

day[R]

(Not documented)

hour[R]

(Not documented)

min[R]

(Not documented)

month[R]

(Not documented)

sec[R]

(Not documented)

wday[R]

(Not documented)

year[R]

(Not documented)

Public Class Methods

new(expr) click to toggle source

initialize the Cron Trigger

    # File server/lib/cron_trigger.rb, line 10
10:     def initialize(expr)
11:       self.cron_expr = expr
12:     end

Public Instance Methods

cron_expr=(expr) click to toggle source

create the cron expression and populate instance variables.

    # File server/lib/cron_trigger.rb, line 15
15:     def cron_expr=(expr)
16:       @cron_expr = expr
17:       self.sec, self.min, self.hour, self.day, self.month, self.wday, self.year = @cron_expr.split(' ')
18:     end
current_time() click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 132
132:     def current_time
133:       Time.local(@t_sec,@t_min,@t_hour,@t_day,@t_month,@t_year,@t_wday,nil,@t_idst,@t_zone)
134:     end
day=(day) click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 151
151:     def day=(day)
152:       @day = parse_part(day, 1 .. 31)
153:     end
day_restricted?() click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 136
136:     def day_restricted?
137:       return !@day.eql?(1..31)
138:     end
fire_after_time(p_time) click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 20
 20:     def fire_after_time(p_time)
 21:       @t_sec,@t_min,@t_hour,@t_day,@t_month,@t_year,@t_wday,@t_yday,@t_idst,@t_zone = p_time.to_a
 22:       @count = 0
 23:       loop do
 24:         @count += 1
 25: 
 26:         if @year && !@year.include?(@t_year)
 27:           return nil if @t_year > @year.max
 28:           @t_year = @year.detect { |y| y > @t_year }
 29:         end
 30: 
 31:         # if range of months doesn't include current month, find next month from the range
 32:         unless @month.include?(@t_month)
 33:           next_month = @month.detect { |m| m > @t_month } || @month.min
 34:           @t_day,@t_hour,@t_min,@t_sec = @day.min,@hour.min,@min.min,@sec.min
 35:           if next_month < @t_month
 36:             @t_month = next_month
 37:             @t_year += 1
 38:             retry
 39:           end
 40:           @t_month = next_month
 41:         end
 42: 
 43:         if !day_restricted? && wday_restricted?
 44:           unless @wday.include?(@t_wday)
 45:             next_wday = @wday.detect { |w| w > @t_wday} || @wday.min
 46:             @t_hour,@t_min,@t_sec = @hour.min,@min.min,@sec.min
 47:             t_time = Chronic.parse("next #{WDAYS[next_wday]}",:now => current_time)
 48:             @t_day,@t_month,@t_year = t_time.to_a[3..5]
 49:             @t_wday = next_wday
 50:             retry
 51:           end
 52:         elsif !wday_restricted? && day_restricted?
 53:           day_range = (1.. month_days(@t_year,@t_month))
 54:           # day array, that includes days which are present in current month
 55:           day_array = @day.select { |d| day_range === d }
 56:           unless day_array.include?(@t_day)
 57:             next_day = day_array.detect { |d| d > @t_day } || day_array.min
 58:             @t_hour,@t_min,@t_sec = @hour.min,@min.min,@sec.min
 59:             if !next_day || next_day < @t_day
 60:               t_time = Chronic.parse("next month",:now => current_time)
 61:               @t_day = next_day.nil? ? @day.min : next_day
 62:               @t_month,@t_year = t_time.month,t_time.year
 63:               retry
 64:             end
 65:             @t_day = next_day
 66:           end
 67:         else
 68:           # if both day and wday are restricted cron should give preference to one thats closer to current time
 69:           day_range = (1 .. month_days(@t_year,@t_month))
 70:           day_array = @day.select { |d| day_range === d }
 71:           if !day_array.include?(@t_day) && !@wday.include?(@t_wday)
 72:             next_day = day_array.detect { |d| d > @t_day } || day_array.min
 73:             next_wday = @wday.detect { |w| w > @t_wday } || @wday.min
 74:             @t_hour,@t_min,@t_sec = @hour.min,@min.min,@sec.min
 75: 
 76:             # if next_day is nil or less than @t_day it means that it should run in next month
 77:             if !next_day || next_day < @t_day
 78:               next_time_mday = Chronic.parse("next month",:now => current_time)
 79:             else
 80:               @t_day = next_day
 81:               next_time_mday = current_time
 82:             end
 83:             next_time_wday = Chronic.parse("next #{WDAYS[next_wday]}",:now => current_time)
 84:             if next_time_mday < next_time_wday
 85:               @t_day,@t_month,@t_year = next_time_mday.to_a[3..5]
 86:             else
 87:               @t_day,@t_month,@t_year = next_time_wday.to_a[3..5]
 88:             end
 89:             retry
 90:           end
 91:         end
 92: 
 93:         unless @hour.include?(@t_hour)
 94:           next_hour = @hour.detect { |h| h > @t_hour } || @hour.min
 95:           @t_min,@t_sec = @min.min,@sec.min
 96:           if next_hour < @t_hour
 97:             @t_hour = next_hour
 98:             next_day = Chronic.parse("next day",:now => current_time)
 99:             @t_day,@t_month,@t_year,@t_wday = next_day.to_a[3..6]
100:             retry
101:           end
102:           @t_hour = next_hour
103:         end
104: 
105:         unless @min.include?(@t_min)
106:           next_min = @min.detect { |m| m > @t_min } || @min.min
107:           @t_sec = @sec.min
108:           if next_min < @t_min
109:             @t_min = next_min
110:             next_hour = Chronic.parse("next hour",:now => current_time)
111:             @t_hour,@t_day,@t_month,@t_year,@t_wday = next_hour.to_a[2..6]
112:             retry
113:           end
114:           @t_min = next_min
115:         end
116: 
117:         unless @sec.include?(@t_sec)
118:           next_sec = @sec.detect { |s| s > @t_sec } || @sec.min
119:           if next_sec < @t_sec
120:             @t_sec = next_sec
121:             next_min = Chronic.parse("next minute",:now => current_time)
122:             @t_min,@t_hour,@t_day,@t_month,@t_year,@t_wday = next_min.to_a[1..6]
123:             retry
124:           end
125:           @t_sec = next_sec
126:         end
127:         break
128:       end # end of loop do
129:       current_time
130:     end
hour=(hour) click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 149
149:     def hour=(hour); @hour = parse_part(hour, 0 .. 23); end
min=(min) click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 147
147:     def min=(min); @min = parse_part(min, 0 .. 59); end
month=(month) click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 155
155:     def month=(month)
156:       @month = parse_part(month, 1 .. 12)
157:     end
sec=(sec) click to toggle source

TODO: mimic attr_reader to define all of these

     # File server/lib/cron_trigger.rb, line 145
145:     def sec=(sec); @sec = parse_part(sec, 0 .. 59); end
wday=(wday) click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 163
163:     def wday=(wday)
164:       @wday = parse_part(wday, 0 .. 6)
165:     end
wday_restricted?() click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 140
140:     def wday_restricted?
141:       return !@wday.eql?(0..6)
142:     end
year=(year) click to toggle source

(Not documented)

     # File server/lib/cron_trigger.rb, line 159
159:     def year=(year)
160:       @year = parse_part(year)
161:     end

secsequence

--- SEC00038

seccomment

--- ""

attributes

--- 
- name: cron_expr
  rw: R
  a_desc: ""
- name: day
  rw: R
  a_desc: ""
- name: hour
  rw: R
  a_desc: ""
- name: min
  rw: R
  a_desc: ""
- name: month
  rw: R
  a_desc: ""
- name: sec
  rw: R
  a_desc: ""
- name: wday
  rw: R
  a_desc: ""
- name: year
  rw: R
  a_desc: ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000116
    name: new
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 10</span>\n\
      10:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>(<span class=\"ruby-identifier\">expr</span>)\n\
      11:       <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">cron_expr</span> = <span class=\"ruby-identifier\">expr</span>\n\
      12:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      initialize the Cron <a href="Trigger.html">Trigger</a>
      </p>
    params: (expr)
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000117
    name: cron_expr=
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 15</span>\n\
      15:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">cron_expr=</span>(<span class=\"ruby-identifier\">expr</span>)\n\
      16:       <span class=\"ruby-ivar\">@cron_expr</span> = <span class=\"ruby-identifier\">expr</span>\n\
      17:       <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">sec</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">min</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">hour</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">day</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">month</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">wday</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">year</span> = <span class=\"ruby-ivar\">@cron_expr</span>.<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-value str\">' '</span>)\n\
      18:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      create the cron expression and populate instance variables.
      </p>
    params: (expr)
  - visibility: public
    aref: M000119
    name: current_time
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 132</span>\n\
      132:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">current_time</span>\n\
      133:       <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">local</span>(<span class=\"ruby-ivar\">@t_sec</span>,<span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span>,<span class=\"ruby-ivar\">@t_wday</span>,<span class=\"ruby-keyword kw\">nil</span>,<span class=\"ruby-ivar\">@t_idst</span>,<span class=\"ruby-ivar\">@t_zone</span>)\n\
      134:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000125
    name: day=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 151</span>\n\
      151:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">day=</span>(<span class=\"ruby-identifier\">day</span>)\n\
      152:       <span class=\"ruby-ivar\">@day</span> = <span class=\"ruby-identifier\">parse_part</span>(<span class=\"ruby-identifier\">day</span>, <span class=\"ruby-value\">1</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-value\">31</span>)\n\
      153:     <span class=\"ruby-keyword kw\">end</span>"
    params: (day)
  - visibility: public
    aref: M000120
    name: day_restricted?
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 136</span>\n\
      136:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">day_restricted?</span>\n\
      137:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-ivar\">@day</span>.<span class=\"ruby-identifier\">eql?</span>(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">31</span>)\n\
      138:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000118
    name: fire_after_time
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 20</span>\n 20:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">fire_after_time</span>(<span class=\"ruby-identifier\">p_time</span>)\n 21:       <span class=\"ruby-ivar\">@t_sec</span>,<span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span>,<span class=\"ruby-ivar\">@t_wday</span>,<span class=\"ruby-ivar\">@t_yday</span>,<span class=\"ruby-ivar\">@t_idst</span>,<span class=\"ruby-ivar\">@t_zone</span> = <span class=\"ruby-identifier\">p_time</span>.<span class=\"ruby-identifier\">to_a</span>\n 22:       <span class=\"ruby-ivar\">@count</span> = <span class=\"ruby-value\">0</span>\n 23:       <span class=\"ruby-identifier\">loop</span> <span class=\"ruby-keyword kw\">do</span>\n 24:         <span class=\"ruby-ivar\">@count</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-value\">1</span>\n 25: \n 26:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@year</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-ivar\">@year</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_year</span>)\n 27:           <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@t_year</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@year</span>.<span class=\"ruby-identifier\">max</span>\n 28:           <span class=\"ruby-ivar\">@t_year</span> = <span class=\"ruby-ivar\">@year</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">y</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">y</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_year</span> }\n 29:         <span class=\"ruby-keyword kw\">end</span>\n 30: \n 31:         <span class=\"ruby-comment cmt\"># if range of months doesn't include current month, find next month from the range</span>\n 32:         <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@month</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_month</span>)\n 33:           <span class=\"ruby-identifier\">next_month</span> = <span class=\"ruby-ivar\">@month</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">m</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">m</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_month</span> } <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@month</span>.<span class=\"ruby-identifier\">min</span>\n 34:           <span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-ivar\">@day</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@hour</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">min</span>\n 35:           <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">next_month</span> <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-ivar\">@t_month</span>\n 36:             <span class=\"ruby-ivar\">@t_month</span> = <span class=\"ruby-identifier\">next_month</span>\n 37:             <span class=\"ruby-ivar\">@t_year</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-value\">1</span>\n 38:             <span class=\"ruby-keyword kw\">retry</span>\n 39:           <span class=\"ruby-keyword kw\">end</span>\n 40:           <span class=\"ruby-ivar\">@t_month</span> = <span class=\"ruby-identifier\">next_month</span>\n 41:         <span class=\"ruby-keyword kw\">end</span>\n 42: \n 43:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-identifier\">day_restricted?</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-identifier\">wday_restricted?</span>\n 44:           <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@wday</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_wday</span>)\n 45:             <span class=\"ruby-identifier\">next_wday</span> = <span class=\"ruby-ivar\">@wday</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">w</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">w</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_wday</span>} <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@wday</span>.<span class=\"ruby-identifier\">min</span>\n 46:             <span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-ivar\">@hour</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">min</span>\n 47:             <span class=\"ruby-identifier\">t_time</span> = <span class=\"ruby-constant\">Chronic</span>.<span class=\"ruby-identifier\">parse</span>(<span class=\"ruby-node\">&quot;next #{WDAYS[next_wday]}&quot;</span>,<span class=\"ruby-identifier\">:now</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">current_time</span>)\n 48:             <span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span> = <span class=\"ruby-identifier\">t_time</span>.<span class=\"ruby-identifier\">to_a</span>[<span class=\"ruby-value\">3</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">5</span>]\n 49:             <span class=\"ruby-ivar\">@t_wday</span> = <span class=\"ruby-identifier\">next_wday</span>\n 50:             <span class=\"ruby-keyword kw\">retry</span>\n 51:           <span class=\"ruby-keyword kw\">end</span>\n 52:         <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-identifier\">wday_restricted?</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-identifier\">day_restricted?</span>\n 53:           <span class=\"ruby-identifier\">day_range</span> = (<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span> <span class=\"ruby-identifier\">month_days</span>(<span class=\"ruby-ivar\">@t_year</span>,<span class=\"ruby-ivar\">@t_month</span>))\n 54:           <span class=\"ruby-comment cmt\"># day array, that includes days which are present in current month</span>\n 55:           <span class=\"ruby-identifier\">day_array</span> = <span class=\"ruby-ivar\">@day</span>.<span class=\"ruby-identifier\">select</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">d</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">day_range</span> <span class=\"ruby-operator\">===</span> <span class=\"ruby-identifier\">d</span> }\n 56:           <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">day_array</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_day</span>)\n 57:             <span class=\"ruby-identifier\">next_day</span> = <span class=\"ruby-identifier\">day_array</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">d</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">d</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_day</span> } <span class=\"ruby-operator\">||</span> <span class=\"ruby-identifier\">day_array</span>.<span class=\"ruby-identifier\">min</span>\n 58:             <span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-ivar\">@hour</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">min</span>\n 59:             <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-identifier\">next_day</span> <span class=\"ruby-operator\">||</span> <span class=\"ruby-identifier\">next_day</span> <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-ivar\">@t_day</span>\n 60:               <span class=\"ruby-identifier\">t_time</span> = <span class=\"ruby-constant\">Chronic</span>.<span class=\"ruby-identifier\">parse</span>(<span class=\"ruby-value str\">&quot;next month&quot;</span>,<span class=\"ruby-identifier\">:now</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">current_time</span>)\n 61:               <span class=\"ruby-ivar\">@t_day</span> = <span class=\"ruby-identifier\">next_day</span>.<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-value\">? </span><span class=\"ruby-ivar\">@day</span>.<span class=\"ruby-identifier\">min</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-identifier\">next_day</span>\n 62:               <span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span> = <span class=\"ruby-identifier\">t_time</span>.<span class=\"ruby-identifier\">month</span>,<span class=\"ruby-identifier\">t_time</span>.<span class=\"ruby-identifier\">year</span>\n 63:               <span class=\"ruby-keyword kw\">retry</span>\n 64:             <span class=\"ruby-keyword kw\">end</span>\n 65:             <span class=\"ruby-ivar\">@t_day</span> = <span class=\"ruby-identifier\">next_day</span>\n 66:           <span class=\"ruby-keyword kw\">end</span>\n 67:         <span class=\"ruby-keyword kw\">else</span>\n 68:           <span class=\"ruby-comment cmt\"># if both day and wday are restricted cron should give preference to one thats closer to current time</span>\n 69:           <span class=\"ruby-identifier\">day_range</span> = (<span class=\"ruby-value\">1</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-identifier\">month_days</span>(<span class=\"ruby-ivar\">@t_year</span>,<span class=\"ruby-ivar\">@t_month</span>))\n 70:           <span class=\"ruby-identifier\">day_array</span> = <span class=\"ruby-ivar\">@day</span>.<span class=\"ruby-identifier\">select</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">d</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">day_range</span> <span class=\"ruby-operator\">===</span> <span class=\"ruby-identifier\">d</span> }\n 71:           <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-identifier\">day_array</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_day</span>) <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-ivar\">@wday</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_wday</span>)\n 72:             <span class=\"ruby-identifier\">next_day</span> = <span class=\"ruby-identifier\">day_array</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">d</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">d</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_day</span> } <span class=\"ruby-operator\">||</span> <span class=\"ruby-identifier\">day_array</span>.<span class=\"ruby-identifier\">min</span>\n 73:             <span class=\"ruby-identifier\">next_wday</span> = <span class=\"ruby-ivar\">@wday</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">w</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">w</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_wday</span> } <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@wday</span>.<span class=\"ruby-identifier\">min</span>\n 74:             <span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-ivar\">@hour</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">min</span>\n 75: \n 76:             <span class=\"ruby-comment cmt\"># if next_day is nil or less than @t_day it means that it should run in next month</span>\n 77:             <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-identifier\">next_day</span> <span class=\"ruby-operator\">||</span> <span class=\"ruby-identifier\">next_day</span> <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-ivar\">@t_day</span>\n 78:               <span class=\"ruby-identifier\">next_time_mday</span> = <span class=\"ruby-constant\">Chronic</span>.<span class=\"ruby-identifier\">parse</span>(<span class=\"ruby-value str\">&quot;next month&quot;</span>,<span class=\"ruby-identifier\">:now</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">current_time</span>)\n 79:             <span class=\"ruby-keyword kw\">else</span>\n 80:               <span class=\"ruby-ivar\">@t_day</span> = <span class=\"ruby-identifier\">next_day</span>\n 81:               <span class=\"ruby-identifier\">next_time_mday</span> = <span class=\"ruby-identifier\">current_time</span>\n 82:             <span class=\"ruby-keyword kw\">end</span>\n 83:             <span class=\"ruby-identifier\">next_time_wday</span> = <span class=\"ruby-constant\">Chronic</span>.<span class=\"ruby-identifier\">parse</span>(<span class=\"ruby-node\">&quot;next #{WDAYS[next_wday]}&quot;</span>,<span class=\"ruby-identifier\">:now</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">current_time</span>)\n 84:             <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">next_time_mday</span> <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-identifier\">next_time_wday</span>\n 85:               <span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span> = <span class=\"ruby-identifier\">next_time_mday</span>.<span class=\"ruby-identifier\">to_a</span>[<span class=\"ruby-value\">3</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">5</span>]\n 86:             <span class=\"ruby-keyword kw\">else</span>\n 87:               <span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span> = <span class=\"ruby-identifier\">next_time_wday</span>.<span class=\"ruby-identifier\">to_a</span>[<span class=\"ruby-value\">3</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">5</span>]\n 88:             <span class=\"ruby-keyword kw\">end</span>\n 89:             <span class=\"ruby-keyword kw\">retry</span>\n 90:           <span class=\"ruby-keyword kw\">end</span>\n 91:         <span class=\"ruby-keyword kw\">end</span>\n 92: \n 93:         <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@hour</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_hour</span>)\n 94:           <span class=\"ruby-identifier\">next_hour</span> = <span class=\"ruby-ivar\">@hour</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">h</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">h</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_hour</span> } <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@hour</span>.<span class=\"ruby-identifier\">min</span>\n 95:           <span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">min</span>,<span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">min</span>\n 96:           <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">next_hour</span> <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-ivar\">@t_hour</span>\n 97:             <span class=\"ruby-ivar\">@t_hour</span> = <span class=\"ruby-identifier\">next_hour</span>\n 98:             <span class=\"ruby-identifier\">next_day</span> = <span class=\"ruby-constant\">Chronic</span>.<span class=\"ruby-identifier\">parse</span>(<span class=\"ruby-value str\">&quot;next day&quot;</span>,<span class=\"ruby-identifier\">:now</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">current_time</span>)\n 99:             <span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span>,<span class=\"ruby-ivar\">@t_wday</span> = <span class=\"ruby-identifier\">next_day</span>.<span class=\"ruby-identifier\">to_a</span>[<span class=\"ruby-value\">3</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">6</span>]\n\
      100:             <span class=\"ruby-keyword kw\">retry</span>\n\
      101:           <span class=\"ruby-keyword kw\">end</span>\n\
      102:           <span class=\"ruby-ivar\">@t_hour</span> = <span class=\"ruby-identifier\">next_hour</span>\n\
      103:         <span class=\"ruby-keyword kw\">end</span>\n\
      104: \n\
      105:         <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_min</span>)\n\
      106:           <span class=\"ruby-identifier\">next_min</span> = <span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">m</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">m</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_min</span> } <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@min</span>.<span class=\"ruby-identifier\">min</span>\n\
      107:           <span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">min</span>\n\
      108:           <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">next_min</span> <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-ivar\">@t_min</span>\n\
      109:             <span class=\"ruby-ivar\">@t_min</span> = <span class=\"ruby-identifier\">next_min</span>\n\
      110:             <span class=\"ruby-identifier\">next_hour</span> = <span class=\"ruby-constant\">Chronic</span>.<span class=\"ruby-identifier\">parse</span>(<span class=\"ruby-value str\">&quot;next hour&quot;</span>,<span class=\"ruby-identifier\">:now</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">current_time</span>)\n\
      111:             <span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span>,<span class=\"ruby-ivar\">@t_wday</span> = <span class=\"ruby-identifier\">next_hour</span>.<span class=\"ruby-identifier\">to_a</span>[<span class=\"ruby-value\">2</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">6</span>]\n\
      112:             <span class=\"ruby-keyword kw\">retry</span>\n\
      113:           <span class=\"ruby-keyword kw\">end</span>\n\
      114:           <span class=\"ruby-ivar\">@t_min</span> = <span class=\"ruby-identifier\">next_min</span>\n\
      115:         <span class=\"ruby-keyword kw\">end</span>\n\
      116: \n\
      117:         <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">include?</span>(<span class=\"ruby-ivar\">@t_sec</span>)\n\
      118:           <span class=\"ruby-identifier\">next_sec</span> = <span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">detect</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">s</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">s</span> <span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-ivar\">@t_sec</span> } <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@sec</span>.<span class=\"ruby-identifier\">min</span>\n\
      119:           <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">next_sec</span> <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-ivar\">@t_sec</span>\n\
      120:             <span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-identifier\">next_sec</span>\n\
      121:             <span class=\"ruby-identifier\">next_min</span> = <span class=\"ruby-constant\">Chronic</span>.<span class=\"ruby-identifier\">parse</span>(<span class=\"ruby-value str\">&quot;next minute&quot;</span>,<span class=\"ruby-identifier\">:now</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">current_time</span>)\n\
      122:             <span class=\"ruby-ivar\">@t_min</span>,<span class=\"ruby-ivar\">@t_hour</span>,<span class=\"ruby-ivar\">@t_day</span>,<span class=\"ruby-ivar\">@t_month</span>,<span class=\"ruby-ivar\">@t_year</span>,<span class=\"ruby-ivar\">@t_wday</span> = <span class=\"ruby-identifier\">next_min</span>.<span class=\"ruby-identifier\">to_a</span>[<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">6</span>]\n\
      123:             <span class=\"ruby-keyword kw\">retry</span>\n\
      124:           <span class=\"ruby-keyword kw\">end</span>\n\
      125:           <span class=\"ruby-ivar\">@t_sec</span> = <span class=\"ruby-identifier\">next_sec</span>\n\
      126:         <span class=\"ruby-keyword kw\">end</span>\n\
      127:         <span class=\"ruby-keyword kw\">break</span>\n\
      128:       <span class=\"ruby-keyword kw\">end</span> <span class=\"ruby-comment cmt\"># end of loop do</span>\n\
      129:       <span class=\"ruby-identifier\">current_time</span>\n\
      130:     <span class=\"ruby-keyword kw\">end</span>"
    params: (p_time)
  - visibility: public
    aref: M000124
    name: hour=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 149</span>\n\
      149:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">hour=</span>(<span class=\"ruby-identifier\">hour</span>); <span class=\"ruby-ivar\">@hour</span> = <span class=\"ruby-identifier\">parse_part</span>(<span class=\"ruby-identifier\">hour</span>, <span class=\"ruby-value\">0</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-value\">23</span>); <span class=\"ruby-keyword kw\">end</span>"
    params: (hour)
  - visibility: public
    aref: M000123
    name: min=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 147</span>\n\
      147:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">min=</span>(<span class=\"ruby-identifier\">min</span>); <span class=\"ruby-ivar\">@min</span> = <span class=\"ruby-identifier\">parse_part</span>(<span class=\"ruby-identifier\">min</span>, <span class=\"ruby-value\">0</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-value\">59</span>); <span class=\"ruby-keyword kw\">end</span>"
    params: (min)
  - visibility: public
    aref: M000126
    name: month=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 155</span>\n\
      155:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">month=</span>(<span class=\"ruby-identifier\">month</span>)\n\
      156:       <span class=\"ruby-ivar\">@month</span> = <span class=\"ruby-identifier\">parse_part</span>(<span class=\"ruby-identifier\">month</span>, <span class=\"ruby-value\">1</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-value\">12</span>)\n\
      157:     <span class=\"ruby-keyword kw\">end</span>"
    params: (month)
  - visibility: public
    aref: M000122
    name: sec=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 145</span>\n\
      145:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">sec=</span>(<span class=\"ruby-identifier\">sec</span>); <span class=\"ruby-ivar\">@sec</span> = <span class=\"ruby-identifier\">parse_part</span>(<span class=\"ruby-identifier\">sec</span>, <span class=\"ruby-value\">0</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-value\">59</span>); <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      TODO: mimic attr_reader to define all of these
      </p>
    params: (sec)
  - visibility: public
    aref: M000128
    name: wday=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 163</span>\n\
      163:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">wday=</span>(<span class=\"ruby-identifier\">wday</span>)\n\
      164:       <span class=\"ruby-ivar\">@wday</span> = <span class=\"ruby-identifier\">parse_part</span>(<span class=\"ruby-identifier\">wday</span>, <span class=\"ruby-value\">0</span> <span class=\"ruby-operator\">..</span> <span class=\"ruby-value\">6</span>)\n\
      165:     <span class=\"ruby-keyword kw\">end</span>"
    params: (wday)
  - visibility: public
    aref: M000121
    name: wday_restricted?
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 140</span>\n\
      140:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">wday_restricted?</span>\n\
      141:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-ivar\">@wday</span>.<span class=\"ruby-identifier\">eql?</span>(<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">6</span>)\n\
      142:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000127
    name: year=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/cron_trigger.rb, line 159</span>\n\
      159:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">year=</span>(<span class=\"ruby-identifier\">year</span>)\n\
      160:       <span class=\"ruby-ivar\">@year</span> = <span class=\"ruby-identifier\">parse_part</span>(<span class=\"ruby-identifier\">year</span>)\n\
      161:     <span class=\"ruby-keyword kw\">end</span>"
    params: (year)
  category: Instance
  type: Public

sectitle

--- 

constants

--- 
- name: WDAYS
  value: "{ 0 =&gt; &quot;Sunday&quot;,1 =&gt; &quot;Monday&quot;,2 =&gt; &quot;Tuesday&quot;,3 =&gt; &quot;Wednesday&quot;, 4 =&gt; &quot;Thursday&quot;, 5 =&gt; &quot;Friday&quot;, 6 =&gt; &quot;Saturday&quot; }"
- name: LeapYearMonthDays
  value: "[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]"
- name: CommonYearMonthDays
  value: "[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]"

[Validate]

Generated with the Darkfish Rdoc Generator.