rufus-scheduler 3.1.9 → 3.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,158 +0,0 @@
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 '#at' do
21
-
22
- it 'raises if the block to schedule is missing' do
23
-
24
- expect {
25
- @scheduler.at(Time.now + 3600)
26
- }.to raise_error(ArgumentError)
27
- end
28
-
29
- it 'returns a job id' do
30
-
31
- job_id =
32
- @scheduler.at(Time.now + 3600) do
33
- end
34
-
35
- expect(job_id.class).to eq(String)
36
- expect(job_id).to match(/^at_/)
37
- end
38
-
39
- it 'returns a job if :job => true' do
40
-
41
- job =
42
- @scheduler.at(Time.now + 3600, :job => true) do
43
- end
44
-
45
- expect(job.class).to eq(Rufus::Scheduler::AtJob)
46
- end
47
-
48
- it 'adds a job' do
49
-
50
- t = Time.now + 3600
51
-
52
- @scheduler.at(t) do
53
- end
54
-
55
- expect(@scheduler.jobs.size).to eq(1)
56
- expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::AtJob)
57
- expect(@scheduler.jobs.first.time).to eq(t)
58
- end
59
-
60
- it 'triggers a job' do
61
-
62
- a = false
63
-
64
- @scheduler.at(Time.now + 0.100) do
65
- a = true
66
- end
67
-
68
- sleep 0.4
69
-
70
- expect(a).to eq(true)
71
- end
72
-
73
- it 'removes the job after execution' do
74
-
75
- @scheduler.at(Time.now + 0.100) do
76
- end
77
-
78
- sleep 0.4
79
-
80
- expect(@scheduler.jobs.size).to eq(0)
81
- end
82
-
83
- it 'accepts a Time instance' do
84
-
85
- t = Time.now + 3600
86
-
87
- job = @scheduler.at(t, :job => true) {}
88
-
89
- expect(job.time).to eq(t)
90
- end
91
-
92
- it 'accepts a time string' do
93
-
94
- job = @scheduler.at('2100-12-12 20:30', :job => true) {}
95
-
96
- expect(job.time).to eq(Time.parse('2100-12-12 20:30'))
97
- end
98
-
99
- it 'accepts a time string with a delta timezone' do
100
-
101
- job = @scheduler.at('2100-12-12 20:30 -0200', :job => true) {}
102
-
103
- expect(job.time).to eq(Time.parse('2100-12-12 20:30 -0200'))
104
- end
105
-
106
- it 'accepts a time string with a named timezone' do
107
-
108
- job = @scheduler.at('2050-12-12 20:30 Europe/Berlin', :job => true) {}
109
-
110
- expect(job.time.strftime('%c %z')).to eq('Mon Dec 12 20:30:00 2050 +0100')
111
- end
112
-
113
- it 'accepts a Chronic string (if Chronic is present)' do
114
-
115
- with_chronic do
116
-
117
- job = @scheduler.schedule_at('next tuesday at 12:00') {}
118
-
119
- expect(job.time.wday).to eq(2)
120
- expect(job.time.hour).to eq(12)
121
- expect(job.time.min).to eq(0)
122
- expect(job.time).to be > Time.now
123
- end
124
- end
125
-
126
- it 'accepts a Chronic string and Chronic options (if Chronic present)' do
127
-
128
- with_chronic do
129
-
130
- job =
131
- @scheduler.schedule_at(
132
- 'may 27th at 12:00', :now => Time.local(Time.now.year + 2, 1, 1)
133
- ) {}
134
-
135
- expect(job.time.year).to eq(Time.now.year + 2)
136
- expect(job.time.month).to eq(5)
137
- expect(job.time.day).to eq(27)
138
- expect(job.time.hour).to eq(12)
139
- expect(job.time.min).to eq(0)
140
- end
141
- end
142
-
143
- it 'accepts an ActiveSupport time thinggy'
144
- end
145
-
146
- describe '#schedule_at' do
147
-
148
- it 'returns a job' do
149
-
150
- job = @scheduler.schedule_at(Time.now + 3600) do
151
- end
152
-
153
- expect(job.class).to eq(Rufus::Scheduler::AtJob)
154
- expect(job.id).to match(/^at_/)
155
- end
156
- end
157
- end
158
-
@@ -1,66 +0,0 @@
1
-
2
- #
3
- # Specifying rufus-scheduler
4
- #
5
- # Sat Jul 13 04:52:08 JST 2013
6
- #
7
- # In the train between Bern and Fribourg, riding back
8
- # from the @ruvetia drinkup
9
- #
10
-
11
- require 'spec_helper'
12
-
13
-
14
- describe Rufus::Scheduler do
15
-
16
- before :each do
17
- @scheduler = Rufus::Scheduler.new
18
- end
19
- after :each do
20
- @scheduler.shutdown
21
- end
22
-
23
- describe '#cron' do
24
-
25
- it 'schedules' do
26
-
27
- counter = 0
28
-
29
- sleep_until_next_second
30
- sleep 0.3 # make sure to schedule right after a scheduler 'tick'
31
-
32
- job =
33
- @scheduler.cron '* * * * * *', :job => true do
34
- counter = counter + 1
35
- end
36
-
37
- sleep_until_next_second
38
- sleep_until_next_second
39
- sleep 0.3 # be sure to be well into the second
40
-
41
- expect(counter).to eq(2)
42
- end
43
-
44
- it 'raises if the job frequency is higher than the scheduler frequency' do
45
-
46
- @scheduler.frequency = 10
47
-
48
- expect {
49
- @scheduler.cron '* * * * * *' do; end
50
- }.to raise_error(ArgumentError)
51
- end
52
- end
53
-
54
- describe '#schedule_cron' do
55
-
56
- it 'returns a CronJob instance' do
57
-
58
- job = @scheduler.schedule_cron '* * * * *' do; end
59
-
60
- expect(job.class).to eq(Rufus::Scheduler::CronJob)
61
- expect(job.original).to eq('* * * * *')
62
- expect(job.job_id).to match(/^cron_/)
63
- end
64
- end
65
- end
66
-
@@ -1,109 +0,0 @@
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
-
@@ -1,80 +0,0 @@
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
-
@@ -1,128 +0,0 @@
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
-