say_when 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/lib/say_when/storage/active_record_strategy.rb +5 -3
- data/lib/say_when/version.rb +1 -1
- data/say_when.gemspec +2 -1
- data/test/active_record_helper.rb +0 -3
- data/test/say_when/configuration_test.rb +5 -5
- data/test/say_when/cron_expression_test.rb +29 -29
- data/test/say_when/poller/base_poller_test.rb +1 -1
- data/test/say_when/poller/celluloid_poller_test.rb +1 -1
- data/test/say_when/poller/concurrent_poller_test.rb +1 -1
- data/test/say_when/poller/simple_poller_test.rb +5 -5
- data/test/say_when/processor/active_job_strategy_test.rb +2 -2
- data/test/say_when/processor/simple_strategy_test.rb +1 -1
- data/test/say_when/scheduler_test.rb +16 -16
- data/test/say_when/storage/active_record_strategy_test.rb +22 -22
- data/test/say_when/storage/memory_strategy_test.rb +15 -15
- data/test/say_when/triggers/cron_strategy_test.rb +1 -1
- data/test/say_when/triggers/instance_strategy_test.rb +1 -1
- data/test/say_when/triggers/once_strategy_test.rb +6 -6
- data/test/say_when_test.rb +3 -3
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4684a6afb159599fe11378e88e25603cfd413755d394f3ee42e026cb4aa33f4
|
4
|
+
data.tar.gz: 3f75b45a4c7ccb1fd73ccadad6130d6ab76abcc304d18215024cef43cefe9f7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20be0b65e7e8536266c9ce8db6fd5b0795c2b38f2bd34802026d446e1d7ea0c0943b936c46b3214af72b0f3afeb3e2580b84773bfaccf5e0678a0c45f746de52
|
7
|
+
data.tar.gz: d93ce5845a287e45f97edb54ef4ec8723495710b009567c340eec8ebeb9fe3ee047f163c341661641e8ae5f6f0c389e1ca5f842f0d2c4510f7b21b098e2349bb
|
data/.gitignore
CHANGED
@@ -44,8 +44,8 @@ module SayWhen
|
|
44
44
|
|
45
45
|
self.table_name = "#{SayWhen.options[:table_prefix]}say_when_jobs"
|
46
46
|
|
47
|
-
serialize :trigger_options
|
48
|
-
serialize :data
|
47
|
+
serialize :trigger_options, coder: YAML
|
48
|
+
serialize :data, coder: YAML
|
49
49
|
|
50
50
|
belongs_to :scheduled, polymorphic: true, optional: true
|
51
51
|
has_many :job_executions, class_name: 'SayWhen::Storage::ActiveRecordStrategy::JobExecution'
|
@@ -93,7 +93,9 @@ module SayWhen
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def self.check_connection
|
96
|
-
if ActiveRecord::Base.respond_to?(:
|
96
|
+
if ActiveRecord::Base.respond_to?(:connection_handler) && ActiveRecord::Base.connection_handler
|
97
|
+
ActiveRecord::Base.connection_handler.clear_active_connections!
|
98
|
+
elsif ActiveRecord::Base.respond_to?(:clear_active_connections!)
|
97
99
|
ActiveRecord::Base.clear_active_connections!
|
98
100
|
elsif ActiveRecord::Base.respond_to?(:verify_active_connections!)
|
99
101
|
ActiveRecord::Base.verify_active_connections!
|
data/lib/say_when/version.rb
CHANGED
data/say_when.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_runtime_dependency('activesupport')
|
22
|
+
spec.add_runtime_dependency('sorted_set')
|
22
23
|
|
23
24
|
spec.add_development_dependency('bundler')
|
24
25
|
spec.add_development_dependency('rake')
|
@@ -28,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
28
29
|
spec.add_development_dependency('simplecov')
|
29
30
|
spec.add_development_dependency('coveralls')
|
30
31
|
|
31
|
-
spec.add_development_dependency('sqlite3')
|
32
|
+
spec.add_development_dependency('sqlite3', '~> 1.4')
|
32
33
|
spec.add_development_dependency('activerecord')
|
33
34
|
spec.add_development_dependency('celluloid')
|
34
35
|
spec.add_development_dependency('concurrent-ruby')
|
@@ -5,10 +5,10 @@ require 'minitest_helper'
|
|
5
5
|
describe SayWhen::Configuration do
|
6
6
|
it 'has default values' do
|
7
7
|
dos = SayWhen::Configuration.default_options
|
8
|
-
dos.wont_be_nil
|
9
|
-
dos[:processor_strategy].must_equal :simple
|
10
|
-
dos[:storage_strategy].must_equal :memory
|
11
|
-
dos[:tick_length].must_equal 5
|
12
|
-
dos[:queue].must_equal "default"
|
8
|
+
expect(dos).wont_be_nil
|
9
|
+
expect(dos[:processor_strategy]).must_equal :simple
|
10
|
+
expect(dos[:storage_strategy]).must_equal :memory
|
11
|
+
expect(dos[:tick_length]).must_equal 5
|
12
|
+
expect(dos[:queue]).must_equal "default"
|
13
13
|
end
|
14
14
|
end
|
@@ -8,71 +8,71 @@ describe SayWhen::CronExpression do
|
|
8
8
|
|
9
9
|
it 'should create with defaults' do
|
10
10
|
ce = SayWhen::CronExpression.new
|
11
|
-
ce.expression.must_equal "* * * ? * ? *"
|
12
|
-
ce.time_zone.must_equal Time.zone.try(:name) || "UTC"
|
11
|
+
expect(ce.expression).must_equal "* * * ? * ? *"
|
12
|
+
expect(ce.time_zone).must_equal Time.zone.try(:name) || "UTC"
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should set the time_zone' do
|
16
16
|
ce = SayWhen::CronExpression.new("0 0 12 ? * 1#1 *", 'Pacific Time (US & Canada)')
|
17
|
-
ce.time_zone.must_equal 'Pacific Time (US & Canada)'
|
17
|
+
expect(ce.time_zone).must_equal 'Pacific Time (US & Canada)'
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'has a pretty to_s' do
|
21
21
|
ce = SayWhen::CronExpression.new("1 1 1 1 1 ? 2000")
|
22
|
-
ce.to_s.must_match(/s:.*/)
|
22
|
+
expect(ce.to_s).must_match(/s:.*/)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'handles #/# numbers' do
|
26
26
|
ce = SayWhen::CronExpression.new("*/10 1 1 1 1 ? 2000")
|
27
|
-
ce.seconds.values.must_equal([0, 10, 20, 30, 40, 50])
|
27
|
+
expect(ce.seconds.values).must_equal([0, 10, 20, 30, 40, 50])
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'handles #,# numbers' do
|
31
31
|
ce = SayWhen::CronExpression.new("1,2 1 1 1 1 ? 2000")
|
32
|
-
ce.seconds.values.must_equal([1, 2])
|
32
|
+
expect(ce.seconds.values).must_equal([1, 2])
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'handles #-# numbers' do
|
36
36
|
ce = SayWhen::CronExpression.new("1-3 1 1 1 1 ? 2000")
|
37
|
-
ce.seconds.values.must_equal([1, 2, 3])
|
37
|
+
expect(ce.seconds.values).must_equal([1, 2, 3])
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'no values when no match' do
|
41
41
|
ce = SayWhen::CronExpression.new("na 1 1 1 1 ? 2000")
|
42
|
-
ce.seconds.values.must_equal([])
|
42
|
+
expect(ce.seconds.values).must_equal([])
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'handles changes in seconds' do
|
46
46
|
ce = SayWhen::CronExpression.new("1-3 1 1 1 1 ? 2000", "UTC")
|
47
47
|
n = ce.next_fire_at(Time.utc(1999,1,1))
|
48
|
-
n.must_equal Time.parse("Sat, 01 Jan 2000 01:01:01 UTC")
|
48
|
+
expect(n).must_equal Time.parse("Sat, 01 Jan 2000 01:01:01 UTC")
|
49
49
|
|
50
50
|
n = ce.next_fire_at(Time.parse("Sat, 01 Jan 2000 01:00:59 UTC"))
|
51
|
-
n.must_equal(Time.parse("Sat, 01 Jan 2000 01:01:01 UTC"))
|
51
|
+
expect(n).must_equal(Time.parse("Sat, 01 Jan 2000 01:01:01 UTC"))
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "Day of the month" do
|
55
55
|
it "gets the last day of the month" do
|
56
56
|
ce = SayWhen::CronExpression.new("0 0 0 L 1 ? 2004", 'UTC')
|
57
|
-
ce.next_fire_at(Time.utc(1999,1,1)).must_equal(Time.parse('Sat, 31 Jan 2004 00:00:00 UTC +00:00'))
|
57
|
+
expect(ce.next_fire_at(Time.utc(1999,1,1))).must_equal(Time.parse('Sat, 31 Jan 2004 00:00:00 UTC +00:00'))
|
58
58
|
end
|
59
59
|
|
60
60
|
it "gets the last weekday of the month" do
|
61
61
|
ce = SayWhen::CronExpression.new("0 0 0 LW 1 ? 2004", 'UTC')
|
62
|
-
ce.next_fire_at(Time.utc(1999,1,1)).must_equal(Time.parse('Fri, 30 Jan 2004 00:00:00 UTC +00:00'))
|
62
|
+
expect(ce.next_fire_at(Time.utc(1999,1,1))).must_equal(Time.parse('Fri, 30 Jan 2004 00:00:00 UTC +00:00'))
|
63
63
|
end
|
64
64
|
|
65
65
|
it "gets a weekday in the month" do
|
66
66
|
ce = SayWhen::CronExpression.new("0 0 0 W 1 ? 2000", 'UTC')
|
67
|
-
ce.next_fire_at(Time.utc(1999,1,1)).must_equal(Time.parse('Mon, 03 Jan 2000 00:00:00 UTC +00:00'))
|
67
|
+
expect(ce.next_fire_at(Time.utc(1999,1,1))).must_equal(Time.parse('Mon, 03 Jan 2000 00:00:00 UTC +00:00'))
|
68
68
|
end
|
69
69
|
|
70
70
|
it "gets the closest weekday in the month" do
|
71
71
|
ce = SayWhen::CronExpression.new("0 0 0 1W 1 ? 2000", 'UTC')
|
72
|
-
ce.next_fire_at(Time.utc(1999,1,1)).must_equal(Time.parse('Tue, 03 Jan 2000 00:00:00 UTC +00:00'))
|
72
|
+
expect(ce.next_fire_at(Time.utc(1999,1,1))).must_equal(Time.parse('Tue, 03 Jan 2000 00:00:00 UTC +00:00'))
|
73
73
|
|
74
74
|
ce = SayWhen::CronExpression.new("0 0 0 10W 1 ? 2000", 'UTC')
|
75
|
-
ce.next_fire_at(Time.utc(1999,1,1)).must_equal(Time.parse('Mon, 10 Jan 2000 00:00:00 UTC +00:00'))
|
75
|
+
expect(ce.next_fire_at(Time.utc(1999,1,1))).must_equal(Time.parse('Mon, 10 Jan 2000 00:00:00 UTC +00:00'))
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -83,23 +83,23 @@ describe SayWhen::CronExpression do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'finds first sunday in the same month' do
|
86
|
-
@ce.next_fire_at(Time.utc(2008,1,1)).must_equal(Time.parse('2008-01-06 12:00:00 -0800'))
|
86
|
+
expect(@ce.next_fire_at(Time.utc(2008,1,1))).must_equal(Time.parse('2008-01-06 12:00:00 -0800'))
|
87
87
|
end
|
88
88
|
|
89
89
|
|
90
90
|
it 'finds first sunday in the next month' do
|
91
|
-
@ce.next_fire_at(Time.utc(2008,1,7)).must_equal(Time.parse('2008-02-03 12:00:00 -0800'))
|
91
|
+
expect(@ce.next_fire_at(Time.utc(2008,1,7))).must_equal(Time.parse('2008-02-03 12:00:00 -0800'))
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'finds last sunday in the same month' do
|
95
|
-
@ce.last_fire_at(Time.utc(2008,1,10)).must_equal(Time.parse('2008-01-06 12:00:00 -0800'))
|
95
|
+
expect(@ce.last_fire_at(Time.utc(2008,1,10))).must_equal(Time.parse('2008-01-06 12:00:00 -0800'))
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'finds sundays in the prior months and years' do
|
99
|
-
@ce.last_fire_at(Time.utc(2008,1,5)).must_equal Time.parse('2007-12-02 12:00:00 -0800')
|
100
|
-
@ce.last_fire_at(Time.parse('2007-12-02 12:00:00 -0800') - 1.second).must_equal(Time.parse('2007-11-04 12:00:00 -0800'))
|
101
|
-
@ce.last_fire_at(Time.parse('2007-11-04 12:00:00 -0800') - 1.second).must_equal(Time.parse('2007-10-07 12:00:00 -0700'))
|
102
|
-
@ce.next_fire_at(Time.parse('2007-10-07 12:00:00 -0700') + 1.second).must_equal(Time.parse('2007-11-04 12:00:00 -0800'))
|
99
|
+
expect(@ce.last_fire_at(Time.utc(2008,1,5))).must_equal Time.parse('2007-12-02 12:00:00 -0800')
|
100
|
+
expect(@ce.last_fire_at(Time.parse('2007-12-02 12:00:00 -0800') - 1.second)).must_equal(Time.parse('2007-11-04 12:00:00 -0800'))
|
101
|
+
expect(@ce.last_fire_at(Time.parse('2007-11-04 12:00:00 -0800') - 1.second)).must_equal(Time.parse('2007-10-07 12:00:00 -0700'))
|
102
|
+
expect(@ce.next_fire_at(Time.parse('2007-10-07 12:00:00 -0700') + 1.second)).must_equal(Time.parse('2007-11-04 12:00:00 -0800'))
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -109,32 +109,32 @@ describe SayWhen::CronExpression do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'gets next final sunday for same month' do
|
112
|
-
@ce.next_fire_at(Time.utc(2008,1,1)).must_equal(Time.parse('2008-01-27 12:00:00 -0800'))
|
112
|
+
expect(@ce.next_fire_at(Time.utc(2008,1,1))).must_equal(Time.parse('2008-01-27 12:00:00 -0800'))
|
113
113
|
end
|
114
114
|
|
115
115
|
|
116
116
|
it 'gets next final sunday for next month' do
|
117
|
-
@ce.next_fire_at(Time.utc(2008,1,28)).must_equal(Time.parse('2008-02-24 12:00:00 -0800'))
|
117
|
+
expect(@ce.next_fire_at(Time.utc(2008,1,28))).must_equal(Time.parse('2008-02-24 12:00:00 -0800'))
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'gets last final sunday for same month' do
|
121
|
-
@ce.last_fire_at(Time.utc(2008,1,28)).must_equal(Time.parse('2008-01-27 12:00:00 -0800'))
|
121
|
+
expect(@ce.last_fire_at(Time.utc(2008,1,28))).must_equal(Time.parse('2008-01-27 12:00:00 -0800'))
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'gets last sunday for prior month and year' do
|
125
|
-
@ce.last_fire_at(Time.utc(2008,1,1)).must_equal(Time.parse('2007-12-30 12:00:00 -0800'))
|
125
|
+
expect(@ce.last_fire_at(Time.utc(2008,1,1))).must_equal(Time.parse('2007-12-30 12:00:00 -0800'))
|
126
126
|
end
|
127
127
|
|
128
128
|
|
129
129
|
it 'gets last sunday for prior month and year' do
|
130
130
|
nfa = @ce.last_fire_at(Time.utc(2007,12,1))
|
131
|
-
nfa.must_equal(Time.parse('2007-11-25 12:00:00 -0800'))
|
131
|
+
expect(nfa).must_equal(Time.parse('2007-11-25 12:00:00 -0800'))
|
132
132
|
|
133
133
|
nfa = @ce.last_fire_at(nfa - 1.second)
|
134
|
-
nfa.must_equal(Time.parse('2007-10-28 12:00:00 -0700'))
|
134
|
+
expect(nfa).must_equal(Time.parse('2007-10-28 12:00:00 -0700'))
|
135
135
|
|
136
136
|
nfa = @ce.next_fire_at(nfa + 1.second)
|
137
|
-
nfa.must_equal(Time.parse('2007-11-25 12:00:00 -0800'))
|
137
|
+
expect(nfa).must_equal(Time.parse('2007-11-25 12:00:00 -0800'))
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
@@ -6,7 +6,7 @@ describe SayWhen::Poller::CelluloidPoller do
|
|
6
6
|
let (:poller) { SayWhen::Poller::CelluloidPoller.new(100) }
|
7
7
|
|
8
8
|
it 'should instantiate the poller' do
|
9
|
-
poller.tick_length.must_equal 100
|
9
|
+
expect(poller.tick_length).must_equal 100
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should start the poller running, and can stop it' do
|
@@ -8,7 +8,7 @@ describe SayWhen::Poller::ConcurrentPoller do
|
|
8
8
|
let (:poller) { SayWhen::Poller::ConcurrentPoller.new(100) }
|
9
9
|
|
10
10
|
it 'should instantiate the poller' do
|
11
|
-
poller.tick_length.must_equal 100
|
11
|
+
expect(poller.tick_length).must_equal 100
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should start the poller running, and can stop it' do
|
@@ -7,21 +7,21 @@ describe SayWhen::Poller::SimplePoller do
|
|
7
7
|
let (:poller) { SayWhen::Poller::SimplePoller.new }
|
8
8
|
|
9
9
|
it 'should instantiate the poller' do
|
10
|
-
poller.wont_be_nil
|
10
|
+
expect(poller).wont_be_nil
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'can check if poller is running' do
|
14
|
-
poller.wont_be :running?
|
14
|
+
expect(poller).wont_be :running?
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should start the poller running, and can stop it' do
|
18
|
-
poller.wont_be :running
|
18
|
+
expect(poller).wont_be :running
|
19
19
|
|
20
20
|
Thread.start{ poller.start }
|
21
21
|
sleep(0.2)
|
22
|
-
poller.must_be :running
|
22
|
+
expect(poller).must_be :running
|
23
23
|
|
24
24
|
poller.stop
|
25
|
-
poller.wont_be :running
|
25
|
+
expect(poller).wont_be :running
|
26
26
|
end
|
27
27
|
end
|
@@ -21,11 +21,11 @@ describe SayWhen::Processor::ActiveJobStrategy do
|
|
21
21
|
job_method: 'execute'
|
22
22
|
}
|
23
23
|
|
24
|
-
SayWhen::Test::TestTask.wont_be :executed?
|
24
|
+
expect(SayWhen::Test::TestTask).wont_be :executed?
|
25
25
|
|
26
26
|
job = SayWhen::Storage::MemoryStrategy.create(options)
|
27
27
|
processor.process(job)
|
28
28
|
|
29
|
-
SayWhen::Test::TestTask.must_be :executed?
|
29
|
+
expect(SayWhen::Test::TestTask).must_be :executed?
|
30
30
|
end
|
31
31
|
end
|
@@ -10,6 +10,6 @@ describe SayWhen::Processor::SimpleStrategy do
|
|
10
10
|
it 'process a job by sending a message' do
|
11
11
|
job = Minitest::Mock.new
|
12
12
|
job.expect(:execute, 'done!')
|
13
|
-
processor.process(job).must_equal 'done!'
|
13
|
+
expect(processor.process(job)).must_equal 'done!'
|
14
14
|
end
|
15
15
|
end
|
@@ -7,35 +7,35 @@ describe SayWhen::Scheduler do
|
|
7
7
|
let (:scheduler) { SayWhen::Scheduler.new }
|
8
8
|
|
9
9
|
it 'has a logger' do
|
10
|
-
scheduler.logger.must_be_instance_of Logger
|
10
|
+
expect(scheduler.logger).must_be_instance_of Logger
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'extracts data' do
|
14
|
-
scheduler.extract_data({}).must_be_nil
|
15
|
-
scheduler.extract_data(data: 'data').must_equal 'data'
|
14
|
+
expect(scheduler.extract_data({})).must_be_nil
|
15
|
+
expect(scheduler.extract_data(data: 'data')).must_equal 'data'
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'extracts job method' do
|
19
|
-
scheduler.extract_job_method({}).must_equal 'execute'
|
20
|
-
scheduler.extract_job_method(job_method: 'just_doit').must_equal 'just_doit'
|
21
|
-
scheduler.extract_job_method(method: 'doit').must_equal 'doit'
|
19
|
+
expect(scheduler.extract_job_method({})).must_equal 'execute'
|
20
|
+
expect(scheduler.extract_job_method(job_method: 'just_doit')).must_equal 'just_doit'
|
21
|
+
expect(scheduler.extract_job_method(method: 'doit')).must_equal 'doit'
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'extracts job class' do
|
25
|
-
scheduler.extract_job_class(job_class: 'foo').must_equal 'foo'
|
26
|
-
scheduler.extract_job_class(class: 'foo').must_equal 'foo'
|
27
|
-
scheduler.extract_job_class(SayWhen::Test::TestTask).must_equal 'SayWhen::Test::TestTask'
|
28
|
-
scheduler.extract_job_class('SayWhen::Test::TestTask').must_equal 'SayWhen::Test::TestTask'
|
25
|
+
expect(scheduler.extract_job_class(job_class: 'foo')).must_equal 'foo'
|
26
|
+
expect(scheduler.extract_job_class(class: 'foo')).must_equal 'foo'
|
27
|
+
expect(scheduler.extract_job_class(SayWhen::Test::TestTask)).must_equal 'SayWhen::Test::TestTask'
|
28
|
+
expect(scheduler.extract_job_class('SayWhen::Test::TestTask')).must_equal 'SayWhen::Test::TestTask'
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'gets job options' do
|
32
32
|
keys = [:job_class, :job_method, :data]
|
33
33
|
opts = scheduler.job_options(keys.inject({}) { |s, k| s[k] = k.to_s; s } )
|
34
|
-
keys.each{|k| opts[k].must_equal k.to_s }
|
34
|
+
keys.each{|k| expect(opts[k]).must_equal k.to_s }
|
35
35
|
|
36
|
-
lambda do
|
36
|
+
expect(lambda do
|
37
37
|
scheduler.job_options(bar: 'foo')
|
38
|
-
end.must_raise RuntimeError
|
38
|
+
end).must_raise RuntimeError
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'can schedule a new job' do
|
@@ -45,15 +45,15 @@ describe SayWhen::Scheduler do
|
|
45
45
|
job_class: 'SayWhen::Test::TestTask',
|
46
46
|
job_method: 'execute'
|
47
47
|
)
|
48
|
-
job.wont_be_nil
|
48
|
+
expect(job).wont_be_nil
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'can schedule a cron job' do
|
52
52
|
job = scheduler.schedule_cron("0 0 12 ? * * *", SayWhen::Test::TestTask)
|
53
|
-
job.wont_be_nil
|
53
|
+
expect(job).wont_be_nil
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should provide the storage strategy' do
|
57
|
-
scheduler.storage.must_equal SayWhen::Storage::MemoryStrategy
|
57
|
+
expect(scheduler.storage).must_equal SayWhen::Storage::MemoryStrategy
|
58
58
|
end
|
59
59
|
end
|
@@ -21,40 +21,40 @@ describe SayWhen::Storage::ActiveRecordStrategy do
|
|
21
21
|
|
22
22
|
it 'job can be created' do
|
23
23
|
j = strategy.create(valid_attributes)
|
24
|
-
j.wont_be_nil
|
24
|
+
expect(j).wont_be_nil
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'job can be serialized' do
|
28
|
-
strategy.serialize(job).must_equal job
|
29
|
-
strategy.deserialize(job).must_equal job
|
28
|
+
expect(strategy.serialize(job)).must_equal job
|
29
|
+
expect(strategy.deserialize(job)).must_equal job
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'can execute the task for the job' do
|
33
|
-
job.execute_job( { result: 1 } ).must_equal 1
|
33
|
+
expect(job.execute_job( { result: 1 } )).must_equal 1
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'can execute the job' do
|
37
37
|
j = strategy.create(valid_attributes)
|
38
|
-
j.execute.must_equal 1
|
38
|
+
expect(j.execute).must_equal 1
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'derives a trigger from the attributes' do
|
42
42
|
t = strategy.create(valid_attributes)
|
43
|
-
t.trigger.wont_be_nil
|
44
|
-
t.trigger.must_be_instance_of SayWhen::Triggers::CronStrategy
|
43
|
+
expect(t.trigger).wont_be_nil
|
44
|
+
expect(t.trigger).must_be_instance_of SayWhen::Triggers::CronStrategy
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'has a waiting state on create' do
|
48
48
|
t = strategy.create(valid_attributes)
|
49
|
-
t.status.must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
49
|
+
expect(t.status).must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'has a next fire at set on create' do
|
53
53
|
opts = valid_attributes[:trigger_options]
|
54
54
|
ce = SayWhen::CronExpression.new(opts[:expression], opts[:time_zone])
|
55
55
|
j = strategy.create(valid_attributes)
|
56
|
-
j.status.must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
57
|
-
j.next_fire_at.must_equal ce.next_fire_at
|
56
|
+
expect(j.status).must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
57
|
+
expect(j.next_fire_at).must_equal ce.next_fire_at
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'can acquire and release the next job' do
|
@@ -71,14 +71,14 @@ describe SayWhen::Storage::ActiveRecordStrategy do
|
|
71
71
|
now = Time.now.change(hour: 0)
|
72
72
|
Time.stub(:now, now) do
|
73
73
|
j1 = strategy.create(valid_attributes)
|
74
|
-
j1.wont_be_nil
|
74
|
+
expect(j1).wont_be_nil
|
75
75
|
j2 = strategy.create(j2_opts)
|
76
76
|
|
77
77
|
next_job = strategy.acquire_next(2.days.since)
|
78
|
-
next_job.status.must_equal "acquired"
|
79
|
-
next_job.must_equal j2
|
78
|
+
expect(next_job.status).must_equal "acquired"
|
79
|
+
expect(next_job).must_equal j2
|
80
80
|
strategy.release(next_job)
|
81
|
-
next_job.status.must_equal "waiting"
|
81
|
+
expect(next_job.status).must_equal "waiting"
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -87,12 +87,12 @@ describe SayWhen::Storage::ActiveRecordStrategy do
|
|
87
87
|
j = strategy.create(valid_attributes)
|
88
88
|
j.update(status: 'acquired', updated_at: old, created_at: old)
|
89
89
|
|
90
|
-
j.status.must_equal 'acquired'
|
90
|
+
expect(j.status).must_equal 'acquired'
|
91
91
|
|
92
92
|
strategy.reset_acquired(3600)
|
93
93
|
|
94
94
|
j.reload
|
95
|
-
j.status.must_equal 'waiting'
|
95
|
+
expect(j.status).must_equal 'waiting'
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'can be fired' do
|
@@ -107,28 +107,28 @@ describe SayWhen::Storage::ActiveRecordStrategy do
|
|
107
107
|
now = Time.now
|
108
108
|
Time.stub(:now, now) do
|
109
109
|
strategy.fired(j, now)
|
110
|
-
j.next_fire_at.must_equal ce.next_fire_at(now)
|
111
|
-
j.last_fire_at.must_equal now
|
112
|
-
j.status.must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
110
|
+
expect(j.next_fire_at).must_equal ce.next_fire_at(now)
|
111
|
+
expect(j.last_fire_at).must_equal now
|
112
|
+
expect(j.status).must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
describe "acts_as_scheduled" do
|
117
117
|
it "acts_as_scheduled calls has_many" do
|
118
|
-
SayWhen::Test::TestActsAsScheduled.must_be :has_many_called?
|
118
|
+
expect(SayWhen::Test::TestActsAsScheduled).must_be :has_many_called?
|
119
119
|
end
|
120
120
|
|
121
121
|
it "includes schedule methods" do
|
122
122
|
taas = SayWhen::Test::TestActsAsScheduled.new
|
123
123
|
[:schedule, :schedule_instance, :schedule_cron, :schedule_once, :schedule_in].each do |m|
|
124
|
-
taas.respond_to?(m).must_equal true
|
124
|
+
expect(taas.respond_to?(m)).must_equal true
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
it "sets the scheduled value" do
|
129
129
|
taas = SayWhen::Test::TestActsAsScheduled.new
|
130
130
|
job = taas.set_scheduled({})
|
131
|
-
job[:scheduled].must_equal taas
|
131
|
+
expect(job[:scheduled]).must_equal taas
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
@@ -23,31 +23,31 @@ describe SayWhen::Storage::MemoryStrategy do
|
|
23
23
|
|
24
24
|
it 'job can be created' do
|
25
25
|
j = strategy.create(valid_attributes)
|
26
|
-
j.wont_be_nil
|
26
|
+
expect(j).wont_be_nil
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'can execute the task for the job' do
|
30
|
-
job.execute_job( { result: 1 } ).must_equal 1
|
30
|
+
expect(job.execute_job( { result: 1 } )).must_equal 1
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'can execute the job' do
|
34
34
|
j = strategy.create(valid_attributes)
|
35
|
-
j.execute.must_equal 1
|
35
|
+
expect(j.execute).must_equal 1
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'can serialize' do
|
39
39
|
j = strategy.create(valid_attributes)
|
40
|
-
j.to_hash[:job_class].must_equal 'SayWhen::Test::TestTask'
|
40
|
+
expect(j.to_hash[:job_class]).must_equal 'SayWhen::Test::TestTask'
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'can acquire and release the next job' do
|
44
44
|
j = strategy.create(valid_attributes)
|
45
|
-
j.wont_be_nil
|
45
|
+
expect(j).wont_be_nil
|
46
46
|
next_job = strategy.acquire_next(2.days.since)
|
47
|
-
next_job.wont_be_nil
|
48
|
-
next_job.status.must_equal "acquired"
|
47
|
+
expect(next_job).wont_be_nil
|
48
|
+
expect(next_job.status).must_equal "acquired"
|
49
49
|
strategy.release(next_job)
|
50
|
-
next_job.status.must_equal "waiting"
|
50
|
+
expect(next_job.status).must_equal "waiting"
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'can reset acquired jobs' do
|
@@ -55,7 +55,7 @@ describe SayWhen::Storage::MemoryStrategy do
|
|
55
55
|
j.status = 'acquired'
|
56
56
|
j.updated_at = 2.hours.ago
|
57
57
|
strategy.reset_acquired(3600)
|
58
|
-
j.status.must_equal 'waiting'
|
58
|
+
expect(j.status).must_equal 'waiting'
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'can be fired' do
|
@@ -70,20 +70,20 @@ describe SayWhen::Storage::MemoryStrategy do
|
|
70
70
|
now = Time.now
|
71
71
|
Time.stub(:now, now) do
|
72
72
|
strategy.fired(j, now)
|
73
|
-
j.next_fire_at.must_equal ce.next_fire_at(now)
|
74
|
-
j.last_fire_at.must_equal now
|
75
|
-
j.status.must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
73
|
+
expect(j.next_fire_at).must_equal ce.next_fire_at(now)
|
74
|
+
expect(j.last_fire_at).must_equal now
|
75
|
+
expect(j.status).must_equal SayWhen::Storage::BaseJob::STATE_WAITING
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
it "can be serialized to a hash" do
|
80
80
|
j = strategy.create(valid_attributes)
|
81
|
-
strategy.serialize(j).class.must_equal Hash
|
81
|
+
expect(strategy.serialize(j).class).must_equal Hash
|
82
82
|
end
|
83
83
|
|
84
84
|
it "can be deserialized from a hash" do
|
85
85
|
j = strategy.deserialize(valid_attributes)
|
86
|
-
j.class.must_equal SayWhen::Storage::MemoryStrategy::Job
|
86
|
+
expect(j.class).must_equal SayWhen::Storage::MemoryStrategy::Job
|
87
87
|
end
|
88
88
|
|
89
89
|
it "can reset acquired jobs" do
|
@@ -91,6 +91,6 @@ describe SayWhen::Storage::MemoryStrategy do
|
|
91
91
|
j.status = 'acquired'
|
92
92
|
j.updated_at = 2.hours.ago
|
93
93
|
SayWhen::Storage::MemoryStrategy::Job.reset_acquired(3600)
|
94
|
-
j.status.must_equal 'waiting'
|
94
|
+
expect(j.status).must_equal 'waiting'
|
95
95
|
end
|
96
96
|
end
|
@@ -6,6 +6,6 @@ require 'say_when/triggers/cron_strategy'
|
|
6
6
|
describe SayWhen::Triggers::CronStrategy do
|
7
7
|
it 'should be constucted with a cron expression' do
|
8
8
|
t = SayWhen::Triggers::CronStrategy.new(expression: '0 0 * ? * * *', job: {})
|
9
|
-
t.wont_be_nil
|
9
|
+
expect(t).wont_be_nil
|
10
10
|
end
|
11
11
|
end
|
@@ -8,16 +8,16 @@ describe SayWhen::Triggers::OnceStrategy do
|
|
8
8
|
it 'should be constucted with at option' do
|
9
9
|
time_at = 1.second.ago
|
10
10
|
o = SayWhen::Triggers::OnceStrategy.new(at: time_at, job: {})
|
11
|
-
o.wont_be_nil
|
12
|
-
o.once_at.must_equal time_at
|
11
|
+
expect(o).wont_be_nil
|
12
|
+
expect(o.once_at).must_equal time_at
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should return once at only once' do
|
16
16
|
time_at = 1.second.ago
|
17
17
|
o = SayWhen::Triggers::OnceStrategy.new(at: time_at, job: {})
|
18
|
-
o.wont_be_nil
|
19
|
-
o.next_fire_at.must_equal time_at
|
20
|
-
o.next_fire_at(time_at + 10.second).must_be_nil
|
21
|
-
o.next_fire_at(time_at - 10.second).must_equal time_at
|
18
|
+
expect(o).wont_be_nil
|
19
|
+
expect(o.next_fire_at).must_equal time_at
|
20
|
+
expect(o.next_fire_at(time_at + 10.second)).must_be_nil
|
21
|
+
expect(o.next_fire_at(time_at - 10.second)).must_equal time_at
|
22
22
|
end
|
23
23
|
end
|
data/test/say_when_test.rb
CHANGED
@@ -5,16 +5,16 @@ require 'minitest_helper'
|
|
5
5
|
describe SayWhen do
|
6
6
|
|
7
7
|
it 'provides a default logger' do
|
8
|
-
SayWhen.logger.wont_be_nil
|
8
|
+
expect(SayWhen.logger).wont_be_nil
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'can set a new logger' do
|
12
12
|
l = Logger.new('/dev/null')
|
13
13
|
SayWhen.logger = l
|
14
|
-
l.must_equal l
|
14
|
+
expect(l).must_equal l
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'provides the scheduler' do
|
18
|
-
SayWhen.scheduler.wont_be_nil
|
18
|
+
expect(SayWhen.scheduler).wont_be_nil
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: say_when
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kuklewicz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sorted_set
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,16 +140,16 @@ dependencies:
|
|
126
140
|
name: sqlite3
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
|
-
- - "
|
143
|
+
- - "~>"
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '1.4'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
|
-
- - "
|
150
|
+
- - "~>"
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '1.4'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: activerecord
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -255,7 +269,7 @@ homepage: https://github.com/kookster/say_when
|
|
255
269
|
licenses:
|
256
270
|
- MIT
|
257
271
|
metadata: {}
|
258
|
-
post_install_message:
|
272
|
+
post_install_message:
|
259
273
|
rdoc_options: []
|
260
274
|
require_paths:
|
261
275
|
- lib
|
@@ -270,8 +284,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
284
|
- !ruby/object:Gem::Version
|
271
285
|
version: '0'
|
272
286
|
requirements: []
|
273
|
-
rubygems_version: 3.
|
274
|
-
signing_key:
|
287
|
+
rubygems_version: 3.5.9
|
288
|
+
signing_key:
|
275
289
|
specification_version: 4
|
276
290
|
summary: Scheduling system for programmatically defined and stored jobs.
|
277
291
|
test_files:
|