scheduled_job 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/scheduled_job/version.rb +1 -1
- data/lib/scheduled_job.rb +3 -1
- data/spec/lib/scheduled_job_spec.rb +41 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9ef9b5bd8566235b6a1befa68badc08cf96670f
|
4
|
+
data.tar.gz: 5f37b2668598ec438c4f34d6233696e7883dcb0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f13ba7f35eadc34d793c0282ccc437b71dc20e1e6ff97461cd58acaaea857a49725170ad350db36b812da4ce9f5128bc5ebf3f5ecefcb5f5afa3eb019f2b682
|
7
|
+
data.tar.gz: dd3475e7da5a8db5f796f8d1d21d5ccfb4bf55ec33723260dede2bec9b4316943cbb6919796d0c6dff648cc6c6f5421c35676a4b8b2b19c16b2a9fc9f266baea
|
data/CHANGELOG.md
CHANGED
@@ -22,3 +22,6 @@ Adds local db for development
|
|
22
22
|
# 0.1.0
|
23
23
|
Makes available the `rake jobs:reschedule` rake task
|
24
24
|
Adds a config to allow the scheduling for more than one instance of the same job
|
25
|
+
|
26
|
+
# 0.1.1
|
27
|
+
Allows jobs in config to be strings, symbols, or classes. If a string or symbol is provided, it will be resolved to a constant before scheduling the job.
|
data/lib/scheduled_job.rb
CHANGED
@@ -18,6 +18,8 @@ module ScheduledJob
|
|
18
18
|
def self.reschedule
|
19
19
|
config.jobs.each do |job, options|
|
20
20
|
options[:count].times do
|
21
|
+
job = job.to_s if job.is_a?(Symbol)
|
22
|
+
job = job.constantize if job.is_a?(String)
|
21
23
|
job.schedule_job
|
22
24
|
end
|
23
25
|
end if config.jobs
|
@@ -34,7 +36,7 @@ module ScheduledJob
|
|
34
36
|
|
35
37
|
def self.validate_job_hash(jobs)
|
36
38
|
jobs.each do |klass, options|
|
37
|
-
raise ConfigError.new("Jobs config found invalid class: #{klass}") unless klass.
|
39
|
+
raise ConfigError.new("Jobs config found invalid class: #{klass}") unless klass.is_a?(Class) || klass.is_a?(Symbol) || klass.is_a?(String)
|
38
40
|
raise ConfigError.new("Jobs config found invalid job count: #{options[:count]}") unless options[:count].to_i >= 0
|
39
41
|
end
|
40
42
|
end
|
@@ -39,35 +39,52 @@ describe ScheduledJob do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
describe 'job config' do
|
42
|
-
|
43
|
-
|
42
|
+
let(:job_class) { UnderTest }
|
43
|
+
let(:job_count) { 1 }
|
44
|
+
|
45
|
+
let(:configure) do
|
46
|
+
lambda do
|
44
47
|
ScheduledJob.configure do |config|
|
45
|
-
config.jobs = {
|
46
|
-
UnderTest => { count: 1 }
|
47
|
-
}
|
48
|
+
config.jobs = { job_class => { count: job_count } }
|
48
49
|
end
|
49
|
-
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'job class is a class' do
|
54
|
+
it 'considers the jobs hash valid' do
|
55
|
+
expect(configure).not_to raise_error
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'job class is a string' do
|
60
|
+
let(:job_class) { 'UnderTest' }
|
61
|
+
|
62
|
+
it 'considers the jobs hash valid' do
|
63
|
+
expect(configure).not_to raise_error
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'job class is a symbol' do
|
68
|
+
let(:job_class) { :UnderTest }
|
69
|
+
|
70
|
+
it 'considers the jobs hash valid' do
|
71
|
+
expect(configure).not_to raise_error
|
72
|
+
end
|
50
73
|
end
|
51
74
|
|
52
|
-
context '
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
'UnderTest' => { count: 1 }
|
58
|
-
}
|
59
|
-
end
|
60
|
-
}.to raise_error(ScheduledJob::ConfigError)
|
75
|
+
context 'job class is not a class, string, or symbol' do
|
76
|
+
let(:job_class) { 1 }
|
77
|
+
|
78
|
+
it 'raises ConfigError' do
|
79
|
+
expect(configure).to raise_error(ScheduledJob::ConfigError)
|
61
80
|
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'job count is not a non-negative integer' do
|
84
|
+
let(:job_count) { -1 }
|
62
85
|
|
63
|
-
it '
|
64
|
-
expect
|
65
|
-
ScheduledJob.configure do |config|
|
66
|
-
config.jobs = {
|
67
|
-
UnderTest => { count: -1 }
|
68
|
-
}
|
69
|
-
end
|
70
|
-
}.to raise_error(ScheduledJob::ConfigError)
|
86
|
+
it 'raises ConfigError' do
|
87
|
+
expect(configure).to raise_error(ScheduledJob::ConfigError)
|
71
88
|
end
|
72
89
|
end
|
73
90
|
end
|
@@ -77,7 +94,7 @@ describe ScheduledJob do
|
|
77
94
|
ScheduledJob.configure do |config|
|
78
95
|
config.jobs = {
|
79
96
|
UnderTest => { count: 1 },
|
80
|
-
Test
|
97
|
+
:Test => { count: 5 }
|
81
98
|
}
|
82
99
|
end
|
83
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scheduled_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CallumD
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: delayed_job
|