rufus-scheduler 3.0.1 → 3.0.2

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.
@@ -2,7 +2,14 @@
2
2
  = rufus-scheduler CHANGELOG.txt
3
3
 
4
4
 
5
- == rufus-scheduler - 3.0.1 not yet released
5
+ == rufus-scheduler - 3.0.2 released 2013/10/22
6
+
7
+ - default :max_work_threads to 28
8
+ - fix "rufus rushes to create work threads" issue, thanks Gatis Tomsons
9
+ - introduce Rufus::Scheduler::NotRunningError, thanks Gatis Tomsons
10
+
11
+
12
+ == rufus-scheduler - 3.0.1 released 2013/10/19
6
13
 
7
14
  - fix post_install_message, thanks Ted Pennings
8
15
  - bring back .parse_time_string and .parse_duration_string
@@ -154,5 +161,9 @@
154
161
  == rufus-scheduler - 2.0.1 released 2009/05/07
155
162
  == rufus-scheduler - 2.0.0 released 2009/05/07
156
163
 
164
+ ...
165
+
157
166
  - initial release
158
167
 
168
+ (was openwferu-scheduler before that)
169
+
@@ -28,7 +28,7 @@
28
28
 
29
29
  == Feedback
30
30
 
31
- - Gatis Tomsons - https://github.io/gacha - heavy duty work threads
31
+ - Gatis Tomsons - https://github.io/gacha - heavy work threads and lock errors
32
32
  - https://github.com/joast - missing .to_time_string alias (code and doc)
33
33
  - Tamir Duberstein - https://github.com/tamird - rdoc inaccuracies
34
34
  - Kevin Bouwkamp - https://github.com/bmxpert1 - first_at issues
data/README.md CHANGED
@@ -966,7 +966,7 @@ This is useful in environments where the Ruby process holding the scheduler gets
966
966
 
967
967
  ### :max_work_threads
968
968
 
969
- In rufus-scheduler 2.x, by default, each job triggering received its own, new, hthread of execution. In rufus-scheduler 3.x, execution happens in a work thread and the max work thread count defaults to 35.
969
+ In rufus-scheduler 2.x, by default, each job triggering received its own, new, hthread of execution. In rufus-scheduler 3.x, execution happens in a work thread and the max work thread count defaults to 28.
970
970
 
971
971
  One can set this maximum value when starting the scheduler.
972
972
 
@@ -38,15 +38,26 @@ module Rufus
38
38
  require 'rufus/scheduler/cronline'
39
39
  require 'rufus/scheduler/job_array'
40
40
 
41
- VERSION = '3.0.1'
41
+ VERSION = '3.0.2'
42
+
43
+ #
44
+ # A common error class for rufus-scheduler
45
+ #
46
+ class Error < StandardError; end
42
47
 
43
48
  #
44
49
  # This error is thrown when the :timeout attribute triggers
45
50
  #
46
- class TimeoutError < StandardError; end
51
+ class TimeoutError < Error; end
47
52
 
48
- #MIN_WORK_THREADS = 7
49
- MAX_WORK_THREADS = 35
53
+ #
54
+ # For when the scheduler is not running
55
+ # (it got shut down or didn't start because of a lock)
56
+ #
57
+ class NotRunningError < Error; end
58
+
59
+ #MIN_WORK_THREADS = 3
60
+ MAX_WORK_THREADS = 28
50
61
 
51
62
  attr_accessor :frequency
52
63
  attr_reader :started_at
@@ -140,6 +151,10 @@ module Rufus
140
151
 
141
152
  def join
142
153
 
154
+ fail NotRunningError.new(
155
+ 'cannot join scheduler that is not running'
156
+ ) unless @thread
157
+
143
158
  @thread.join
144
159
  end
145
160
 
@@ -502,7 +517,7 @@ module Rufus
502
517
 
503
518
  def do_schedule(job_type, t, callable, opts, return_job_instance, block)
504
519
 
505
- raise RuntimeError.new(
520
+ fail NotRunningError.new(
506
521
  'cannot schedule, scheduler is down or shutting down'
507
522
  ) if @started_at == nil
508
523
 
@@ -82,8 +82,6 @@ module Rufus
82
82
  @scheduled_at = Time.now
83
83
  @unscheduled_at = nil
84
84
  @last_time = nil
85
- #@mutexes = {}
86
- #@pool_mutex = Mutex.new
87
85
 
88
86
  @locals = {}
89
87
  @local_mutex = Mutex.new
@@ -290,15 +288,15 @@ module Rufus
290
288
 
291
289
  def do_trigger_in_thread(time)
292
290
 
293
- #@pool_mutex.synchronize do
291
+ threads = @scheduler.work_threads
294
292
 
295
- count = @scheduler.work_threads.size
296
- #vacant = threads.select { |t| t[:rufus_scheduler_job] == nil }.size
293
+ cur = threads.size
294
+ vac = threads.select { |t| t[:rufus_scheduler_job] == nil }.size
297
295
  #min = @scheduler.min_work_threads
298
296
  max = @scheduler.max_work_threads
297
+ que = @scheduler.work_queue.size
299
298
 
300
- start_work_thread if count < max
301
- #end
299
+ start_work_thread if vac - que < 1 && cur < max
302
300
 
303
301
  @scheduler.work_queue << [ self, time ]
304
302
  end
@@ -231,16 +231,21 @@ describe Rufus::Scheduler::RepeatJob do
231
231
  it 'unschedules the job after the last_at time' do
232
232
 
233
233
  t = Time.now + 2
234
+
234
235
  counter = 0
236
+ tt = nil
235
237
 
236
238
  job =
237
239
  @scheduler.schedule_every '0.5s', :last => t do
238
240
  counter = counter + 1
241
+ tt = Time.now
239
242
  end
240
243
 
241
244
  sleep 3
242
245
 
243
- counter.should == 3
246
+ #counter.should == 3
247
+ [ 3, 4 ].should include(counter)
248
+ tt.should < t
244
249
  @scheduler.jobs.should_not include(job)
245
250
  end
246
251
 
@@ -154,7 +154,7 @@ describe Rufus::Scheduler do
154
154
 
155
155
  lambda {
156
156
  @scheduler.in('0s') { puts 'hhhhhhhhhhhello!!' }
157
- }.should raise_error(RuntimeError)
157
+ }.should raise_error(Rufus::Scheduler::NotRunningError)
158
158
  end
159
159
  end
160
160
 
@@ -373,15 +373,16 @@ describe Rufus::Scheduler do
373
373
  it 'lists all the work threads in the pool' do
374
374
 
375
375
  @scheduler.in '0s' do
376
- # nada
376
+ sleep(0.2)
377
377
  end
378
378
  @scheduler.in '0s' do
379
- sleep(2)
379
+ sleep(2.0)
380
380
  end
381
381
 
382
382
  sleep 0.6
383
383
 
384
384
  @scheduler.work_threads.size.should == 2
385
+ @scheduler.work_threads(:all).size.should == 2
385
386
  end
386
387
  end
387
388
 
@@ -392,17 +393,18 @@ describe Rufus::Scheduler do
392
393
  @scheduler.work_threads(:vacant).should == []
393
394
  end
394
395
 
395
- it 'lists all the work threads in the pool' do
396
+ it 'lists all the vacant work threads in the pool' do
396
397
 
397
398
  @scheduler.in '0s' do
398
- # nada
399
+ sleep(0.2)
399
400
  end
400
401
  @scheduler.in '0s' do
401
- sleep(2)
402
+ sleep(2.0)
402
403
  end
403
404
 
404
- sleep 0.4
405
+ sleep 0.6
405
406
 
407
+ @scheduler.work_threads(:all).size.should == 2
406
408
  @scheduler.work_threads(:vacant).size.should == 1
407
409
  end
408
410
  end
@@ -452,7 +454,7 @@ describe Rufus::Scheduler do
452
454
 
453
455
  #describe '#min_work_threads' do
454
456
  # it 'returns the min job thread count' do
455
- # @scheduler.min_work_threads.should == 7
457
+ # @scheduler.min_work_threads.should == 3
456
458
  # end
457
459
  #end
458
460
  #describe '#min_work_threads=' do
@@ -466,7 +468,7 @@ describe Rufus::Scheduler do
466
468
 
467
469
  it 'returns the max job thread count' do
468
470
 
469
- @scheduler.max_work_threads.should == 35
471
+ @scheduler.max_work_threads.should == 28
470
472
  end
471
473
  end
472
474
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-18 00:00:00.000000000 Z
12
+ date: 2013-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tzinfo
@@ -102,7 +102,7 @@ files:
102
102
  homepage: http://github.com/jmettraux/rufus-scheduler
103
103
  licenses:
104
104
  - MIT
105
- post_install_message: ! "\n***\n\nThanks for installing rufus-scheduler 3.0.1\n\nIt
105
+ post_install_message: ! "\n***\n\nThanks for installing rufus-scheduler 3.0.2\n\nIt
106
106
  might not be 100% compatible with rufus-scheduler 2.x.\n\nIf you encounter issues
107
107
  with this new rufus-scheduler, especially\nif your app worked fine with previous
108
108
  versions of it, you can\n\nA) Forget it and peg your Gemfile to rufus-scheduler