rufus-scheduler 2.0.24 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/CHANGELOG.txt +76 -0
  2. data/CREDITS.txt +23 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1439 -0
  5. data/Rakefile +1 -5
  6. data/TODO.txt +149 -55
  7. data/lib/rufus/{sc → scheduler}/cronline.rb +167 -53
  8. data/lib/rufus/scheduler/job_array.rb +92 -0
  9. data/lib/rufus/scheduler/jobs.rb +633 -0
  10. data/lib/rufus/scheduler/locks.rb +95 -0
  11. data/lib/rufus/scheduler/util.rb +306 -0
  12. data/lib/rufus/scheduler/zones.rb +174 -0
  13. data/lib/rufus/scheduler/zotime.rb +154 -0
  14. data/lib/rufus/scheduler.rb +608 -27
  15. data/rufus-scheduler.gemspec +6 -4
  16. data/spec/basics_spec.rb +54 -0
  17. data/spec/cronline_spec.rb +479 -152
  18. data/spec/error_spec.rb +139 -0
  19. data/spec/job_array_spec.rb +39 -0
  20. data/spec/job_at_spec.rb +58 -0
  21. data/spec/job_cron_spec.rb +128 -0
  22. data/spec/job_every_spec.rb +104 -0
  23. data/spec/job_in_spec.rb +20 -0
  24. data/spec/job_interval_spec.rb +68 -0
  25. data/spec/job_repeat_spec.rb +357 -0
  26. data/spec/job_spec.rb +498 -109
  27. data/spec/lock_custom_spec.rb +47 -0
  28. data/spec/lock_flock_spec.rb +47 -0
  29. data/spec/lock_lockfile_spec.rb +61 -0
  30. data/spec/lock_spec.rb +59 -0
  31. data/spec/parse_spec.rb +263 -0
  32. data/spec/schedule_at_spec.rb +158 -0
  33. data/spec/schedule_cron_spec.rb +66 -0
  34. data/spec/schedule_every_spec.rb +109 -0
  35. data/spec/schedule_in_spec.rb +80 -0
  36. data/spec/schedule_interval_spec.rb +128 -0
  37. data/spec/scheduler_spec.rb +928 -124
  38. data/spec/spec_helper.rb +126 -0
  39. data/spec/threads_spec.rb +96 -0
  40. data/spec/zotime_spec.rb +396 -0
  41. metadata +56 -33
  42. data/README.rdoc +0 -661
  43. data/lib/rufus/otime.rb +0 -3
  44. data/lib/rufus/sc/jobqueues.rb +0 -160
  45. data/lib/rufus/sc/jobs.rb +0 -471
  46. data/lib/rufus/sc/rtime.rb +0 -363
  47. data/lib/rufus/sc/scheduler.rb +0 -636
  48. data/lib/rufus/sc/version.rb +0 -32
  49. data/spec/at_in_spec.rb +0 -47
  50. data/spec/at_spec.rb +0 -125
  51. data/spec/blocking_spec.rb +0 -64
  52. data/spec/cron_spec.rb +0 -134
  53. data/spec/every_spec.rb +0 -304
  54. data/spec/exception_spec.rb +0 -113
  55. data/spec/in_spec.rb +0 -150
  56. data/spec/mutex_spec.rb +0 -159
  57. data/spec/rtime_spec.rb +0 -137
  58. data/spec/schedulable_spec.rb +0 -97
  59. data/spec/spec_base.rb +0 -87
  60. data/spec/stress_schedule_unschedule_spec.rb +0 -159
  61. data/spec/timeout_spec.rb +0 -148
  62. data/test/kjw.rb +0 -113
  63. data/test/t.rb +0 -20
@@ -0,0 +1,109 @@
1
+
2
+ #
3
+ # Specifying rufus-scheduler
4
+ #
5
+ # Wed Apr 17 06:00:59 JST 2013
6
+ #
7
+
8
+ require 'spec_helper'
9
+
10
+
11
+ describe Rufus::Scheduler do
12
+
13
+ before :each do
14
+ @scheduler = Rufus::Scheduler.new
15
+ end
16
+ after :each do
17
+ @scheduler.shutdown
18
+ end
19
+
20
+ describe '#every' do
21
+
22
+ it 'adds a job' do
23
+
24
+ @scheduler.every(10) do
25
+ end
26
+
27
+ expect(@scheduler.jobs.size).to eq(1)
28
+ expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::EveryJob)
29
+ end
30
+
31
+ it 'triggers a job (2 times)' do
32
+
33
+ counter = 0
34
+
35
+ @scheduler.every(0.4) do
36
+ counter += 1
37
+ end
38
+
39
+ sleep 2.0
40
+
41
+ expect(counter).to be > 2
42
+ end
43
+
44
+ it 'does not remove the job after execution' do
45
+
46
+ @scheduler.every(0.4) do
47
+ end
48
+
49
+ sleep 0.9
50
+
51
+ expect(@scheduler.jobs.size).to eq(1)
52
+ end
53
+
54
+ it 'raises on negative frequencies' do
55
+
56
+ expect {
57
+ @scheduler.every(-1) do
58
+ end
59
+ }.to raise_error(ArgumentError)
60
+ end
61
+
62
+ it 'raises on zero frequencies' do
63
+
64
+ expect {
65
+ @scheduler.every(0) do
66
+ end
67
+ }.to raise_error(ArgumentError)
68
+ end
69
+
70
+ it 'does not reschedule if the job was unscheduled' do
71
+
72
+ counter = 0
73
+
74
+ job =
75
+ @scheduler.schedule_every '0.5s' do
76
+ counter = counter + 1
77
+ end
78
+
79
+ sleep 1.6
80
+
81
+ job.unschedule
82
+ c = counter
83
+
84
+ sleep 1.6
85
+
86
+ expect(counter).to eq(c)
87
+ end
88
+
89
+ it 'raises if the job frequency is higher than the scheduler frequency' do
90
+
91
+ @scheduler.frequency = 10
92
+
93
+ expect {
94
+ @scheduler.every '1s' do; end
95
+ }.to raise_error(ArgumentError)
96
+ end
97
+ end
98
+
99
+ describe '#schedule_every' do
100
+
101
+ it 'accepts a duration string' do
102
+
103
+ job = @scheduler.schedule_every('1h') do; end
104
+
105
+ expect(job.frequency).to eq(3600.0)
106
+ end
107
+ end
108
+ end
109
+
@@ -0,0 +1,80 @@
1
+
2
+ #
3
+ # Specifying rufus-scheduler
4
+ #
5
+ # Wed Apr 17 06:00:59 JST 2013
6
+ #
7
+
8
+ require 'spec_helper'
9
+
10
+
11
+ describe Rufus::Scheduler do
12
+
13
+ before :each do
14
+ @scheduler = Rufus::Scheduler.new
15
+ end
16
+ after :each do
17
+ @scheduler.shutdown
18
+ end
19
+
20
+ describe '#in' do
21
+
22
+ it 'adds a job' do
23
+
24
+ @scheduler.in(3600) do
25
+ end
26
+
27
+ expect(@scheduler.jobs.size).to eq(1)
28
+ expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::InJob)
29
+ end
30
+
31
+ it 'triggers a job' do
32
+
33
+ a = false
34
+
35
+ @scheduler.in(0.4) do
36
+ a = true
37
+ end
38
+
39
+ sleep 0.9
40
+
41
+ expect(a).to eq(true)
42
+ end
43
+
44
+ it 'removes the job after execution' do
45
+
46
+ @scheduler.in(0.4) do
47
+ end
48
+
49
+ sleep 0.700
50
+
51
+ expect(@scheduler.jobs.size).to eq(0)
52
+ end
53
+ end
54
+
55
+ describe '#schedule_in' do
56
+
57
+ it 'accepts a number' do
58
+
59
+ job = @scheduler.schedule_in(3600) {}
60
+
61
+ expect(job.original).to eq(3600)
62
+ end
63
+
64
+ it 'accepts a duration string' do
65
+
66
+ job = @scheduler.schedule_in('1h') {}
67
+
68
+ expect(job.original).to eq('1h')
69
+ expect(job.time).to be >= job.scheduled_at + 3509
70
+ expect(job.time).to be <= job.scheduled_at + 3601
71
+ end
72
+
73
+ it 'accepts an ActiveSupport .from_now thinggy'
74
+ #
75
+ # schedule_in(2.days.from_now)
76
+ #
77
+ # that'd simply require "in" to be a bit like "at"...
78
+ end
79
+ end
80
+
@@ -0,0 +1,128 @@
1
+
2
+ #
3
+ # Specifying rufus-scheduler
4
+ #
5
+ # Wed Aug 7 06:20:55 JST 2013
6
+ #
7
+
8
+ require 'spec_helper'
9
+
10
+
11
+ describe Rufus::Scheduler do
12
+
13
+ before :each do
14
+ @scheduler = Rufus::Scheduler.new
15
+ end
16
+ after :each do
17
+ @scheduler.shutdown
18
+ end
19
+
20
+ describe '#interval' do
21
+
22
+ it 'adds a job' do
23
+
24
+ @scheduler.interval(10) do
25
+ end
26
+
27
+ expect(@scheduler.jobs.size).to eq(1)
28
+ expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::IntervalJob)
29
+ end
30
+
31
+ it 'triggers a job (2 times)' do
32
+
33
+ counter = 0
34
+
35
+ @scheduler.interval(0.4) do
36
+ counter += 1
37
+ end
38
+
39
+ sleep 2.0
40
+
41
+ expect(counter).to be > 2
42
+ end
43
+
44
+ it 'triggers, but reschedules after the trigger execution' do
45
+
46
+ chronos = []
47
+
48
+ @scheduler.interval(0.4) do
49
+ now = Time.now
50
+ last, delta = chronos.last
51
+ chronos << [ now, last ? now - last : nil ]
52
+ sleep 0.5
53
+ end
54
+
55
+ t = Time.now
56
+ sleep 0.1 while chronos.size < 4 && Time.now < t + 5
57
+
58
+ expect(chronos.size).to eq(4)
59
+
60
+ deltas = chronos.collect(&:last).compact
61
+
62
+ #pp chronos
63
+ #pp deltas
64
+
65
+ deltas.each do |d|
66
+ expect(d).to be >= 0.9
67
+ end
68
+ end
69
+
70
+ it 'does not reschedule if the job was unscheduled' do
71
+
72
+ counter = 0
73
+
74
+ job =
75
+ @scheduler.schedule_interval '0.5s' do
76
+ counter = counter + 1
77
+ end
78
+
79
+ sleep 1.6
80
+
81
+ expect(@scheduler.jobs(:all).size).to eq(1)
82
+
83
+ job.unschedule
84
+ c = counter
85
+
86
+ sleep 1.6
87
+
88
+ expect(counter).to eq(c)
89
+ expect(@scheduler.jobs(:all).size).to eq(0)
90
+ end
91
+
92
+ it 'raises on negative intervals' do
93
+
94
+ expect {
95
+ @scheduler.interval(-1) do
96
+ end
97
+ }.to raise_error(ArgumentError)
98
+ end
99
+
100
+ it 'raises on zero intervals' do
101
+
102
+ expect {
103
+ @scheduler.interval(0) do
104
+ end
105
+ }.to raise_error(ArgumentError)
106
+ end
107
+
108
+ #it 'raises if the job frequency is higher than the scheduler frequency' do
109
+ #
110
+ # @scheduler.frequency = 10
111
+ #
112
+ # lambda {
113
+ # @scheduler.interval '1s' do; end
114
+ # }.should raise_error(ArgumentError)
115
+ #end
116
+ end
117
+
118
+ describe '#schedule_interval' do
119
+
120
+ it 'accepts a duration string' do
121
+
122
+ job = @scheduler.schedule_interval('1h') do; end
123
+
124
+ expect(job.interval).to eq(3600)
125
+ end
126
+ end
127
+ end
128
+