delayed_job_recurring 0.1 → 0.2

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: a415c64ebb7f90d1e582264d12150ea51ca9035e
4
- data.tar.gz: 018743cb2951f1b615796103e7a16b66de915ca5
3
+ metadata.gz: 611fadd7b0841b22954dbfb4aeb07b4a1e4374df
4
+ data.tar.gz: 876ea72b2951452c45547d8241cb1c97ee3c2c56
5
5
  SHA512:
6
- metadata.gz: 3a741233a41bdd26c970abf7e1eb9fc96b8dee93f0990d0925fa6d67ad918bc1537fc52219869156b5aaccec96203b6c7cdeceb3bc0db7ec4817760e0cc56a6a
7
- data.tar.gz: d5ebc8c0ae9e1d2fc6b0503d432ee72b72e41273e1c268c9343cb7ca9a1122a88370dbba65fe9ede822831a013d649817bde53a1a575a681b35ee8ccc159c084
6
+ metadata.gz: 03330925d4bb8a28d0926a43a78d73c07531f3e7bafc9bb1557a8722566c8892e5f6ec285dd3abdaee1102512a446d3434800c3e71061a2da78fc7173e056e4e
7
+ data.tar.gz: de4ffb37d1a04c881da94c96309167202ced75dd928df0c0a3ca8eefade2b5f91f63da20b6794870d1946d1cf10b21487d2725fd7bc414a7ef6838a3aeb790ae
data/README.md CHANGED
@@ -4,13 +4,15 @@ Extends delayed\_job to support recurring jobs.
4
4
 
5
5
  ## Usage
6
6
 
7
- In your Gemfile:
7
+ Add it to your Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'delayed_job_recurring'
11
11
  ```
12
12
 
13
- Then define a task class:
13
+ Then define a task class. We like the concept of
14
+ [interactors](http://eng.joingrouper.com/blog/2014/03/03/rails-the-missing-parts-interactors),
15
+ so we put our task classes in `app/interactors`. You could also put them in `lib` or even `app/models`.
14
16
 
15
17
  ```ruby
16
18
  class MyTask
@@ -41,6 +41,7 @@ module Delayed
41
41
  def next_run_time
42
42
  times = @schedule_options[:run_at]
43
43
  times = [times] unless times.is_a? Array
44
+ times = times.map{|time| parse_time(time, @schedule_options[:timezone])}
44
45
  times = times.map{|time| time.in_time_zone @schedule_options[:timezone]} if @schedule_options[:timezone]
45
46
 
46
47
  interval = deserialize_duration(@schedule_options[:run_interval])
@@ -76,16 +77,34 @@ module Delayed
76
77
  end
77
78
  end
78
79
 
80
+ def parse_time(time, timezone)
81
+ case time
82
+ when String
83
+ get_timezone(timezone).parse(time)
84
+ else
85
+ time
86
+ end
87
+ end
88
+
89
+ def get_timezone(zone)
90
+ if zone
91
+ ActiveSupport::TimeZone.new(zone)
92
+ else
93
+ Time.zone
94
+ end
95
+ end
96
+
79
97
  def next_future_time(times)
80
98
  times.select{|time| time > Time.now}.min
81
99
  end
82
100
 
83
101
  module ClassMethods
84
- def run_at(time = nil)
85
- if time.nil?
102
+ def run_at(*times)
103
+ if times.length == 0
86
104
  @run_at || run_every.from_now
87
105
  else
88
- @run_at = time
106
+ @run_at ||= []
107
+ @run_at.concat times
89
108
  end
90
109
  end
91
110
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_recurring
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Novak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails