resque-scheduler 1.9.6 → 1.9.7
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.
- data/HISTORY.md +5 -0
- data/lib/resque/scheduler.rb +17 -9
- data/lib/resque_scheduler.rb +4 -2
- data/lib/resque_scheduler/server/views/scheduler.erb +4 -2
- data/lib/resque_scheduler/version.rb +1 -1
- data/resque-scheduler.gemspec +2 -2
- data/test/delayed_queue_test.rb +21 -0
- data/test/scheduler_test.rb +6 -1
- metadata +4 -4
data/HISTORY.md
CHANGED
data/lib/resque/scheduler.rb
CHANGED
|
@@ -60,13 +60,20 @@ module Resque
|
|
|
60
60
|
# to.
|
|
61
61
|
if config['rails_env'].nil? || rails_env_matches?(config)
|
|
62
62
|
log! "Scheduling #{name} "
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
interval_defined = false
|
|
64
|
+
interval_types = %w{cron every}
|
|
65
|
+
interval_types.each do |interval_type|
|
|
66
|
+
if !config[interval_type].nil? && config[interval_type].length > 0
|
|
67
|
+
rufus_scheduler.send(interval_type, config[interval_type]) do
|
|
68
|
+
log! "queueing #{config['class']} (#{name})"
|
|
69
|
+
enqueue_from_config(config)
|
|
70
|
+
end
|
|
71
|
+
interval_defined = true
|
|
72
|
+
break
|
|
67
73
|
end
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
end
|
|
75
|
+
unless interval_defined
|
|
76
|
+
log! "no #{interval_types.join(' / ')} found for #{config['class']} (#{name}) - skipping"
|
|
70
77
|
end
|
|
71
78
|
end
|
|
72
79
|
end
|
|
@@ -79,10 +86,11 @@ module Resque
|
|
|
79
86
|
end
|
|
80
87
|
|
|
81
88
|
# Handles queueing delayed items
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
# at_time - Time to start scheduling items (default: now).
|
|
90
|
+
def handle_delayed_items(at_time=nil)
|
|
91
|
+
timestamp = nil
|
|
84
92
|
begin
|
|
85
|
-
if timestamp = Resque.next_delayed_timestamp
|
|
93
|
+
if timestamp = Resque.next_delayed_timestamp(at_time)
|
|
86
94
|
enqueue_delayed_items_for_timestamp(timestamp)
|
|
87
95
|
end
|
|
88
96
|
# continue processing until there are no more ready timestamps
|
data/lib/resque_scheduler.rb
CHANGED
|
@@ -18,6 +18,8 @@ module ResqueScheduler
|
|
|
18
18
|
#
|
|
19
19
|
# :name can be anything and is used only to describe the scheduled job
|
|
20
20
|
# :cron can be any cron scheduling string :job can be any resque job class
|
|
21
|
+
# :every can be used in lieu of :cron. see rufus-scheduler's 'every' usage for
|
|
22
|
+
# valid syntax. If :cron is present it will take precedence over :every.
|
|
21
23
|
# :class must be a resque worker class
|
|
22
24
|
# :args can be any yaml which will be converted to a ruby literal and passed
|
|
23
25
|
# in a params. (optional)
|
|
@@ -89,8 +91,8 @@ module ResqueScheduler
|
|
|
89
91
|
|
|
90
92
|
# Returns the next delayed queue timestamp
|
|
91
93
|
# (don't call directly)
|
|
92
|
-
def next_delayed_timestamp
|
|
93
|
-
items = redis.zrangebyscore :delayed_queue_schedule, '-inf', Time.now.to_i, :limit => [0, 1]
|
|
94
|
+
def next_delayed_timestamp(at_time=nil)
|
|
95
|
+
items = redis.zrangebyscore :delayed_queue_schedule, '-inf', (at_time || Time.now).to_i, :limit => [0, 1]
|
|
94
96
|
timestamp = items.nil? ? nil : Array(items).first
|
|
95
97
|
timestamp.to_i unless timestamp.nil?
|
|
96
98
|
end
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<th></th>
|
|
11
11
|
<th>Name</th>
|
|
12
12
|
<th>Description</th>
|
|
13
|
-
<th>
|
|
13
|
+
<th>Interval</th>
|
|
14
14
|
<th>Class</th>
|
|
15
15
|
<th>Queue</th>
|
|
16
16
|
<th>Arguments</th>
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
</td>
|
|
27
27
|
<td><%= h name %></td>
|
|
28
28
|
<td><%= h config['description'] %></td>
|
|
29
|
-
<td style="white-space:nowrap"><%=
|
|
29
|
+
<td style="white-space:nowrap"><%= (config['cron'].nil? && !config['every'].nil?) ?
|
|
30
|
+
h('every: ' + config['every']) :
|
|
31
|
+
h('cron: ' + config['cron']) %></td>
|
|
30
32
|
<td><%= h config['class'] %></td>
|
|
31
33
|
<td><%= h config['queue'] || queue_from_class_name(config['class']) %></td>
|
|
32
34
|
<td><%= h config['args'].inspect %></td>
|
data/resque-scheduler.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{resque-scheduler}
|
|
8
|
-
s.version = "1.9.
|
|
8
|
+
s.version = "1.9.7"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Ben VandenBos"]
|
|
12
|
-
s.date = %q{2010-10
|
|
12
|
+
s.date = %q{2010-11-10}
|
|
13
13
|
s.description = %q{Light weight job scheduling on top of Resque.
|
|
14
14
|
Adds methods enqueue_at/enqueue_in to schedule jobs in the future.
|
|
15
15
|
Also supports queueing jobs on a fixed, cron-like schedule.}
|
data/test/delayed_queue_test.rb
CHANGED
|
@@ -50,6 +50,16 @@ class Resque::DelayedQueueTest < Test::Unit::TestCase
|
|
|
50
50
|
assert_nil(read_timestamp, "No timestamps should be ready for queueing")
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def test_something_in_the_future_comes_out_if_you_want_it_to
|
|
54
|
+
timestamp = Time.now + 600 # 10 minutes from now
|
|
55
|
+
|
|
56
|
+
Resque.enqueue_at(timestamp, SomeIvarJob, "path")
|
|
57
|
+
|
|
58
|
+
read_timestamp = Resque.next_delayed_timestamp(timestamp)
|
|
59
|
+
|
|
60
|
+
assert_equal(timestamp.to_i, read_timestamp, "The timestamp we pull out of redis should match the one we put in")
|
|
61
|
+
end
|
|
62
|
+
|
|
53
63
|
def test_enqueue_at_and_enqueue_in_are_equivelent
|
|
54
64
|
timestamp = Time.now + 60
|
|
55
65
|
|
|
@@ -120,6 +130,17 @@ class Resque::DelayedQueueTest < Test::Unit::TestCase
|
|
|
120
130
|
Resque.expects(:queue_from_class).never # Should NOT need to load the class
|
|
121
131
|
Resque::Scheduler.handle_delayed_items
|
|
122
132
|
end
|
|
133
|
+
|
|
134
|
+
def test_handle_delayed_items_with_items_in_the_future
|
|
135
|
+
t = Time.now + 60 # in the future
|
|
136
|
+
Resque.enqueue_at(t, SomeIvarJob)
|
|
137
|
+
Resque.enqueue_at(t, SomeIvarJob)
|
|
138
|
+
|
|
139
|
+
# 2 SomeIvarJob jobs should be created in the "ivar" queue
|
|
140
|
+
Resque::Job.expects(:create).twice.with('ivar', 'SomeIvarJob', nil)
|
|
141
|
+
Resque.expects(:queue_from_class).never # Should NOT need to load the class
|
|
142
|
+
Resque::Scheduler.handle_delayed_items(t)
|
|
143
|
+
end
|
|
123
144
|
|
|
124
145
|
def test_enqueue_delayed_items_for_timestamp
|
|
125
146
|
t = Time.now + 60
|
data/test/scheduler_test.rb
CHANGED
|
@@ -14,7 +14,12 @@ class Resque::SchedulerTest < Test::Unit::TestCase
|
|
|
14
14
|
Resque::Job.stubs(:create).once.returns(true).with('joes_queue', 'BigJoesJob', '/tmp')
|
|
15
15
|
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'BigJoesJob', 'args' => "/tmp", 'queue' => 'joes_queue')
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
def test_enqueue_from_config_with_every_syntax
|
|
19
|
+
Resque::Job.stubs(:create).once.returns(true).with('james_queue', 'JamesJob', '/tmp')
|
|
20
|
+
Resque::Scheduler.enqueue_from_config('every' => '1m', 'class' => 'JamesJob', 'args' => '/tmp', 'queue' => 'james_queue')
|
|
21
|
+
end
|
|
22
|
+
|
|
18
23
|
def test_enqueue_from_config_puts_stuff_in_the_resque_queue
|
|
19
24
|
Resque::Job.stubs(:create).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
|
|
20
25
|
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: resque-scheduler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 61
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 9
|
|
9
|
-
-
|
|
10
|
-
version: 1.9.
|
|
9
|
+
- 7
|
|
10
|
+
version: 1.9.7
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Ben VandenBos
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-10
|
|
18
|
+
date: 2010-11-10 00:00:00 -08:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|