sidekiq-cron 1.5.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +161 -0
- data/Gemfile +3 -0
- data/README.md +74 -66
- data/lib/sidekiq/cron/job.rb +191 -132
- data/lib/sidekiq/cron/launcher.rb +17 -15
- data/lib/sidekiq/cron/locales/it.yml +23 -0
- data/lib/sidekiq/cron/poller.rb +14 -18
- data/lib/sidekiq/cron/schedule_loader.rb +20 -0
- data/lib/sidekiq/cron/support.rb +8 -1
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/cron/views/cron.erb +1 -1
- data/lib/sidekiq/cron/web_extension.rb +6 -9
- data/lib/sidekiq/cron.rb +1 -0
- data/lib/sidekiq/options.rb +29 -0
- data/sidekiq-cron.gemspec +12 -13
- metadata +45 -32
- data/Changes.md +0 -111
- data/test/integration/performance_test.rb +0 -49
- data/test/test_helper.rb +0 -92
- data/test/unit/job_test.rb +0 -1124
- data/test/unit/poller_test.rb +0 -150
- data/test/unit/web_extension_test.rb +0 -156
data/test/unit/poller_test.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
|
3
|
-
describe 'Cron Poller' do
|
4
|
-
before do
|
5
|
-
REDIS.with { |c| c.respond_to?(:redis) ? c.redis.flushdb : c.flushdb }
|
6
|
-
Sidekiq.redis = REDIS
|
7
|
-
|
8
|
-
#clear all previous saved data from redis
|
9
|
-
Sidekiq.redis do |conn|
|
10
|
-
conn.keys("cron_job*").each do |key|
|
11
|
-
conn.del(key)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
@args = {
|
17
|
-
name: "Test",
|
18
|
-
cron: "*/2 * * * *",
|
19
|
-
klass: "CronTestClass"
|
20
|
-
}
|
21
|
-
@args2 = @args.merge(name: 'with_queue', klass: 'CronTestClassWithQueue', cron: "*/10 * * * *")
|
22
|
-
|
23
|
-
@poller = Sidekiq::Cron::Poller.new
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'not enqueue any job - new jobs' do
|
27
|
-
now = Time.now.utc + 3600
|
28
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 5, 1)
|
29
|
-
Time.stubs(:now).returns(enqueued_time)
|
30
|
-
#new jobs!
|
31
|
-
Sidekiq::Cron::Job.create(@args)
|
32
|
-
Sidekiq::Cron::Job.create(@args2)
|
33
|
-
|
34
|
-
@poller.enqueue
|
35
|
-
|
36
|
-
Sidekiq.redis do |conn|
|
37
|
-
assert_equal 0, conn.llen("queue:default")
|
38
|
-
assert_equal 0, conn.llen("queue:super")
|
39
|
-
end
|
40
|
-
|
41
|
-
#30 seconds after!
|
42
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 5, 30)
|
43
|
-
Time.stubs(:now).returns(enqueued_time)
|
44
|
-
|
45
|
-
@poller.enqueue
|
46
|
-
|
47
|
-
Sidekiq.redis do |conn|
|
48
|
-
assert_equal 0, conn.llen("queue:default")
|
49
|
-
assert_equal 0, conn.llen("queue:super")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should enqueue only job with cron */2' do
|
54
|
-
now = Time.now.utc + 3600
|
55
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 5, 1)
|
56
|
-
Time.stubs(:now).returns(enqueued_time)
|
57
|
-
#new jobs!
|
58
|
-
Sidekiq::Cron::Job.create(@args)
|
59
|
-
Sidekiq::Cron::Job.create(@args2)
|
60
|
-
|
61
|
-
@poller.enqueue
|
62
|
-
|
63
|
-
Sidekiq.redis do |conn|
|
64
|
-
assert_equal 0, conn.llen("queue:default")
|
65
|
-
assert_equal 0, conn.llen("queue:super")
|
66
|
-
end
|
67
|
-
|
68
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 6, 1)
|
69
|
-
Time.stubs(:now).returns(enqueued_time)
|
70
|
-
@poller.enqueue
|
71
|
-
|
72
|
-
Sidekiq.redis do |conn|
|
73
|
-
assert_equal 1, conn.llen("queue:default")
|
74
|
-
assert_equal 0, conn.llen("queue:super")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should enqueue both jobs' do
|
79
|
-
now = Time.now.utc + 3600
|
80
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 8, 1)
|
81
|
-
Time.stubs(:now).returns(enqueued_time)
|
82
|
-
#new jobs!
|
83
|
-
Sidekiq::Cron::Job.create(@args)
|
84
|
-
Sidekiq::Cron::Job.create(@args2)
|
85
|
-
|
86
|
-
@poller.enqueue
|
87
|
-
|
88
|
-
Sidekiq.redis do |conn|
|
89
|
-
assert_equal 0, conn.llen("queue:default")
|
90
|
-
assert_equal 0, conn.llen("queue:super")
|
91
|
-
end
|
92
|
-
|
93
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 10, 5)
|
94
|
-
Time.stubs(:now).returns(enqueued_time)
|
95
|
-
@poller.enqueue
|
96
|
-
|
97
|
-
Sidekiq.redis do |conn|
|
98
|
-
assert_equal 1, conn.llen("queue:default")
|
99
|
-
assert_equal 1, conn.llen("queue:super")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should enqueue both jobs but only one time each' do
|
104
|
-
now = Time.now.utc + 3600
|
105
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 8, 1)
|
106
|
-
Time.stubs(:now).returns(enqueued_time)
|
107
|
-
#new jobs!
|
108
|
-
Sidekiq::Cron::Job.create(@args)
|
109
|
-
Sidekiq::Cron::Job.create(@args2)
|
110
|
-
|
111
|
-
@poller.enqueue
|
112
|
-
|
113
|
-
Sidekiq.redis do |conn|
|
114
|
-
assert_equal 0, conn.llen("queue:default")
|
115
|
-
assert_equal 0, conn.llen("queue:super")
|
116
|
-
end
|
117
|
-
|
118
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 20, 1)
|
119
|
-
Time.stubs(:now).returns(enqueued_time)
|
120
|
-
@poller.enqueue
|
121
|
-
Sidekiq.redis do |conn|
|
122
|
-
assert_equal 1, conn.llen("queue:default")
|
123
|
-
assert_equal 1, conn.llen("queue:super")
|
124
|
-
end
|
125
|
-
|
126
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 20, 2)
|
127
|
-
Time.stubs(:now).returns(enqueued_time)
|
128
|
-
@poller.enqueue
|
129
|
-
Sidekiq.redis do |conn|
|
130
|
-
assert_equal 1, conn.llen("queue:default")
|
131
|
-
assert_equal 1, conn.llen("queue:super")
|
132
|
-
end
|
133
|
-
|
134
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 20, 20)
|
135
|
-
Time.stubs(:now).returns(enqueued_time)
|
136
|
-
@poller.enqueue
|
137
|
-
Sidekiq.redis do |conn|
|
138
|
-
assert_equal 1, conn.llen("queue:default")
|
139
|
-
assert_equal 1, conn.llen("queue:super")
|
140
|
-
end
|
141
|
-
|
142
|
-
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 20, 50)
|
143
|
-
Time.stubs(:now).returns(enqueued_time)
|
144
|
-
@poller.enqueue
|
145
|
-
Sidekiq.redis do |conn|
|
146
|
-
assert_equal 1, conn.llen("queue:default")
|
147
|
-
assert_equal 1, conn.llen("queue:super")
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
@@ -1,156 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
|
3
|
-
describe 'Cron web' do
|
4
|
-
include Rack::Test::Methods
|
5
|
-
|
6
|
-
TOKEN = SecureRandom.base64(32).freeze
|
7
|
-
|
8
|
-
def app
|
9
|
-
Sidekiq::Web
|
10
|
-
end
|
11
|
-
|
12
|
-
before do
|
13
|
-
env 'rack.session', { csrf: TOKEN }
|
14
|
-
env 'HTTP_X_CSRF_TOKEN', TOKEN
|
15
|
-
REDIS.with { |c| c.respond_to?(:redis) ? c.redis.flushdb : c.flushdb }
|
16
|
-
Sidekiq.redis = REDIS
|
17
|
-
end
|
18
|
-
|
19
|
-
let(:job_name) { "TestNameOfCronJob" }
|
20
|
-
let(:cron_job_name) { "TesQueueNameOfCronJob" }
|
21
|
-
|
22
|
-
let(:args) do
|
23
|
-
{
|
24
|
-
name: job_name,
|
25
|
-
cron: "*/2 * * * *",
|
26
|
-
klass: "CronTestClass"
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:cron_args) do
|
31
|
-
{
|
32
|
-
name: cron_job_name,
|
33
|
-
cron: "*/2 * * * *",
|
34
|
-
klass: "CronQueueTestClass",
|
35
|
-
queue: "cron"
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'display cron web' do
|
40
|
-
get '/cron'
|
41
|
-
assert_equal 200, last_response.status
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'display cron web with message - no cron jobs' do
|
45
|
-
get '/cron'
|
46
|
-
assert last_response.body.include?('No cron jobs were found')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'display cron web with cron jobs table' do
|
50
|
-
Sidekiq::Cron::Job.create(args)
|
51
|
-
|
52
|
-
get '/cron'
|
53
|
-
assert_equal 200, last_response.status
|
54
|
-
refute last_response.body.include?('No cron jobs were found')
|
55
|
-
assert last_response.body.include?('table')
|
56
|
-
assert last_response.body.include?("TestNameOfCronJob")
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "work with cron job" do
|
60
|
-
before do
|
61
|
-
@job = Sidekiq::Cron::Job.new(args.merge(status: "enabled"))
|
62
|
-
assert @job.save
|
63
|
-
|
64
|
-
@cron_job = Sidekiq::Cron::Job.new(cron_args.merge(status: "enabled"))
|
65
|
-
assert @cron_job.save
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'shows history of a cron job' do
|
69
|
-
@job.enque!
|
70
|
-
get "/cron/#{job_name}"
|
71
|
-
|
72
|
-
jid =
|
73
|
-
Sidekiq.redis do |conn|
|
74
|
-
history = conn.lrange Sidekiq::Cron::Job.jid_history_key(job_name), 0, -1
|
75
|
-
Sidekiq.load_json(history.last)['jid']
|
76
|
-
end
|
77
|
-
|
78
|
-
assert jid
|
79
|
-
assert last_response.body.include?(jid)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'redirects to cron path when name not found' do
|
83
|
-
get '/cron/some-fake-name'
|
84
|
-
|
85
|
-
assert_match %r{\/cron\z}, last_response['Location']
|
86
|
-
end
|
87
|
-
|
88
|
-
it "disable and enable all cron jobs" do
|
89
|
-
post "/cron/__all__/disable"
|
90
|
-
assert_equal Sidekiq::Cron::Job.find(job_name).status, "disabled"
|
91
|
-
|
92
|
-
post "/cron/__all__/enable"
|
93
|
-
assert_equal Sidekiq::Cron::Job.find(job_name).status, "enabled"
|
94
|
-
end
|
95
|
-
|
96
|
-
it "disable and enable cron job" do
|
97
|
-
post "/cron/#{job_name}/disable"
|
98
|
-
assert_equal Sidekiq::Cron::Job.find(job_name).status, "disabled"
|
99
|
-
|
100
|
-
post "/cron/#{job_name}/enable"
|
101
|
-
assert_equal Sidekiq::Cron::Job.find(job_name).status, "enabled"
|
102
|
-
end
|
103
|
-
|
104
|
-
it "enqueue all jobs" do
|
105
|
-
Sidekiq.redis do |conn|
|
106
|
-
assert_equal 0, conn.llen("queue:default"), "Queue should have no jobs"
|
107
|
-
end
|
108
|
-
|
109
|
-
post "/cron/__all__/enque"
|
110
|
-
|
111
|
-
Sidekiq.redis do |conn|
|
112
|
-
assert_equal 1, conn.llen("queue:default"), "Queue should have 1 job in default"
|
113
|
-
assert_equal 1, conn.llen("queue:cron"), "Queue should have 1 job in cron"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
it "enqueue job" do
|
118
|
-
Sidekiq.redis do |conn|
|
119
|
-
assert_equal 0, conn.llen("queue:default"), "Queue should have no jobs"
|
120
|
-
end
|
121
|
-
|
122
|
-
post "/cron/#{job_name}/enque"
|
123
|
-
|
124
|
-
Sidekiq.redis do |conn|
|
125
|
-
assert_equal 1, conn.llen("queue:default"), "Queue should have 1 job"
|
126
|
-
end
|
127
|
-
|
128
|
-
#should enqueue more times
|
129
|
-
post "/cron/#{job_name}/enque"
|
130
|
-
|
131
|
-
Sidekiq.redis do |conn|
|
132
|
-
assert_equal 2, conn.llen("queue:default"), "Queue should have 2 job"
|
133
|
-
end
|
134
|
-
|
135
|
-
#should enqueue to cron job queue
|
136
|
-
post "/cron/#{cron_job_name}/enque"
|
137
|
-
|
138
|
-
Sidekiq.redis do |conn|
|
139
|
-
assert_equal 1, conn.llen("queue:cron"), "Queue should have 1 cron job"
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
it "destroy job" do
|
144
|
-
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 job"
|
145
|
-
post "/cron/#{job_name}/delete"
|
146
|
-
post "/cron/#{cron_job_name}/delete"
|
147
|
-
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have zero jobs"
|
148
|
-
end
|
149
|
-
|
150
|
-
it "destroy all jobs" do
|
151
|
-
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 job"
|
152
|
-
post "/cron/__all__/delete"
|
153
|
-
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have zero jobs"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|