scheduled_job 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8992a23a08c1f37078a3f9a41e3e79807ccdcd86
4
- data.tar.gz: f0fa25cd3bd9e27fb4b827a76e0c581f558ea451
3
+ metadata.gz: c9ef9b5bd8566235b6a1befa68badc08cf96670f
4
+ data.tar.gz: 5f37b2668598ec438c4f34d6233696e7883dcb0f
5
5
  SHA512:
6
- metadata.gz: 3bdada7d253e3124f3ef9ac9e303015a80082a8e3ef3ba61a2f34a30c9b6de9ee3e9ad238484e2d280b4b1bad61efc07144611f56f942b18d80c53d481a98b4e
7
- data.tar.gz: b7da6a1ed79dab91050c9bec04668117b37ec2688f7726aeca25b99b8f5f76590ec2269b454bc68b218b0d24e02a831876aaca816804dd62b75d1aff379e2ea4
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.
@@ -1,3 +1,3 @@
1
1
  module ScheduledJob
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.class == Class
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
- it 'takes a jobs hash config' do
43
- expect {
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
- }.not_to raise_error
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 'validates the job hash' do
53
- it 'detects an bad job class' do
54
- expect {
55
- ScheduledJob.configure do |config|
56
- config.jobs = {
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 'detects a bad job count' do
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 => { count: 5 }
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.0
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-02-16 00:00:00.000000000 Z
14
+ date: 2015-04-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: delayed_job