openwferu-scheduler 0.9.15.1128 → 0.9.15.1172

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,6 +53,9 @@ module OpenWFE
53
53
  to_iso8601_date(Time.new())
54
54
  end
55
55
 
56
+ #
57
+ # As the name implies.
58
+ #
56
59
  def OpenWFE.to_iso8601_date (date)
57
60
 
58
61
  if date.kind_of? Float
@@ -143,6 +143,17 @@ module OpenWFE
143
143
  # prevents you from using anything else. The scheduler has no persistence
144
144
  # by itself, so no serialization issue.
145
145
  #
146
+ #
147
+ # Since OpenWFEru 0.9.16, a cron schedule can be set at the second level :
148
+ #
149
+ # scheduler.schedule "7 * * * * *" do
150
+ # puts "it's now the seventh second of the minute"
151
+ # end
152
+ #
153
+ # The OpenWFEru scheduler recognizes an optional first column for second
154
+ # scheduling. This column can, like for the other columns, specify a
155
+ # value ("7"), a list of values ("7,8,9,27") or a range ("7-12").
156
+ #
146
157
  class Scheduler
147
158
  include MonitorMixin
148
159
 
@@ -178,7 +189,7 @@ module OpenWFE
178
189
  @exit_when_no_more_jobs = false
179
190
  @dont_reschedule_every = false
180
191
 
181
- @last_cron_minute = -1
192
+ @last_cron_second = -1
182
193
 
183
194
  @stopped = true
184
195
  end
@@ -657,15 +668,15 @@ module OpenWFE
657
668
  @dont_reschedule_every = true if at_job_count < 1
658
669
  end
659
670
 
671
+ # TODO : eventually consider running cron / pending
672
+ # job triggering in two different threads
673
+
660
674
  #
661
675
  # cron jobs
662
676
 
663
- if now.sec == 0 and now.min != @last_cron_minute
664
- #
665
- # only consider cron jobs at the second 0 of a
666
- # minute
677
+ if now.sec != @last_cron_second
667
678
 
668
- @last_cron_minute = now.min
679
+ @last_cron_second = now.sec
669
680
 
670
681
  #puts "step() @cron_jobs.size #{@cron_jobs.size}"
671
682
 
@@ -845,6 +856,7 @@ module OpenWFE
845
856
  class CronLine
846
857
 
847
858
  attr_reader \
859
+ :seconds,
848
860
  :minutes,
849
861
  :hours,
850
862
  :days,
@@ -857,19 +869,26 @@ module OpenWFE
857
869
 
858
870
  items = line.split
859
871
 
860
- if items.length != 5
872
+ unless [ 5, 6 ].include?(items.length)
861
873
  raise \
862
- "cron '#{line}' string should hold 5 items, " +
874
+ "cron '#{line}' string should hold 5 or 6 items, " +
863
875
  "not #{items.length}" \
864
876
  end
865
877
 
866
- @minutes = parse_item(items[0], 0, 59)
867
- @hours = parse_item(items[1], 0, 24)
868
- @days = parse_item(items[2], 1, 31)
869
- @months = parse_item(items[3], 1, 12)
870
- @weekdays = parse_weekdays(items[4])
878
+ offset = items.length - 5
879
+
880
+ @seconds = if offset == 1
881
+ parse_item(items[0], 0, 59)
882
+ else
883
+ [ 0 ]
884
+ end
885
+ @minutes = parse_item(items[0+offset], 0, 59)
886
+ @hours = parse_item(items[1+offset], 0, 24)
887
+ @days = parse_item(items[2+offset], 1, 31)
888
+ @months = parse_item(items[3+offset], 1, 12)
889
+ @weekdays = parse_weekdays(items[4+offset])
871
890
 
872
- adjust_arrays()
891
+ #adjust_arrays()
873
892
  end
874
893
 
875
894
  def matches? (time)
@@ -878,6 +897,7 @@ module OpenWFE
878
897
  time = Time.at(time)
879
898
  end
880
899
 
900
+ return false if no_match?(time.sec, @seconds)
881
901
  return false if no_match?(time.min, @minutes)
882
902
  return false if no_match?(time.hour, @hours)
883
903
  return false if no_match?(time.day, @days)
@@ -888,12 +908,12 @@ module OpenWFE
888
908
  end
889
909
 
890
910
  #
891
- # Returns an array of 5 arrays (minutes, hours, days, months,
892
- # weekdays).
911
+ # Returns an array of 6 arrays (seconds, minutes, hours, days,
912
+ # months, weekdays).
893
913
  # This method is used by the cronline unit tests.
894
914
  #
895
915
  def to_array
896
- [ @minutes, @hours, @days, @months, @weekdays ]
916
+ [ @seconds, @minutes, @hours, @days, @months, @weekdays ]
897
917
  end
898
918
 
899
919
  private
@@ -901,18 +921,20 @@ module OpenWFE
901
921
  #
902
922
  # adjust values to Ruby
903
923
  #
904
- def adjust_arrays()
905
- if @hours
906
- @hours.each do |h|
907
- h = 0 if h == 23
908
- end
909
- end
910
- if @weekdays
911
- @weekdays.each do |wd|
912
- wd = wd - 1
913
- end
914
- end
915
- end
924
+ #def adjust_arrays()
925
+ # @hours = @hours.collect { |h|
926
+ # if h == 24
927
+ # 0
928
+ # else
929
+ # h
930
+ # end
931
+ # } if @hours
932
+ # @weekdays = @weekdays.collect { |wd|
933
+ # wd - 1
934
+ # } if @weekdays
935
+ #end
936
+ #
937
+ # dead code
916
938
 
917
939
  WDS = [ "mon", "tue", "wed", "thu", "fri", "sat", "sun" ]
918
940
  #
@@ -947,6 +969,7 @@ module OpenWFE
947
969
  end
948
970
 
949
971
  def parse_list (item, min, max)
972
+
950
973
  items = item.split(",")
951
974
  result = []
952
975
  items.each do |i|
@@ -959,6 +982,7 @@ module OpenWFE
959
982
  end
960
983
 
961
984
  def parse_range (item, min, max)
985
+
962
986
  i = item.index("-")
963
987
  j = item.index("/")
964
988
 
@@ -980,6 +1004,7 @@ module OpenWFE
980
1004
  end
981
1005
 
982
1006
  else # case */x
1007
+
983
1008
  istart = min
984
1009
  iend = max
985
1010
  end
@@ -991,6 +1016,7 @@ module OpenWFE
991
1016
 
992
1017
  value = istart
993
1018
  while true
1019
+
994
1020
  result << value
995
1021
  value = value + inc
996
1022
  break if value > iend
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: openwferu-scheduler
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.15.1128
7
- date: 2007-10-07 00:00:00 +09:00
6
+ version: 0.9.15.1172
7
+ date: 2007-10-18 00:00:00 +09:00
8
8
  summary: OpenWFEru scheduler for Ruby (at, cron and every)
9
9
  require_paths:
10
10
  - lib