delayed_cron 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8d527eed69dcd460b43262ae37aaf0efbb67034
4
- data.tar.gz: 00b2a965f05f28325034d6bc32fc5dacd842bb42
3
+ metadata.gz: c34b1f4a8ad81433f720139d2ab42fc434e57c26
4
+ data.tar.gz: 35e783bd8f72dfa67fcf02ec651a1b148738dab2
5
5
  SHA512:
6
- metadata.gz: 169d92d5916d779d255da607ec0a7e0bce301a0429a5351643648f546287b41e014a0e670132f98e46fc30c0364d66812d91e6b560d58516991621957819c27b
7
- data.tar.gz: 350cbc62f24790b3ef75114746597346a22fa23432f11b076eb390c353f3b4eba79ddbdd1c6fe5403188144661d2f10ec172d4fce96992dcd3bf706cac0b62bb
6
+ metadata.gz: bde551335a82a185dbcdebd8631d9c57b6528f47302c3dd90bc10240e2794d7c508558dd4ce5788bd79303fc5177816455a175c4e0fd3bfad3053113662758ac
7
+ data.tar.gz: 3225ce660f0a19b7c20a3a76e93544a22e598882052d2bf98014f4a88d984bed7793b36f36b6fe5cee22f0753851a82c6e3d72352245f19e09b5f58c11775c4f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- delayed_cron (0.2.3)
4
+ delayed_cron (0.2.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -75,7 +75,7 @@ GEM
75
75
  activesupport (= 4.1.2)
76
76
  rake (>= 0.8.7)
77
77
  thor (>= 0.18.1, < 2.0)
78
- rake (10.3.2)
78
+ rake (10.4.2)
79
79
  redis (3.1.0)
80
80
  redis-namespace (1.5.0)
81
81
  redis (~> 3.0, >= 3.0.4)
data/README.md CHANGED
@@ -7,10 +7,10 @@ run cron jobs with sidekiq, delayed_job, resque, or sucker_punch
7
7
  ### DEPENDENCIES:
8
8
  - background process handler: sidekiq, delayed_job, resque, or sucker_punch
9
9
 
10
- ### INSTALL
10
+ ### INSTALL
11
11
 
12
12
  ```ruby
13
- gem "delayed_cron", "0.2.2"
13
+ gem "delayed_cron", "0.2.4"
14
14
  ```
15
15
 
16
16
  ### USE IN MODEL
@@ -20,7 +20,7 @@ class Product < ActiveRecord::Base
20
20
  ...
21
21
 
22
22
  # Define in Model
23
- # * this is an alternative to the methods array in config
23
+ # * this is an alternative to the cron_jobs array in config
24
24
  #
25
25
  # OPTIONS: *optional
26
26
  # - interval - override default_inteveral from setup
@@ -44,7 +44,10 @@ DelayedCron.setup do |config|
44
44
  config.default_interval = 10.minutes
45
45
 
46
46
  # array of methods to run at the above configured interval
47
- config.cron_jobs = [ "SomeClass.expensive_task", "AnotherClass.other_expensive_task" ]
47
+ config.cron_jobs = [
48
+ "SomeClass.expensive_task", # will run at default interval
49
+ { job: "AnotherClass.other_expensive_task", interval: 1.hour } # override default
50
+ ]
48
51
 
49
52
  end
50
53
  ```
@@ -1,3 +1,3 @@
1
1
  module DelayedCron
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/lib/delayed_cron.rb CHANGED
@@ -15,9 +15,13 @@ module DelayedCron
15
15
  def define_cron_jobs
16
16
  return false unless cron_jobs.present?
17
17
  cron_jobs.each do |job|
18
+ obj = job
19
+ job_is_hash = job.is_a?(Hash)
20
+ job = job_is_hash ? obj[:job] : job
21
+ interval = job_is_hash ? obj[:interval] : default_interval
18
22
  klass, name = job.split(".")
19
- # TODO: raise error if interval is not set from config
20
- DelayedCron.schedule(klass, name, { interval: default_interval })
23
+ # TODO: raise error if interval is not set
24
+ DelayedCron.schedule(klass, name, { interval: interval })
21
25
  end
22
26
  end
23
27
 
@@ -55,10 +59,10 @@ module DelayedCron
55
59
  end
56
60
 
57
61
  def parse_time(time_array)
58
- {
59
- hours: time_array[0],
60
- mins: time_array[1],
61
- secs: time_array[2] || 0,
62
+ {
63
+ hours: time_array[0],
64
+ mins: time_array[1],
65
+ secs: time_array[2] || 0,
62
66
  tz: time_array[3] || Time.now.strftime("%z").to_i
63
67
  }
64
68
  end
@@ -5,7 +5,7 @@ require 'rspec-sidekiq'
5
5
  describe DelayedCron do
6
6
 
7
7
  describe ".setup" do
8
-
8
+
9
9
  it "yields self" do
10
10
  DelayedCron.setup do |config|
11
11
  DelayedCron.should == config
@@ -31,11 +31,22 @@ describe DelayedCron do
31
31
  DelayedCron.cron_jobs.should be_an(Array)
32
32
  end
33
33
 
34
+ let(:options) do
35
+ {
36
+ default_interval: 1.hour,
37
+ cron_jobs: [
38
+ "SomeClass.long_method",
39
+ { job: "AnotherClass.expensive_method", interval: 1.hour }
40
+ ]
41
+ }
42
+ end
43
+
34
44
  it "sends cron_jobs to schedule" do
35
- options = { default_interval: 1.hour, cron_jobs: ["SomeClass.long_method", "AnotherClass.expensive_method"] }
36
45
  options[:cron_jobs].each do |cron_job|
37
- klass, method_name = cron_job.split(".")
38
- DelayedCron.should_receive(:schedule).with(klass, method_name, { interval: options[:default_interval] })
46
+ job_is_hash = cron_job.is_a?(Hash)
47
+ klass, method_name = job_is_hash ? cron_job[:job].split(".") : cron_job.split(".")
48
+ interval = job_is_hash ? cron_job[:interval] : options[:default_interval]
49
+ DelayedCron.should_receive(:schedule).with(klass, method_name, { interval: interval })
39
50
  end
40
51
  setup(options)
41
52
  end
@@ -120,4 +131,4 @@ describe DelayedCron do
120
131
  end
121
132
  end
122
133
 
123
- end
134
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Grubbs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: delayed_job
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.0.6
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Run your cron jobs with sidekiq, delayed_job, resque, or sucker_punch.