rufus-scheduler 2.0.9 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.txt CHANGED
@@ -2,7 +2,12 @@
2
2
  = rufus-scheduler CHANGELOG.txt
3
3
 
4
4
 
5
- == rufus-scheduler - 2.0.9 released 2010/04/22
5
+ == rufus-scheduler - 2.0.10 released 2011/06/26
6
+
7
+ - every and allow_overlapping now surviving exceptions. Thanks sha1dy
8
+
9
+
10
+ == rufus-scheduler - 2.0.9 released 2011/04/22
6
11
 
7
12
  - Scheduler#first_at and :discard_past => true. Thanks concept47
8
13
  - Scheduler#cron and monthdays (sun#2 or mon#1)
@@ -16,6 +21,7 @@
16
21
 
17
22
  == rufus-scheduler - 2.0.7 released 2010/11/09
18
23
 
24
+ - :allow_overlapping => false, thanks Adam Davies
19
25
  - cron and timezones, thanks Tanzeeb Khalili
20
26
  - Scheduler#trigger_threads, thanks Tim Uckun
21
27
 
data/CREDITS.txt CHANGED
@@ -7,13 +7,14 @@
7
7
  - concept47 (https://github.com/concept47) every and :discard_past
8
8
  - Chris Kampemeier (http://github.com/chrisk) rspec 2.0 refinements
9
9
  - Tanzeeb Khalili (http://github.com/tanzeeb) cron and timezones
10
- - Adam Davies (http://github.com/adz), @allow_overlap = false
10
+ - Adam Davies (http://github.com/adz), :allow_overlapping => false
11
11
  - Klaas Jan Wierenga, at/every/in stress tests (1.0 and 2.0)
12
12
  - TobyH (http://github.com/tobyh), faster and cleaner CronLine#next_time
13
13
 
14
14
 
15
15
  == Feedback
16
16
 
17
+ - sha1dy - https://github.com/sha1dy - every and overlapping exception issue
17
18
  - Defusal - unschedule_by_tag
18
19
  - pickerel - https://github.com/pickerel
19
20
  - Gonzalo Suarez - parse_time_string(s) issue
data/README.rdoc CHANGED
@@ -158,7 +158,7 @@ http://rufus.rubyforge.org/rufus-scheduler/classes/Rufus/Scheduler/Job.html
158
158
  p Rufus.to_time_string 7 * 24 * 3600 # => "1w"
159
159
 
160
160
 
161
- == :blocking
161
+ == :blocking => true
162
162
 
163
163
  Jobs will, by default, trigger in their own thread. This is usually desirable since one expects the scheduler to continue scheduling even if a job is currently running.
164
164
 
@@ -175,6 +175,27 @@ Jobs scheduled with the :blocking parameter will run in the thread of the schedu
175
175
  Hence, our espresso will come in 22 minutes instead of 21.
176
176
 
177
177
 
178
+ == :allow_overlapping => false
179
+
180
+ By default, every and cron jobs will "overlap" :
181
+
182
+ scheduler.every '3s' do
183
+ 4.times do
184
+ puts "hello!"
185
+ sleep 1
186
+ end
187
+ end
188
+
189
+ This every job, will have overlaps. To prevent that :
190
+
191
+ scheduler.every '3s', :allow_overlapping => false do
192
+ 4.times do
193
+ puts "hello!"
194
+ sleep 1
195
+ end
196
+ end
197
+
198
+
178
199
  == 'every' jobs and :first_at / :first_in
179
200
 
180
201
  This job will execute every 3 days, but first time will be in 5 days from now :
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ CLEAN.include('pkg', 'rdoc')
20
20
 
21
21
  #task :spec => :check_dependencies do
22
22
  task :spec do
23
- sh 'rspec spec/'
23
+ exec 'rspec spec/'
24
24
  end
25
25
  task :test => :spec
26
26
 
data/lib/rufus/sc/jobs.rb CHANGED
@@ -67,8 +67,6 @@ module Scheduler
67
67
  #
68
68
  attr_reader :job_id
69
69
 
70
- attr_accessor :running
71
-
72
70
  # Instantiating the job.
73
71
  #
74
72
  def initialize(scheduler, t, params, &block)
@@ -79,10 +77,6 @@ module Scheduler
79
77
  @block = block || params[:schedulable]
80
78
 
81
79
  @running = false
82
- @allow_overlapping = true
83
- if !params[:allow_overlapping].nil?
84
- @allow_overlapping = params[:allow_overlapping]
85
- end
86
80
 
87
81
  raise ArgumentError.new(
88
82
  'no block or :schedulable passed, nothing to schedule'
@@ -95,6 +89,15 @@ module Scheduler
95
89
  determine_at
96
90
  end
97
91
 
92
+ # Returns true if this job is currently running (in the middle of #trigger)
93
+ #
94
+ def running
95
+
96
+ @running
97
+ end
98
+
99
+ alias running? running
100
+
98
101
  # Returns the list of tags attached to the job.
99
102
  #
100
103
  def tags
@@ -126,9 +129,10 @@ module Scheduler
126
129
  job_thread = nil
127
130
  to_job = nil
128
131
 
129
- return if @running && !@allow_overlapping
132
+ return if @running and (params[:allow_overlapping] == false)
130
133
 
131
134
  @running = true
135
+
132
136
  @scheduler.send(:trigger_job, @params[:blocking]) do
133
137
  #
134
138
  # Note that #trigger_job is protected, hence the #send
@@ -147,12 +151,12 @@ module Scheduler
147
151
  job_thread = nil
148
152
  to_job.unschedule if to_job
149
153
 
150
- @running = false
151
-
152
154
  rescue Exception => e
153
155
 
154
156
  @scheduler.handle_exception(self, e)
155
157
  end
158
+
159
+ @running = false
156
160
  end
157
161
 
158
162
  # note that add_job and add_cron_job ensured that :blocking is
@@ -169,7 +173,6 @@ module Scheduler
169
173
  end
170
174
  end
171
175
  end
172
-
173
176
  end
174
177
 
175
178
  # Simply encapsulating the block#call/trigger operation, for easy
@@ -26,7 +26,7 @@
26
26
  module Rufus
27
27
  module Scheduler
28
28
 
29
- VERSION = '2.0.9'
29
+ VERSION = '2.0.10'
30
30
  end
31
31
  end
32
32
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- load 'lib/rufus/sc/version.rb'
3
+ require File.join(File.dirname(__FILE__), 'lib/rufus/sc/version')
4
+ # bundler wants absolute path
4
5
 
5
6
 
6
7
  Gem::Specification.new do |s|
data/spec/at_spec.rb CHANGED
@@ -101,35 +101,3 @@ describe "#{SCHEDULER_CLASS}#schedule_at" do
101
101
  end
102
102
  end
103
103
 
104
- describe Rufus::Scheduler::AtJob do
105
-
106
- before do
107
- @s = start_scheduler
108
- end
109
- after do
110
- stop_scheduler(@s)
111
- end
112
-
113
- it 'unschedules itself' do
114
-
115
- job = @s.at Time.now + 3 * 3600 do
116
- end
117
-
118
- wait_next_tick
119
-
120
- job.unschedule
121
-
122
- @s.jobs.size.should == 0
123
- end
124
-
125
- it 'responds to #next_time' do
126
-
127
- t = Time.now + 3 * 3600
128
-
129
- job = @s.at Time.now + 3 * 3600 do
130
- end
131
-
132
- job.next_time.to_i.should == t.to_i
133
- end
134
- end
135
-
data/spec/cron_spec.rb CHANGED
@@ -99,24 +99,5 @@ describe "#{SCHEDULER_CLASS}#cron" do
99
99
  @s.jobs.size.should == 0
100
100
  stack.should == %w[ ok ok ok done ]
101
101
  end
102
-
103
- end
104
-
105
- describe Rufus::Scheduler::CronJob do
106
-
107
- before(:each) do
108
- @s = start_scheduler
109
- end
110
- after(:each) do
111
- stop_scheduler(@s)
112
- end
113
-
114
- it 'responds to #next_time' do
115
-
116
- job = @s.cron '* * * * *' do
117
- end
118
-
119
- (job.next_time.to_i - Time.now.to_i).should satisfy { |v| v < 60 }
120
- end
121
102
  end
122
103
 
data/spec/every_spec.rb CHANGED
@@ -202,29 +202,8 @@ describe "#{SCHEDULER_CLASS}#every" do
202
202
 
203
203
  @s.trigger_threads.size.should == 4
204
204
  end
205
- end
206
-
207
- describe Rufus::Scheduler::EveryJob do
208
-
209
- before(:each) do
210
- @s = start_scheduler
211
- end
212
- after(:each) do
213
- stop_scheduler(@s)
214
- end
215
-
216
- it 'responds to #next_time' do
217
-
218
- t = Time.now + 3 * 3600
219
-
220
- job = @s.every '3h' do
221
- end
222
-
223
- job.next_time.to_i.should == t.to_i
224
- end
225
205
 
226
-
227
- it 'does not allow a job to overlap execution if set !allow_overlapping' do
206
+ it "doesn't allow overlapped execution if :allow_overlapping => false" do
228
207
 
229
208
  stack = []
230
209
 
@@ -238,7 +217,7 @@ describe Rufus::Scheduler::EveryJob do
238
217
  stack.size.should == 2
239
218
  end
240
219
 
241
- it 'allows a job to overlap execution (backward compatibility?)' do
220
+ it 'allows overlapped execution by default' do
242
221
 
243
222
  stack = []
244
223
 
@@ -251,5 +230,22 @@ describe Rufus::Scheduler::EveryJob do
251
230
 
252
231
  stack.size.should == 4
253
232
  end
233
+
234
+ it 'schedules anyway when exception and :allow_overlapping => false' do
235
+
236
+ $exceptions = []
237
+
238
+ def @s.handle_exception(job, exception)
239
+ $exceptions << exception
240
+ end
241
+
242
+ @s.every '1s', :allow_overlapping => false do
243
+ raise 'fail'
244
+ end
245
+
246
+ sleep 4
247
+
248
+ $exceptions.size.should be > 1
249
+ end
254
250
  end
255
251
 
data/spec/in_spec.rb CHANGED
@@ -140,35 +140,3 @@ describe "#{SCHEDULER_CLASS}#in" do
140
140
  end
141
141
  end
142
142
 
143
- describe Rufus::Scheduler::InJob do
144
-
145
- before(:each) do
146
- @s = start_scheduler
147
- end
148
- after(:each) do
149
- stop_scheduler(@s)
150
- end
151
-
152
- it 'unschedules itself' do
153
-
154
- job = @s.in '2d' do
155
- end
156
-
157
- wait_next_tick
158
-
159
- job.unschedule
160
-
161
- @s.jobs.size.should == 0
162
- end
163
-
164
- it 'responds to #next_time' do
165
-
166
- t = Time.now + 3 * 3600
167
-
168
- job = @s.in '3h' do
169
- end
170
-
171
- job.next_time.to_i.should == t.to_i
172
- end
173
- end
174
-
data/spec/job_spec.rb ADDED
@@ -0,0 +1,174 @@
1
+
2
+ #
3
+ # Specifying rufus-scheduler
4
+ #
5
+ # Wed Apr 27 00:51:07 JST 2011
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'spec_base')
9
+
10
+
11
+ describe 'job classes' do
12
+
13
+ before(:each) do
14
+ @s = start_scheduler
15
+ end
16
+ after(:each) do
17
+ stop_scheduler(@s)
18
+ end
19
+
20
+ describe Rufus::Scheduler::Job do
21
+
22
+ describe '#running' do
23
+
24
+ it 'returns false when the job is inactive' do
25
+
26
+ job = @s.in '2d' do
27
+ end
28
+
29
+ job.running.should == false
30
+ end
31
+
32
+ it 'returns true when the job is active' do
33
+
34
+ job = @s.in 0 do
35
+ sleep(100)
36
+ end
37
+
38
+ wait_next_tick
39
+
40
+ job.running.should == true
41
+ end
42
+
43
+ it 'returns false when the job hit some error' do
44
+
45
+ $exception = nil
46
+
47
+ def @s.handle_exception(j, e)
48
+ #p e
49
+ $exception = e
50
+ end
51
+
52
+ job = @s.in 0 do
53
+ raise "nada"
54
+ end
55
+
56
+ wait_next_tick
57
+
58
+ $exception.should_not == nil
59
+ job.running.should == false
60
+ end
61
+ end
62
+
63
+ describe '#running?' do
64
+
65
+ it 'is an alias for #running' do
66
+
67
+ job = @s.in 0 do
68
+ sleep(100)
69
+ end
70
+
71
+ wait_next_tick
72
+
73
+ job.running?.should == true
74
+ end
75
+ end
76
+ end
77
+
78
+ describe Rufus::Scheduler::AtJob do
79
+
80
+ describe '#unschedule' do
81
+
82
+ it 'removes the job from the scheduler' do
83
+
84
+ job = @s.at Time.now + 3 * 3600 do
85
+ end
86
+
87
+ wait_next_tick
88
+
89
+ job.unschedule
90
+
91
+ @s.jobs.size.should == 0
92
+ end
93
+ end
94
+
95
+ describe '#next_time' do
96
+
97
+ it 'returns the time when the job will trigger' do
98
+
99
+ t = Time.now + 3 * 3600
100
+
101
+ job = @s.at Time.now + 3 * 3600 do
102
+ end
103
+
104
+ job.next_time.class.should == Time
105
+ job.next_time.to_i.should == t.to_i
106
+ end
107
+ end
108
+ end
109
+
110
+ describe Rufus::Scheduler::InJob do
111
+
112
+ describe '#unschedule' do
113
+
114
+ it 'removes the job from the scheduler' do
115
+
116
+ job = @s.in '2d' do
117
+ end
118
+
119
+ wait_next_tick
120
+
121
+ job.unschedule
122
+
123
+ @s.jobs.size.should == 0
124
+ end
125
+ end
126
+
127
+ describe '#next_time' do
128
+
129
+ it 'returns the time when the job will trigger' do
130
+
131
+ t = Time.now + 3 * 3600
132
+
133
+ job = @s.in '3h' do
134
+ end
135
+
136
+ job.next_time.class.should == Time
137
+ job.next_time.to_i.should == t.to_i
138
+ end
139
+ end
140
+ end
141
+
142
+ describe Rufus::Scheduler::EveryJob do
143
+
144
+ describe '#next_time' do
145
+
146
+ it 'returns the time when the job will trigger' do
147
+
148
+ t = Time.now + 3 * 3600
149
+
150
+ job = @s.every '3h' do
151
+ end
152
+
153
+ job.next_time.class.should == Time
154
+ job.next_time.to_i.should == t.to_i
155
+ end
156
+ end
157
+ end
158
+
159
+ describe Rufus::Scheduler::CronJob do
160
+
161
+ describe '#next_time' do
162
+
163
+ it 'returns the time when the job will trigger' do
164
+
165
+ job = @s.cron '* * * * *' do
166
+ end
167
+
168
+ job.next_time.class.should == Time
169
+ (job.next_time.to_i - Time.now.to_i).should satisfy { |v| v < 60 }
170
+ end
171
+ end
172
+ end
173
+ end
174
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 9
10
- version: 2.0.9
9
+ - 10
10
+ version: 2.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Mettraux
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-22 00:00:00 +09:00
18
+ date: 2011-06-26 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -91,6 +91,7 @@ files:
91
91
  - spec/every_spec.rb
92
92
  - spec/exception_spec.rb
93
93
  - spec/in_spec.rb
94
+ - spec/job_spec.rb
94
95
  - spec/rtime_spec.rb
95
96
  - spec/schedulable_spec.rb
96
97
  - spec/scheduler_spec.rb