openwferu-scheduler 0.9.11 → 0.9.12.826

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,7 +51,8 @@ module OpenWFE
51
51
  # Returns the current time as an ISO date string
52
52
  #
53
53
  def OpenWFE.now ()
54
- return to_iso8601_date(Time.new())
54
+
55
+ to_iso8601_date(Time.new())
55
56
  end
56
57
 
57
58
  def OpenWFE.to_iso8601_date (date)
@@ -64,10 +65,10 @@ module OpenWFE
64
65
  date = DateTime.parse(date)
65
66
  end
66
67
 
67
- s = date.to_s
68
+ s = date.to_s # this is costly
68
69
  s[10] = " "
69
70
 
70
- return s
71
+ s
71
72
  end
72
73
 
73
74
  #
@@ -89,7 +90,7 @@ module OpenWFE
89
90
  #
90
91
  def OpenWFE.to_ruby_time (iso_date)
91
92
 
92
- return DateTime.parse(iso_date)
93
+ DateTime.parse(iso_date)
93
94
  end
94
95
 
95
96
  #def OpenWFE.parse_date (date)
@@ -102,7 +103,7 @@ module OpenWFE
102
103
 
103
104
  t = Time.new()
104
105
  t = t.to_f * 1000
105
- return t.to_i
106
+ t.to_i
106
107
  end
107
108
 
108
109
  #
@@ -154,7 +155,7 @@ module OpenWFE
154
155
  result = result + (value * multiplier)
155
156
  end
156
157
 
157
- return result
158
+ result
158
159
  end
159
160
 
160
161
  #
@@ -163,7 +164,7 @@ module OpenWFE
163
164
  def OpenWFE.is_digit? (c)
164
165
  return false if not c.kind_of?(String)
165
166
  return false if c.length > 1
166
- return (c >= "0" and c <= "9")
167
+ (c >= "0" and c <= "9")
167
168
  end
168
169
 
169
170
  #
@@ -185,7 +186,7 @@ module OpenWFE
185
186
 
186
187
  begin
187
188
 
188
- return DateTime.new(
189
+ DateTime.new(
189
190
  time.year,
190
191
  time.month,
191
192
  time.day,
@@ -204,7 +205,7 @@ module OpenWFE
204
205
  # "\n....y:#{time.year} M:#{time.month} d:#{time.day} "+
205
206
  # "h:#{time.hour} m:#{time.min} s:#{s} o:#{o}"
206
207
 
207
- return DateTime.new(
208
+ DateTime.new(
208
209
  time.year,
209
210
  time.month,
210
211
  time.day,
@@ -223,7 +224,7 @@ module OpenWFE
223
224
  to_ttime(dtime.new_offset(DateTime.now.offset-offset), :local)
224
225
  end
225
226
 
226
- def to_ttime (d, method)
227
+ def OpenWFE.to_ttime (d, method)
227
228
  usec = (d.sec_fraction * 3600 * 24 * (10**6)).to_i
228
229
  Time.send(method, d.year, d.month, d.day, d.hour, d.min, d.sec, usec)
229
230
  end
@@ -40,7 +40,6 @@
40
40
  #
41
41
 
42
42
  require 'monitor'
43
-
44
43
  require 'openwfe/util/otime'
45
44
 
46
45
 
@@ -105,14 +104,31 @@ module OpenWFE
105
104
  # This attribute is best used indirectly : the method
106
105
  # join_until_no_more_jobs() wraps it.
107
106
  #
107
+ # Since OpenWFEru 0.9.13, the :scheduler_precision can be set when
108
+ # instantiating the scheduler.
109
+ #
110
+ # scheduler = OpenWFE::Scheduler.new(:scheduler_precision => 0.500)
111
+ # scheduler.start
112
+ # #
113
+ # # instatiates a scheduler that checks its jobs twice per second
114
+ # # (the default is 4 times per second (0.250))
115
+ #
108
116
  class Scheduler
109
117
  include MonitorMixin
110
118
 
111
- attr_accessor \
112
- :precision,
113
- :exit_when_no_more_jobs
119
+ #
120
+ # By default, the precision is 0.250, with means the scheduler
121
+ # will check for jobs to execute 4 times per second.
122
+ #
123
+ attr_accessor :precision
114
124
 
115
- def initialize
125
+ #
126
+ # As its name implies.
127
+ #
128
+ attr_accessor :stopped
129
+
130
+
131
+ def initialize (params={})
116
132
 
117
133
  super()
118
134
 
@@ -122,15 +138,19 @@ module OpenWFE
122
138
  @scheduler_thread = nil
123
139
 
124
140
  @precision = 0.250
125
- #
126
- # every 250ms, the scheduler wakes up
141
+ # every 250ms, the scheduler wakes up (default value)
142
+ begin
143
+ @precision = Float(params[:scheduler_precision])
144
+ rescue Exception => e
145
+ # let precision at its default value
146
+ end
127
147
 
128
148
  @exit_when_no_more_jobs = false
129
149
  @dont_reschedule_every = false
130
150
 
131
151
  @last_cron_minute = -1
132
152
 
133
- @stopped = false
153
+ @stopped = true
134
154
  end
135
155
 
136
156
  #
@@ -138,11 +158,19 @@ module OpenWFE
138
158
  #
139
159
  def sstart
140
160
 
161
+ @stopped = false
162
+
141
163
  @scheduler_thread = Thread.new do
164
+
165
+ if defined?(JRUBY_VERSION)
166
+ require 'java'
167
+ java.lang.Thread.current_thread.name = "openwferu scheduler (Ruby Thread)"
168
+ end
169
+
142
170
  while true
143
171
  break if @stopped
144
172
  step
145
- sleep(@precision)
173
+ sleep @precision
146
174
  end
147
175
  end
148
176
  end
@@ -184,6 +212,9 @@ module OpenWFE
184
212
  # Schedules a job by specifying at which time it should trigger.
185
213
  # Returns the a job_id that can be used to unschedule the job.
186
214
  #
215
+ # This method returns a job identifier which can be used to unschedule()
216
+ # the job.
217
+ #
187
218
  def schedule_at (at, params={}, &block)
188
219
 
189
220
  params = prepare_params(params)
@@ -196,6 +227,9 @@ module OpenWFE
196
227
  # Schedules a job by stating in how much time it should trigger.
197
228
  # Returns the a job_id that can be used to unschedule the job.
198
229
  #
230
+ # This method returns a job identifier which can be used to unschedule()
231
+ # the job.
232
+ #
199
233
  def schedule_in (duration, params={}, &block)
200
234
 
201
235
  duration = duration_to_f(duration)
@@ -218,6 +252,9 @@ module OpenWFE
218
252
  # end
219
253
  # end
220
254
  #
255
+ # This method returns a job identifier which can be used to unschedule()
256
+ # the job.
257
+ #
221
258
  def schedule_every (freq, params={}, &block)
222
259
 
223
260
  f = duration_to_f freq
@@ -277,7 +314,7 @@ module OpenWFE
277
314
  #
278
315
  # Schedules a cron job, the 'cron_line' is a string
279
316
  # following the Unix cron standard (see "man 5 crontab" in your command
280
- # line).
317
+ # line, or http://www.google.com/search?q=man%205%20crontab).
281
318
  #
282
319
  # For example :
283
320
  #
@@ -296,8 +333,10 @@ module OpenWFE
296
333
  # Returns the job id attributed to this 'cron job', this id can
297
334
  # be used to unschedule the job.
298
335
  #
336
+ # This method returns a job identifier which can be used to unschedule()
337
+ # the job.
338
+ #
299
339
  def schedule (cron_line, params={}, &block)
300
-
301
340
  synchronize do
302
341
 
303
342
  params = prepare_params(params)
@@ -397,8 +436,11 @@ module OpenWFE
397
436
  params
398
437
  end
399
438
 
439
+ #
440
+ # The core method behind schedule_at and schedule_in (and also
441
+ # schedule_every). It's protected, don't use it directly.
442
+ #
400
443
  def sschedule_at (at, params={}, &block)
401
-
402
444
  synchronize do
403
445
 
404
446
  #puts "0 at is '#{at.to_s}' (#{at.class})"
@@ -428,7 +470,7 @@ module OpenWFE
428
470
  unschedule(job_id) if job_id
429
471
 
430
472
  if at < (Time.new.to_f + @precision)
431
- job.trigger()
473
+ job.trigger() unless params[:discard_past]
432
474
  return nil
433
475
  end
434
476
 
@@ -509,7 +551,7 @@ module OpenWFE
509
551
 
510
552
  #puts "push() at '#{Time.at(job.at)}'"
511
553
 
512
- return job.eid
554
+ job.eid
513
555
  end
514
556
 
515
557
  #
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: openwferu-scheduler
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.11
7
- date: 2007-06-06 00:00:00 +09:00
6
+ version: 0.9.12.826
7
+ date: 2007-07-20 00:00:00 +09:00
8
8
  summary: OpenWFEru scheduler for Ruby (at, cron and every)
9
9
  require_paths:
10
10
  - lib