sidekiq-cron 0.2.0 → 0.3.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +2 -3
- data/Changes.md +6 -1
- data/Gemfile +10 -9
- data/README.md +83 -9
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/lib/sidekiq/cron.rb +1 -18
- data/lib/sidekiq/cron/job.rb +71 -12
- data/lib/sidekiq/cron/views/cron.erb +5 -5
- data/lib/sidekiq/cron/views/cron.slim +7 -7
- data/lib/sidekiq/cron/web.rb +12 -0
- data/sidekiq-cron.gemspec +13 -8
- data/test/test_helper.rb +2 -7
- data/test/unit/job_test.rb +587 -462
- data/test/unit/poller_test.rb +123 -127
- data/test/unit/web_extesion_test.rb +63 -68
- metadata +62 -84
@@ -34,20 +34,20 @@
|
|
34
34
|
</td>
|
35
35
|
<td style="<%= style %>">
|
36
36
|
<% if job.status == 'enabled' %>
|
37
|
-
<form action="<%= root_path %>cron/<%= job.name %>/enque" method="post">
|
37
|
+
<form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/enque" method="post">
|
38
38
|
<input class='btn btn-xs pull-left' type="submit" name="enque" value="<%= t('EnqueueNow') %>"/>
|
39
39
|
</form>
|
40
|
-
<form action="<%= root_path %>cron/<%= job.name %>/disable" method="post">
|
40
|
+
<form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/disable" method="post">
|
41
41
|
<input class='btn btn-xs pull-left' type="submit" name="disable" value="<%= t('Disable') %>"/>
|
42
42
|
</form>
|
43
43
|
<% else %>
|
44
|
-
<form action="<%= root_path %>cron/<%= job.name %>/enque" method="post">
|
44
|
+
<form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/enque" method="post">
|
45
45
|
<input class='btn btn-xs pull-left' type="submit" name="enque" value="<%= t('EnqueueNow') %>"/>
|
46
46
|
</form>
|
47
|
-
<form action="<%= root_path %>cron/<%= job.name %>/enable" method="post">
|
47
|
+
<form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/enable" method="post">
|
48
48
|
<input class='btn btn-xs pull-left' type="submit" name="enable" value="<%= t('Enable') %>"/>
|
49
49
|
</form>
|
50
|
-
<form action="<%= root_path %>cron/<%= job.name %>/delete" method="post">
|
50
|
+
<form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/delete" method="post">
|
51
51
|
<input class='btn btn-xs btn-danger pull-left' type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => job.name) %>"/>
|
52
52
|
</form>
|
53
53
|
<% end %>
|
@@ -10,7 +10,7 @@ header.row
|
|
10
10
|
th = t('Cron')
|
11
11
|
th = t('Last enque')
|
12
12
|
th = t('Arguments')
|
13
|
-
th width="253px"
|
13
|
+
th width="253px"
|
14
14
|
= t('Actions')
|
15
15
|
|
16
16
|
|
@@ -31,16 +31,16 @@ header.row
|
|
31
31
|
= job.message
|
32
32
|
td[style="#{style}"]
|
33
33
|
-if job.status == 'enabled'
|
34
|
-
form action="#{root_path}cron/#{job.name}/enque" method="post"
|
34
|
+
form action="#{root_path}cron/#{CGI.escape(job.name).gsub('+', '%20')}/enque" method="post"
|
35
35
|
input.btn.btn-small.pull-left type="submit" name="enque" value="#{t('EnqueueNow')}"
|
36
|
-
form action="#{root_path}cron/#{job.name}/disable" method="post"
|
36
|
+
form action="#{root_path}cron/#{CGI.escape(job.name).gsub('+', '%20')}/disable" method="post"
|
37
37
|
input.btn.btn-small.pull-left type="submit" name="disable" value="#{t('Disable')}"
|
38
|
-
-else
|
39
|
-
form action="#{root_path}cron/#{job.name}/enque" method="post"
|
38
|
+
-else
|
39
|
+
form action="#{root_path}cron/#{CGI.escape(job.name).gsub('+', '%20')}/enque" method="post"
|
40
40
|
input.btn.btn-small.pull-left type="submit" name="enque" value="#{t('EnqueueNow')}"
|
41
|
-
form action="#{root_path}cron/#{job.name}/enable" method="post"
|
41
|
+
form action="#{root_path}cron/#{CGI.escape(job.name).gsub('+', '%20')}/enable" method="post"
|
42
42
|
input.btn.btn-small.pull-left type="submit" name="enable" value="#{t('Enable')}"
|
43
|
-
form action="#{root_path}cron/#{job.name}/delete" method="post"
|
43
|
+
form action="#{root_path}cron/#{CGI.escape(job.name).gsub('+', '%20')}/delete" method="post"
|
44
44
|
input.btn.btn-danger.btn-small type="submit" name="delete" value="#{t('Delete')}" data-confirm="#{t('AreYouSureDeleteCronJob', :job => job.name)}"
|
45
45
|
|
46
46
|
- else
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "sidekiq/cron/web_extension"
|
2
|
+
|
3
|
+
if defined?(Sidekiq::Web)
|
4
|
+
Sidekiq::Web.register Sidekiq::Cron::WebExtension
|
5
|
+
|
6
|
+
if Sidekiq::Web.tabs.is_a?(Array)
|
7
|
+
# For sidekiq < 2.5
|
8
|
+
Sidekiq::Web.tabs << "cron"
|
9
|
+
else
|
10
|
+
Sidekiq::Web.tabs["Cron"] = "cron"
|
11
|
+
end
|
12
|
+
end
|
data/sidekiq-cron.gemspec
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: sidekiq-cron 0.3.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "sidekiq-cron"
|
8
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Ondrej Bartas"]
|
12
|
-
s.date = "
|
14
|
+
s.date = "2015-06-26"
|
13
15
|
s.description = "Enables to set jobs to be run in specified time (using CRON notation)"
|
14
16
|
s.email = "ondrej@bartas.cz"
|
15
17
|
s.extra_rdoc_files = [
|
@@ -36,6 +38,7 @@ Gem::Specification.new do |s|
|
|
36
38
|
"lib/sidekiq/cron/poller.rb",
|
37
39
|
"lib/sidekiq/cron/views/cron.erb",
|
38
40
|
"lib/sidekiq/cron/views/cron.slim",
|
41
|
+
"lib/sidekiq/cron/web.rb",
|
39
42
|
"lib/sidekiq/cron/web_extension.rb",
|
40
43
|
"sidekiq-cron.gemspec",
|
41
44
|
"test/test_helper.rb",
|
@@ -45,12 +48,11 @@ Gem::Specification.new do |s|
|
|
45
48
|
]
|
46
49
|
s.homepage = "http://github.com/ondrejbartas/sidekiq-cron"
|
47
50
|
s.licenses = ["MIT"]
|
48
|
-
s.
|
49
|
-
s.rubygems_version = "1.8.23"
|
51
|
+
s.rubygems_version = "2.4.5"
|
50
52
|
s.summary = "Sidekiq Cron helps to add repeated scheduled jobs"
|
51
53
|
|
52
54
|
if s.respond_to? :specification_version then
|
53
|
-
s.specification_version =
|
55
|
+
s.specification_version = 4
|
54
56
|
|
55
57
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
58
|
s.add_runtime_dependency(%q<tilt>, ["< 2.0.0"])
|
@@ -59,10 +61,11 @@ Gem::Specification.new do |s|
|
|
59
61
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
60
62
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
61
63
|
s.add_development_dependency(%q<shoulda-context>, [">= 0"])
|
62
|
-
s.add_development_dependency(%q<turn>, [">= 0"])
|
63
64
|
s.add_development_dependency(%q<rack>, [">= 0"])
|
64
65
|
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
65
66
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
67
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<test-unit>, [">= 0"])
|
66
69
|
s.add_development_dependency(%q<sdoc>, [">= 0"])
|
67
70
|
s.add_development_dependency(%q<slim>, [">= 0"])
|
68
71
|
s.add_development_dependency(%q<sinatra>, [">= 0"])
|
@@ -76,10 +79,11 @@ Gem::Specification.new do |s|
|
|
76
79
|
s.add_dependency(%q<bundler>, [">= 0"])
|
77
80
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
78
81
|
s.add_dependency(%q<shoulda-context>, [">= 0"])
|
79
|
-
s.add_dependency(%q<turn>, [">= 0"])
|
80
82
|
s.add_dependency(%q<rack>, [">= 0"])
|
81
83
|
s.add_dependency(%q<rack-test>, [">= 0"])
|
82
84
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
85
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
86
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
83
87
|
s.add_dependency(%q<sdoc>, [">= 0"])
|
84
88
|
s.add_dependency(%q<slim>, [">= 0"])
|
85
89
|
s.add_dependency(%q<sinatra>, [">= 0"])
|
@@ -94,10 +98,11 @@ Gem::Specification.new do |s|
|
|
94
98
|
s.add_dependency(%q<bundler>, [">= 0"])
|
95
99
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
96
100
|
s.add_dependency(%q<shoulda-context>, [">= 0"])
|
97
|
-
s.add_dependency(%q<turn>, [">= 0"])
|
98
101
|
s.add_dependency(%q<rack>, [">= 0"])
|
99
102
|
s.add_dependency(%q<rack-test>, [">= 0"])
|
100
103
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
104
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
105
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
101
106
|
s.add_dependency(%q<sdoc>, [">= 0"])
|
102
107
|
s.add_dependency(%q<slim>, [">= 0"])
|
103
108
|
s.add_dependency(%q<sinatra>, [">= 0"])
|
data/test/test_helper.rb
CHANGED
@@ -9,7 +9,7 @@ rescue Bundler::BundlerError => e
|
|
9
9
|
end
|
10
10
|
|
11
11
|
require 'simplecov'
|
12
|
-
SimpleCov.start do
|
12
|
+
SimpleCov.start do
|
13
13
|
add_filter "/test/"
|
14
14
|
|
15
15
|
add_group 'SidekiqCron', 'lib/'
|
@@ -19,7 +19,6 @@ Coveralls.wear!
|
|
19
19
|
|
20
20
|
require "minitest/autorun"
|
21
21
|
require 'shoulda-context'
|
22
|
-
require 'turn'
|
23
22
|
require "rack/test"
|
24
23
|
require "mocha/setup"
|
25
24
|
|
@@ -44,10 +43,7 @@ end
|
|
44
43
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
45
44
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
46
45
|
require 'sidekiq-cron'
|
47
|
-
|
48
|
-
class Test::Unit::TestCase
|
49
|
-
end
|
50
|
-
|
46
|
+
require 'sidekiq/cron/web'
|
51
47
|
|
52
48
|
class CronTestClass
|
53
49
|
include Sidekiq::Worker
|
@@ -65,4 +61,3 @@ class CronTestClassWithQueue
|
|
65
61
|
puts "super croned job #{args}"
|
66
62
|
end
|
67
63
|
end
|
68
|
-
|
data/test/unit/job_test.rb
CHANGED
@@ -1,584 +1,709 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require './test/test_helper'
|
3
3
|
|
4
|
-
|
5
|
-
context "Cron Job" do
|
4
|
+
describe "Cron Job" do
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
6
|
+
before do
|
7
|
+
#clear all previous saved data from redis
|
8
|
+
Sidekiq.redis do |conn|
|
9
|
+
conn.keys("cron_job*").each do |key|
|
10
|
+
conn.del(key)
|
13
11
|
end
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
#clear all queues
|
15
|
+
Sidekiq::Queue.all.each do |queue|
|
16
|
+
queue.clear
|
19
17
|
end
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
it "be initialized" do
|
21
|
+
job = Sidekiq::Cron::Job.new()
|
22
|
+
assert_nil job.last_enqueue_time
|
23
|
+
assert job.is_a?(Sidekiq::Cron::Job)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "class methods" do
|
27
|
+
it "have create method" do
|
28
|
+
assert Sidekiq::Cron::Job.respond_to?(:create)
|
25
29
|
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
+
it "have destroy method" do
|
32
|
+
assert Sidekiq::Cron::Job.respond_to?(:destroy)
|
33
|
+
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
it "have count" do
|
36
|
+
assert Sidekiq::Cron::Job.respond_to?(:count)
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
it "have all" do
|
40
|
+
assert Sidekiq::Cron::Job.respond_to?(:all)
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
it "have find" do
|
44
|
+
assert Sidekiq::Cron::Job.respond_to?(:find)
|
45
|
+
end
|
46
|
+
end
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
describe "instance methods" do
|
49
|
+
before do
|
50
|
+
@job = Sidekiq::Cron::Job.new()
|
47
51
|
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
assert @job.respond_to?("valid?".to_sym)
|
59
|
-
end
|
60
|
-
should "have destroy method" do
|
61
|
-
assert @job.respond_to?(:destroy)
|
62
|
-
end
|
53
|
+
it "have save method" do
|
54
|
+
assert @job.respond_to?(:save)
|
55
|
+
end
|
56
|
+
it "have valid? method" do
|
57
|
+
assert @job.respond_to?("valid?".to_sym)
|
58
|
+
end
|
59
|
+
it "have destroy method" do
|
60
|
+
assert @job.respond_to?(:destroy)
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
63
|
+
it 'have sort_name - used for sorting enabled disbaled jobs on frontend' do
|
64
|
+
job = Sidekiq::Cron::Job.new(name: "TestName")
|
65
|
+
assert_equal job.sort_name, "0_testname"
|
68
66
|
end
|
67
|
+
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
setup do
|
73
|
-
@job = Sidekiq::Cron::Job.new()
|
74
|
-
end
|
69
|
+
describe "invalid job" do
|
75
70
|
|
76
|
-
|
77
|
-
|
78
|
-
|
71
|
+
before do
|
72
|
+
@job = Sidekiq::Cron::Job.new()
|
73
|
+
end
|
79
74
|
|
80
|
-
|
81
|
-
|
82
|
-
assert @job.errors.any?{|e| e.include?("klass")}, "Should have error for klass"
|
83
|
-
end
|
75
|
+
it "allow a class instance for the klass" do
|
76
|
+
@job.klass = CronTestClass
|
84
77
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
assert @job.errors.is_a?(Array)
|
89
|
-
assert @job.errors.any?{|e| e.include?("cron")}, "Should have error for cron"
|
90
|
-
end
|
78
|
+
refute @job.valid?
|
79
|
+
refute @job.errors.any?{|e| e.include?("klass")}, "Should not have error for klass"
|
80
|
+
end
|
91
81
|
|
92
|
-
|
93
|
-
|
94
|
-
|
82
|
+
it "return false on valid? and errors" do
|
83
|
+
refute @job.valid?
|
84
|
+
assert @job.errors.is_a?(Array)
|
85
|
+
|
86
|
+
assert @job.errors.any?{|e| e.include?("name")}, "Should have error for name"
|
87
|
+
assert @job.errors.any?{|e| e.include?("cron")}, "Should have error for cron"
|
88
|
+
assert @job.errors.any?{|e| e.include?("klass")}, "Should have error for klass"
|
95
89
|
end
|
96
90
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@job = Sidekiq::Cron::Job.new(@args)
|
104
|
-
end
|
91
|
+
it "return false on valid? with invalid cron" do
|
92
|
+
@job.cron = "* s *"
|
93
|
+
refute @job.valid?
|
94
|
+
assert @job.errors.is_a?(Array)
|
95
|
+
assert @job.errors.any?{|e| e.include?("cron")}, "Should have error for cron"
|
96
|
+
end
|
105
97
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
98
|
+
it "return false on save" do
|
99
|
+
refute @job.save
|
100
|
+
end
|
101
|
+
end
|
111
102
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
103
|
+
describe "new" do
|
104
|
+
before do
|
105
|
+
@args = {
|
106
|
+
name: "Test",
|
107
|
+
cron: "* * * * *"
|
108
|
+
}
|
109
|
+
@job = Sidekiq::Cron::Job.new(@args)
|
117
110
|
end
|
118
111
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
Sidekiq::Cron::Job.new('klass' => CronTestClass)
|
123
|
-
end
|
112
|
+
it "have all setted attributes" do
|
113
|
+
@args.each do |key, value|
|
114
|
+
assert_equal @job.send(key), value, "New job should have #{key} with value #{value} but it has: #{@job.send(key)}"
|
124
115
|
end
|
116
|
+
end
|
125
117
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
118
|
+
it "have to_hash method" do
|
119
|
+
[:name,:klass,:cron,:args,:message,:status].each do |key|
|
120
|
+
assert @job.to_hash.has_key?(key), "to_hash must have key: #{key}"
|
130
121
|
end
|
122
|
+
end
|
123
|
+
end
|
131
124
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
125
|
+
describe "new with different class inputs" do
|
126
|
+
it "be initialized by 'klass' and Class" do
|
127
|
+
job = Sidekiq::Cron::Job.new('klass' => CronTestClass)
|
128
|
+
assert_equal job.message['class'], 'CronTestClass'
|
129
|
+
end
|
137
130
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
end
|
131
|
+
it "be initialized by 'klass' and string Class" do
|
132
|
+
job = Sidekiq::Cron::Job.new('klass' => 'CronTestClass')
|
133
|
+
assert_equal job.message['class'], 'CronTestClass'
|
143
134
|
end
|
144
135
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
assert_equal job.message, {"class"=>"UnknownCronClass", "args"=>[], "queue"=>"default"}
|
150
|
-
end
|
151
|
-
end
|
136
|
+
it "be initialized by 'class' and string Class" do
|
137
|
+
job = Sidekiq::Cron::Job.new('class' => 'CronTestClass')
|
138
|
+
assert_equal job.message['class'], 'CronTestClass'
|
139
|
+
end
|
152
140
|
|
153
|
-
|
154
|
-
|
155
|
-
|
141
|
+
it "be initialized by 'class' and Class" do
|
142
|
+
job = Sidekiq::Cron::Job.new('class' => CronTestClass)
|
143
|
+
assert_equal job.message['class'], 'CronTestClass'
|
144
|
+
end
|
145
|
+
end
|
156
146
|
|
157
|
-
|
158
|
-
|
159
|
-
|
147
|
+
describe "new should find klass specific settings (queue, retry ...)" do
|
148
|
+
it "nothing raise on unknown klass" do
|
149
|
+
job = Sidekiq::Cron::Job.new('klass' => 'UnknownCronClass')
|
150
|
+
assert_equal job.message, {"class"=>"UnknownCronClass", "args"=>[], "queue"=>"default"}
|
151
|
+
end
|
160
152
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
"queue"=>:super,
|
166
|
-
"backtrace"=>true,
|
167
|
-
"class"=>"CronTestClassWithQueue",
|
168
|
-
"args"=>[]}
|
169
|
-
end
|
170
|
-
end
|
153
|
+
it "be initialized with default attributes" do
|
154
|
+
job = Sidekiq::Cron::Job.new('klass' => 'CronTestClass')
|
155
|
+
assert_equal job.message, {"retry"=>true, "queue"=>"default", "class"=>"CronTestClass", "args"=>[]}
|
156
|
+
end
|
171
157
|
|
172
|
-
|
173
|
-
|
174
|
-
|
158
|
+
it "be initialized with class specified attributes" do
|
159
|
+
job = Sidekiq::Cron::Job.new('class' => 'CronTestClassWithQueue')
|
160
|
+
assert_equal job.message, {"retry"=>false,
|
161
|
+
"queue"=>:super,
|
162
|
+
"backtrace"=>true,
|
163
|
+
"class"=>"CronTestClassWithQueue",
|
164
|
+
"args"=>[]}
|
165
|
+
end
|
175
166
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
167
|
+
it "be initialized with 'class' and overwrite queue by settings" do
|
168
|
+
job = Sidekiq::Cron::Job.new('class' => CronTestClassWithQueue, queue: 'my_testing_queue')
|
169
|
+
|
170
|
+
assert_equal job.message, {"retry"=>false,
|
171
|
+
"queue"=>'my_testing_queue',
|
172
|
+
"backtrace"=>true,
|
173
|
+
"class"=>"CronTestClassWithQueue",
|
174
|
+
"args"=>[]}
|
183
175
|
end
|
184
|
-
|
185
|
-
context "cron test" do
|
186
|
-
setup do
|
187
|
-
@job = Sidekiq::Cron::Job.new()
|
188
|
-
end
|
176
|
+
end
|
189
177
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
178
|
+
describe "cron test" do
|
179
|
+
before do
|
180
|
+
@job = Sidekiq::Cron::Job.new()
|
181
|
+
end
|
195
182
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
183
|
+
it "return previous minute" do
|
184
|
+
@job.cron = "* * * * *"
|
185
|
+
time = Time.now
|
186
|
+
assert_equal @job.last_time(time).strftime("%Y-%m-%d-%H-%M-%S"), time.strftime("%Y-%m-%d-%H-%M-00")
|
187
|
+
end
|
188
|
+
|
189
|
+
it "return previous hour" do
|
190
|
+
@job.cron = "1 * * * *"
|
191
|
+
time = Time.now
|
192
|
+
assert_equal @job.last_time(time).strftime("%Y-%m-%d-%H-%M-%S"), time.strftime("%Y-%m-%d-%H-01-00")
|
193
|
+
end
|
194
|
+
|
195
|
+
it "return previous day" do
|
196
|
+
@job.cron = "1 2 * * *"
|
197
|
+
time = Time.now
|
201
198
|
|
202
|
-
|
203
|
-
@job.cron = "1 2 * * *"
|
204
|
-
time = Time.now
|
199
|
+
if time.hour >= 2
|
205
200
|
assert_equal @job.last_time(time).strftime("%Y-%m-%d-%H-%M-%S"), time.strftime("%Y-%m-%d-02-01-00")
|
201
|
+
else
|
202
|
+
yesterday = Date.today - 1
|
203
|
+
assert_equal @job.last_time(time).strftime("%Y-%m-%d-%H-%M-%S"), yesterday.strftime("%Y-%m-%d-02-01-00")
|
206
204
|
end
|
205
|
+
end
|
206
|
+
end
|
207
207
|
|
208
|
+
describe '#sidekiq_worker_message' do
|
209
|
+
before do
|
210
|
+
@args = {
|
211
|
+
name: 'Test',
|
212
|
+
cron: '* * * * *',
|
213
|
+
queue: 'super_queue',
|
214
|
+
klass: 'CronTestClass',
|
215
|
+
args: { foo: 'bar' }
|
216
|
+
}
|
217
|
+
@job = Sidekiq::Cron::Job.new(@args)
|
208
218
|
end
|
209
219
|
|
210
|
-
|
211
|
-
|
220
|
+
it 'should return valid payload for Sidekiq::Client' do
|
221
|
+
payload = {
|
222
|
+
"retry" => true,
|
223
|
+
"queue" => "super_queue",
|
224
|
+
"class" => "CronTestClass",
|
225
|
+
"args" => [{:foo=>"bar"}]
|
226
|
+
}
|
227
|
+
assert_equal @job.sidekiq_worker_message, payload
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe '#active_job_message' do
|
232
|
+
before do
|
233
|
+
SecureRandom.stubs(:uuid).returns('XYZ')
|
234
|
+
|
235
|
+
@args = {
|
236
|
+
name: 'Test',
|
237
|
+
cron: '* * * * *',
|
238
|
+
klass: 'CronTestClass',
|
239
|
+
queue: 'super_queue',
|
240
|
+
args: { foo: 'bar' }
|
241
|
+
}
|
242
|
+
@job = Sidekiq::Cron::Job.new(@args)
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should return valid payload for Sidekiq::Client' do
|
246
|
+
payload = {
|
247
|
+
'class' => 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper',
|
248
|
+
'queue' => 'super_queue',
|
249
|
+
'args' =>[{
|
250
|
+
'job_class' => 'CronTestClass',
|
251
|
+
'job_id' => 'XYZ',
|
252
|
+
'queue_name' => 'super_queue',
|
253
|
+
'arguments' => [{foo: 'bar'}]
|
254
|
+
}]
|
255
|
+
}
|
256
|
+
assert_equal @job.active_job_message, payload
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe '#enque!' do
|
261
|
+
describe 'active job' do
|
262
|
+
before do
|
263
|
+
module ActiveJob
|
264
|
+
class Base; end
|
265
|
+
end
|
266
|
+
class ActiveJobTest < ActiveJob::Base; end
|
267
|
+
|
212
268
|
@args = {
|
213
|
-
name:
|
214
|
-
cron:
|
215
|
-
klass:
|
269
|
+
name: 'Test',
|
270
|
+
cron: '* * * * *',
|
271
|
+
klass: 'ActiveJobTest'
|
216
272
|
}
|
217
273
|
@job = Sidekiq::Cron::Job.new(@args)
|
218
274
|
end
|
219
275
|
|
220
|
-
|
221
|
-
|
276
|
+
it 'pushes to queue active jobs message' do
|
277
|
+
@job.expects(:active_job_message)
|
278
|
+
.returns('class' => 'Test', 'args' => [])
|
279
|
+
@job.enque!
|
222
280
|
end
|
281
|
+
end
|
223
282
|
|
283
|
+
describe 'sidekiq worker' do
|
284
|
+
before do
|
285
|
+
@args = {
|
286
|
+
name: 'Test',
|
287
|
+
cron: '* * * * *',
|
288
|
+
klass: 'CronTestClass'
|
289
|
+
}
|
290
|
+
@job = Sidekiq::Cron::Job.new(@args)
|
291
|
+
end
|
224
292
|
|
225
|
-
|
226
|
-
|
227
|
-
|
293
|
+
it 'pushes to queue active jobs message' do
|
294
|
+
@job.expects(:sidekiq_worker_message)
|
295
|
+
.returns('class' => 'Test', 'args' => [])
|
296
|
+
@job.enque!
|
228
297
|
end
|
229
298
|
end
|
299
|
+
end
|
230
300
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
301
|
+
describe "save" do
|
302
|
+
before do
|
303
|
+
@args = {
|
304
|
+
name: "Test",
|
305
|
+
cron: "* * * * *",
|
306
|
+
klass: "CronTestClass"
|
307
|
+
}
|
308
|
+
@job = Sidekiq::Cron::Job.new(@args)
|
235
309
|
end
|
236
310
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
name: "Test",
|
241
|
-
cron: "* * * * *",
|
242
|
-
klass: "CronTestClass"
|
243
|
-
}
|
244
|
-
end
|
311
|
+
it "be saved" do
|
312
|
+
assert @job.save
|
313
|
+
end
|
245
314
|
|
246
|
-
should "be created and enabled" do
|
247
|
-
Sidekiq::Cron::Job.create(@args)
|
248
|
-
job = Sidekiq::Cron::Job.find(@args)
|
249
|
-
assert_equal job.status, "enabled"
|
250
|
-
end
|
251
315
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
316
|
+
it "be saved and found by name" do
|
317
|
+
assert @job.save, "not saved"
|
318
|
+
assert Sidekiq::Cron::Job.find("Test").is_a?(Sidekiq::Cron::Job)
|
319
|
+
end
|
320
|
+
end
|
256
321
|
|
257
|
-
|
258
|
-
|
322
|
+
describe "nonexisting job" do
|
323
|
+
it "not be found" do
|
324
|
+
assert Sidekiq::Cron::Job.find("nonexisting").nil?, "should return nil"
|
325
|
+
end
|
326
|
+
end
|
259
327
|
|
260
|
-
|
261
|
-
|
262
|
-
|
328
|
+
describe "disabled/enabled" do
|
329
|
+
before do
|
330
|
+
@args = {
|
331
|
+
name: "Test",
|
332
|
+
cron: "* * * * *",
|
333
|
+
klass: "CronTestClass"
|
334
|
+
}
|
335
|
+
end
|
263
336
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
337
|
+
it "be created and enabled" do
|
338
|
+
Sidekiq::Cron::Job.create(@args)
|
339
|
+
job = Sidekiq::Cron::Job.find(@args)
|
340
|
+
assert_equal job.status, "enabled"
|
341
|
+
end
|
269
342
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
job.disable!
|
275
|
-
assert_equal job.status, "disabled", "directly after call"
|
276
|
-
job = Sidekiq::Cron::Job.find(@args)
|
277
|
-
assert_equal job.status, "disabled", "after find"
|
278
|
-
end
|
343
|
+
it "be created and then enabled and disabled" do
|
344
|
+
Sidekiq::Cron::Job.create(@args)
|
345
|
+
job = Sidekiq::Cron::Job.find(@args)
|
346
|
+
assert_equal job.status, "enabled"
|
279
347
|
|
280
|
-
|
281
|
-
|
282
|
-
job = Sidekiq::Cron::Job.find(@args)
|
283
|
-
assert_equal job.status, "enabled"
|
284
|
-
job.disable!
|
285
|
-
assert_equal job.status, "disabled", "directly after call"
|
286
|
-
job = Sidekiq::Cron::Job.find(@args)
|
287
|
-
assert_equal job.status, "disabled", "after find"
|
288
|
-
|
289
|
-
Sidekiq::Cron::Job.create(@args)
|
290
|
-
assert_equal job.status, "disabled", "after second create"
|
291
|
-
job = Sidekiq::Cron::Job.find(@args)
|
292
|
-
assert_equal job.status, "disabled", "after second find"
|
293
|
-
end
|
348
|
+
job.enable!
|
349
|
+
assert_equal job.status, "enabled"
|
294
350
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
Sidekiq::Cron::Job.create(@args.merge('last_enqueue_time' => last_enqueue_time))
|
299
|
-
job = Sidekiq::Cron::Job.find(@args)
|
300
|
-
assert_equal job.last_enqueue_time, Time.parse(last_enqueue_time)
|
351
|
+
job.disable!
|
352
|
+
assert_equal job.status, "disabled"
|
353
|
+
end
|
301
354
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
355
|
+
it "be created with status disabled" do
|
356
|
+
Sidekiq::Cron::Job.create(@args.merge(status: "disabled"))
|
357
|
+
job = Sidekiq::Cron::Job.find(@args)
|
358
|
+
assert_equal job.status, "disabled"
|
306
359
|
end
|
307
360
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
361
|
+
it "be created with status enabled and disable it afterwards" do
|
362
|
+
Sidekiq::Cron::Job.create(@args)
|
363
|
+
job = Sidekiq::Cron::Job.find(@args)
|
364
|
+
assert_equal job.status, "enabled"
|
365
|
+
job.disable!
|
366
|
+
assert_equal job.status, "disabled", "directly after call"
|
367
|
+
job = Sidekiq::Cron::Job.find(@args)
|
368
|
+
assert_equal job.status, "disabled", "after find"
|
369
|
+
end
|
370
|
+
|
371
|
+
it "status shouldn't be rewritten after save without status" do
|
372
|
+
Sidekiq::Cron::Job.create(@args)
|
373
|
+
job = Sidekiq::Cron::Job.find(@args)
|
374
|
+
assert_equal job.status, "enabled"
|
375
|
+
job.disable!
|
376
|
+
assert_equal job.status, "disabled", "directly after call"
|
377
|
+
job = Sidekiq::Cron::Job.find(@args)
|
378
|
+
assert_equal job.status, "disabled", "after find"
|
379
|
+
|
380
|
+
Sidekiq::Cron::Job.create(@args)
|
381
|
+
assert_equal job.status, "disabled", "after second create"
|
382
|
+
job = Sidekiq::Cron::Job.find(@args)
|
383
|
+
assert_equal job.status, "disabled", "after second find"
|
384
|
+
end
|
385
|
+
|
386
|
+
it "last_enqueue_time shouldn't be rewritten after save" do
|
387
|
+
#adding last_enqueue_time to initialize is only for test purpose
|
388
|
+
last_enqueue_time = '2013-01-01 23:59:59'
|
389
|
+
Sidekiq::Cron::Job.create(@args.merge('last_enqueue_time' => last_enqueue_time))
|
390
|
+
job = Sidekiq::Cron::Job.find(@args)
|
391
|
+
assert_equal job.last_enqueue_time, Time.parse(last_enqueue_time)
|
392
|
+
|
393
|
+
Sidekiq::Cron::Job.create(@args)
|
394
|
+
job = Sidekiq::Cron::Job.find(@args)
|
395
|
+
assert_equal job.last_enqueue_time, Time.parse(last_enqueue_time), "after second create should have same time"
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
describe "initialize args" do
|
400
|
+
it "from JSON" do
|
401
|
+
args = {
|
402
|
+
name: "Test",
|
403
|
+
cron: "* * * * *",
|
404
|
+
klass: "CronTestClass",
|
405
|
+
args: JSON.dump(["123"])
|
406
|
+
}
|
407
|
+
Sidekiq::Cron::Job.new(args).tap do |job|
|
408
|
+
assert_equal job.args, ["123"]
|
409
|
+
assert_equal job.name, "Test"
|
332
410
|
end
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
411
|
+
end
|
412
|
+
it "from String" do
|
413
|
+
args = {
|
414
|
+
name: "Test",
|
415
|
+
cron: "* * * * *",
|
416
|
+
klass: "CronTestClass",
|
417
|
+
args: "(my funny string)"
|
418
|
+
}
|
419
|
+
Sidekiq::Cron::Job.new(args).tap do |job|
|
420
|
+
assert_equal job.args, ["(my funny string)"]
|
421
|
+
assert_equal job.name, "Test"
|
344
422
|
end
|
345
423
|
end
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
424
|
+
it "from Array" do
|
425
|
+
args = {
|
426
|
+
name: "Test",
|
427
|
+
cron: "* * * * *",
|
428
|
+
klass: "CronTestClass",
|
429
|
+
args: ["This is array"]
|
430
|
+
}
|
431
|
+
Sidekiq::Cron::Job.new(args).tap do |job|
|
432
|
+
assert_equal job.args, ["This is array"]
|
433
|
+
assert_equal job.name, "Test"
|
354
434
|
end
|
435
|
+
end
|
436
|
+
end
|
355
437
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
438
|
+
describe "create & find methods" do
|
439
|
+
before do
|
440
|
+
@args = {
|
441
|
+
name: "Test",
|
442
|
+
cron: "* * * * *",
|
443
|
+
klass: "CronTestClass"
|
444
|
+
}
|
445
|
+
end
|
363
446
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
447
|
+
it "create first three jobs" do
|
448
|
+
assert_equal Sidekiq::Cron::Job.count, 0, "Should have 0 jobs"
|
449
|
+
Sidekiq::Cron::Job.create(@args)
|
450
|
+
Sidekiq::Cron::Job.create(@args.merge(name: "Test2"))
|
451
|
+
Sidekiq::Cron::Job.create(@args.merge(name: "Test3"))
|
452
|
+
assert_equal Sidekiq::Cron::Job.count, 3, "Should have 3 jobs"
|
453
|
+
end
|
371
454
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
455
|
+
it "create first three jobs - 1 has same name" do
|
456
|
+
assert_equal Sidekiq::Cron::Job.count, 0, "Should have 0 jobs"
|
457
|
+
Sidekiq::Cron::Job.create(@args)
|
458
|
+
Sidekiq::Cron::Job.create(@args.merge(name: "Test2"))
|
459
|
+
Sidekiq::Cron::Job.create(@args.merge(cron: "1 * * * *"))
|
460
|
+
assert_equal Sidekiq::Cron::Job.count, 2, "Should have 2 jobs"
|
461
|
+
end
|
379
462
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
463
|
+
it "be found by method all" do
|
464
|
+
Sidekiq::Cron::Job.create(@args)
|
465
|
+
Sidekiq::Cron::Job.create(@args.merge(name: "Test2"))
|
466
|
+
Sidekiq::Cron::Job.create(@args.merge(name: "Test3"))
|
467
|
+
assert_equal Sidekiq::Cron::Job.all.size, 3, "Should have 3 jobs"
|
468
|
+
assert Sidekiq::Cron::Job.all.all?{|j| j.is_a?(Sidekiq::Cron::Job)}, "All returned jobs should be Job class"
|
469
|
+
end
|
384
470
|
|
385
|
-
|
386
|
-
|
387
|
-
|
471
|
+
it "be found by method all - defect in set" do
|
472
|
+
Sidekiq::Cron::Job.create(@args)
|
473
|
+
Sidekiq::Cron::Job.create(@args.merge(name: "Test2"))
|
474
|
+
Sidekiq::Cron::Job.create(@args.merge(name: "Test3"))
|
388
475
|
|
389
|
-
|
476
|
+
Sidekiq.redis do |conn|
|
477
|
+
conn.sadd Sidekiq::Cron::Job.jobs_key, "some_other_key"
|
390
478
|
end
|
391
479
|
|
392
|
-
|
393
|
-
|
394
|
-
assert Sidekiq::Cron::Job.find("Test")
|
395
|
-
end
|
480
|
+
assert_equal Sidekiq::Cron::Job.all.size, 3, "All have to return only valid 3 jobs"
|
481
|
+
end
|
396
482
|
|
397
|
-
|
398
|
-
|
399
|
-
|
483
|
+
it "be found by string name" do
|
484
|
+
Sidekiq::Cron::Job.create(@args)
|
485
|
+
assert Sidekiq::Cron::Job.find("Test")
|
486
|
+
end
|
400
487
|
|
401
|
-
|
402
|
-
|
403
|
-
|
488
|
+
it "be found by hash with key name" do
|
489
|
+
Sidekiq::Cron::Job.create(@args)
|
490
|
+
assert Sidekiq::Cron::Job.find(name: "Test"), "symbol keys keys"
|
404
491
|
|
492
|
+
Sidekiq::Cron::Job.create(@args)
|
493
|
+
assert Sidekiq::Cron::Job.find('name' => "Test"), "String keys"
|
405
494
|
end
|
406
495
|
|
407
|
-
|
408
|
-
setup do
|
409
|
-
@args = {
|
410
|
-
name: "Test",
|
411
|
-
cron: "* * * * *",
|
412
|
-
klass: "CronTestClass"
|
413
|
-
}
|
414
|
-
end
|
496
|
+
end
|
415
497
|
|
416
|
-
|
417
|
-
|
418
|
-
|
498
|
+
describe "destroy" do
|
499
|
+
before do
|
500
|
+
@args = {
|
501
|
+
name: "Test",
|
502
|
+
cron: "* * * * *",
|
503
|
+
klass: "CronTestClass"
|
504
|
+
}
|
505
|
+
end
|
419
506
|
|
420
|
-
|
421
|
-
|
422
|
-
|
507
|
+
it "create and then destroy by hash" do
|
508
|
+
Sidekiq::Cron::Job.create(@args)
|
509
|
+
assert_equal Sidekiq::Cron::Job.all.size, 1, "Should have 1 job"
|
423
510
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
end
|
511
|
+
assert Sidekiq::Cron::Job.destroy(@args)
|
512
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 job after destroy"
|
513
|
+
end
|
428
514
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
515
|
+
it "return false on destroying nonexisting" do
|
516
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs"
|
517
|
+
refute Sidekiq::Cron::Job.destroy("nonexisting")
|
518
|
+
end
|
433
519
|
|
434
|
-
|
435
|
-
|
436
|
-
|
520
|
+
it "return destroy by string name" do
|
521
|
+
Sidekiq::Cron::Job.create(@args)
|
522
|
+
assert Sidekiq::Cron::Job.destroy("Test")
|
523
|
+
end
|
437
524
|
|
438
|
-
|
439
|
-
|
440
|
-
|
525
|
+
it "return destroy by hash with key name" do
|
526
|
+
Sidekiq::Cron::Job.create(@args)
|
527
|
+
assert Sidekiq::Cron::Job.destroy(name: "Test"), "symbol keys keys"
|
441
528
|
|
529
|
+
Sidekiq::Cron::Job.create(@args)
|
530
|
+
assert Sidekiq::Cron::Job.destroy('name' => "Test"), "String keys"
|
442
531
|
end
|
443
532
|
|
444
|
-
|
445
|
-
setup do
|
446
|
-
@args = {
|
447
|
-
name: "Test",
|
448
|
-
cron: "* * * * *",
|
449
|
-
klass: "CronTestClass"
|
450
|
-
}
|
451
|
-
#first time is allways
|
452
|
-
#after next cron time!
|
453
|
-
@time = Time.now + 120
|
454
|
-
end
|
455
|
-
should "be allways false when status is disabled" do
|
456
|
-
refute Sidekiq::Cron::Job.new(@args.merge(status: 'disabled')).should_enque? @time
|
457
|
-
refute Sidekiq::Cron::Job.new(@args.merge(status: 'disabled')).should_enque? @time - 60
|
458
|
-
refute Sidekiq::Cron::Job.new(@args.merge(status: 'disabled')).should_enque? @time - 120
|
459
|
-
assert_equal Sidekiq::Queue.all.size, 0, "Sidekiq 0 queues"
|
460
|
-
end
|
533
|
+
end
|
461
534
|
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
535
|
+
describe "destroy_removed_jobs" do
|
536
|
+
before do
|
537
|
+
args1 = {
|
538
|
+
name: "WillBeErasedJob",
|
539
|
+
cron: "* * * * *",
|
540
|
+
klass: "CronTestClass"
|
541
|
+
}
|
542
|
+
Sidekiq::Cron::Job.create(args1)
|
543
|
+
|
544
|
+
args2 = {
|
545
|
+
name: "ContinueRemainingJob",
|
546
|
+
cron: "* * * * *",
|
547
|
+
klass: "CronTestClass"
|
548
|
+
}
|
549
|
+
Sidekiq::Cron::Job.create(args2)
|
550
|
+
end
|
467
551
|
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 135
|
473
|
-
assert Sidekiq::Cron::Job.new(@args).should_enque? @time + 235
|
474
|
-
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 235
|
475
|
-
|
476
|
-
#just for check
|
477
|
-
refute Sidekiq::Cron::Job.new(@args).should_enque? @time
|
478
|
-
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 135
|
479
|
-
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 235
|
480
|
-
end
|
552
|
+
it "be destroied removed job that not exists in args" do
|
553
|
+
assert_equal Sidekiq::Cron::Job.destroy_removed_jobs(["ContinueRemainingJob"]), ["WillBeErasedJob"], "Should be destroyed WillBeErasedJob"
|
554
|
+
end
|
555
|
+
end
|
481
556
|
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
557
|
+
describe "test of enque" do
|
558
|
+
before do
|
559
|
+
@args = {
|
560
|
+
name: "Test",
|
561
|
+
cron: "* * * * *",
|
562
|
+
klass: "CronTestClass"
|
563
|
+
}
|
564
|
+
#first time is allways
|
565
|
+
#after next cron time!
|
566
|
+
@time = Time.now + 120
|
567
|
+
end
|
568
|
+
it "be allways false when status is disabled" do
|
569
|
+
refute Sidekiq::Cron::Job.new(@args.merge(status: 'disabled')).should_enque? @time
|
570
|
+
refute Sidekiq::Cron::Job.new(@args.merge(status: 'disabled')).should_enque? @time - 60
|
571
|
+
refute Sidekiq::Cron::Job.new(@args.merge(status: 'disabled')).should_enque? @time - 120
|
572
|
+
assert_equal Sidekiq::Queue.all.size, 0, "Sidekiq 0 queues"
|
573
|
+
end
|
487
574
|
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
575
|
+
it "be false for same times" do
|
576
|
+
assert Sidekiq::Cron::Job.new(@args).should_enque?(@time), "First time - true"
|
577
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time
|
578
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time
|
579
|
+
end
|
493
580
|
|
494
|
-
|
495
|
-
|
496
|
-
|
581
|
+
it "be false for same times but true for next time" do
|
582
|
+
assert Sidekiq::Cron::Job.new(@args).should_enque?(@time), "First time - true"
|
583
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time
|
584
|
+
assert Sidekiq::Cron::Job.new(@args).should_enque? @time + 135
|
585
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 135
|
586
|
+
assert Sidekiq::Cron::Job.new(@args).should_enque? @time + 235
|
587
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 235
|
588
|
+
|
589
|
+
#just for check
|
590
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time
|
591
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 135
|
592
|
+
refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 235
|
593
|
+
end
|
497
594
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
595
|
+
it "remove old enque times + should be enqeued" do
|
596
|
+
job = Sidekiq::Cron::Job.new(@args)
|
597
|
+
assert_nil job.last_enqueue_time
|
598
|
+
assert job.test_and_enque_for_time!(@time), "should enqueue"
|
599
|
+
assert job.last_enqueue_time
|
502
600
|
|
503
|
-
|
504
|
-
|
505
|
-
|
601
|
+
refute Sidekiq::Cron::Job.new(@args).test_and_enque_for_time!(@time), "should not enqueue"
|
602
|
+
Sidekiq.redis do |conn|
|
603
|
+
assert_equal conn.zcard(Sidekiq::Cron::Job.new(@args).send(:job_enqueued_key)), 2, "Should have two enqueued job (first was in save, second in enque)"
|
604
|
+
end
|
605
|
+
assert_equal Sidekiq::Queue.all.first.size, 1, "Sidekiq queue 1 job in queue"
|
506
606
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
607
|
+
# 20 hours after
|
608
|
+
assert Sidekiq::Cron::Job.new(@args).test_and_enque_for_time! @time + 1 * 60 * 60
|
609
|
+
refute Sidekiq::Cron::Job.new(@args).test_and_enque_for_time! @time + 1 * 60 * 60
|
610
|
+
|
611
|
+
Sidekiq.redis do |conn|
|
612
|
+
assert_equal conn.zcard(Sidekiq::Cron::Job.new(@args).send(:job_enqueued_key)), 3, "Should have two enqueued job + one from start"
|
511
613
|
end
|
614
|
+
assert_equal Sidekiq::Queue.all.first.size, 2, "Sidekiq queue 2 jobs in queue"
|
615
|
+
|
616
|
+
# 26 hour after
|
617
|
+
assert Sidekiq::Cron::Job.new(@args).test_and_enque_for_time! @time + 26 * 60 * 60
|
618
|
+
refute Sidekiq::Cron::Job.new(@args).test_and_enque_for_time! @time + 26 * 60 * 60
|
619
|
+
|
620
|
+
Sidekiq.redis do |conn|
|
621
|
+
assert_equal conn.zcard(Sidekiq::Cron::Job.new(@args).send(:job_enqueued_key)), 1, "Should have one enqueued job - old jobs should be deleted"
|
622
|
+
end
|
623
|
+
assert_equal Sidekiq::Queue.all.first.size, 3, "Sidekiq queue 3 jobs in queue"
|
512
624
|
end
|
625
|
+
end
|
513
626
|
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
}
|
627
|
+
describe "load" do
|
628
|
+
|
629
|
+
describe "from hash" do
|
630
|
+
before do
|
631
|
+
@jobs_hash = {
|
632
|
+
'name_of_job' => {
|
633
|
+
'class' => 'MyClass',
|
634
|
+
'cron' => '1 * * * *',
|
635
|
+
'args' => '(OPTIONAL) [Array or Hash]'
|
636
|
+
},
|
637
|
+
'My super iber cool job' => {
|
638
|
+
'class' => 'SecondClass',
|
639
|
+
'cron' => '*/5 * * * *'
|
528
640
|
}
|
529
|
-
|
641
|
+
}
|
642
|
+
end
|
530
643
|
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
644
|
+
it "create new jobs and update old one with same settings" do
|
645
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
|
646
|
+
out = Sidekiq::Cron::Job.load_from_hash @jobs_hash
|
647
|
+
assert_equal out.size, 0, "should have no errors"
|
648
|
+
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
|
649
|
+
end
|
537
650
|
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
651
|
+
it "return errors on loaded jobs" do
|
652
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
|
653
|
+
#set something bag to hash
|
654
|
+
@jobs_hash['name_of_job']['cron'] = "bad cron"
|
655
|
+
out = Sidekiq::Cron::Job.load_from_hash @jobs_hash
|
656
|
+
assert_equal 1, out.size, "should have 1 error"
|
657
|
+
assert_equal ({"name_of_job"=>["'cron' -> bad cron: not a valid cronline : 'bad cron'"]}), out
|
658
|
+
assert_equal 1, Sidekiq::Cron::Job.all.size, "Should have only 1 job after load"
|
659
|
+
end
|
547
660
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
661
|
+
it "create new jobs and then destroy them all" do
|
662
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
|
663
|
+
out = Sidekiq::Cron::Job.load_from_hash @jobs_hash
|
664
|
+
assert_equal out.size, 0, "should have no errors"
|
665
|
+
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
|
666
|
+
Sidekiq::Cron::Job.destroy_all!
|
667
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs after destroy all"
|
668
|
+
end
|
669
|
+
|
670
|
+
it "create new jobs and update old one with same settings with load_from_hash!" do
|
671
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
|
672
|
+
out = Sidekiq::Cron::Job.load_from_hash! @jobs_hash
|
673
|
+
assert_equal out.size, 0, "should have no errors"
|
674
|
+
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
|
675
|
+
end
|
676
|
+
end
|
556
677
|
|
678
|
+
describe "from array" do
|
679
|
+
before do
|
680
|
+
@jobs_array = [
|
681
|
+
{
|
682
|
+
'name' => 'name_of_job',
|
683
|
+
'class' => 'MyClass',
|
684
|
+
'cron' => '1 * * * *',
|
685
|
+
'args' => '(OPTIONAL) [Array or Hash]'
|
686
|
+
},
|
687
|
+
{
|
688
|
+
'name' => 'Cool Job for Second Class',
|
689
|
+
'class' => 'SecondClass',
|
690
|
+
'cron' => '*/5 * * * *'
|
691
|
+
}
|
692
|
+
]
|
557
693
|
end
|
558
694
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
'cron' => '1 * * * *',
|
566
|
-
'args' => '(OPTIONAL) [Array or Hash]'
|
567
|
-
},
|
568
|
-
{
|
569
|
-
'name' => 'Cool Job for Second Class',
|
570
|
-
'class' => 'SecondClass',
|
571
|
-
'cron' => '*/5 * * * *'
|
572
|
-
}
|
573
|
-
]
|
574
|
-
end
|
695
|
+
it "create new jobs and update old one with same settings" do
|
696
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
|
697
|
+
out = Sidekiq::Cron::Job.load_from_array @jobs_array
|
698
|
+
assert_equal out.size, 0, "should have 0 error"
|
699
|
+
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
|
700
|
+
end
|
575
701
|
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
end
|
702
|
+
it "create new jobs and update old one with same settings with load_from_array" do
|
703
|
+
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
|
704
|
+
out = Sidekiq::Cron::Job.load_from_array! @jobs_array
|
705
|
+
assert_equal out.size, 0, "should have 0 error"
|
706
|
+
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
|
582
707
|
end
|
583
708
|
end
|
584
709
|
end
|