resque-scheduler 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +5 -1
- data/lib/resque/scheduler.rb +16 -11
- data/lib/resque_scheduler/server.rb +6 -0
- data/lib/resque_scheduler/server/views/delayed.erb +7 -0
- data/lib/resque_scheduler/version.rb +1 -1
- data/resque-scheduler.gemspec +2 -2
- data/test/delayed_queue_test.rb +16 -0
- metadata +2 -2
data/HISTORY.md
CHANGED
data/lib/resque/scheduler.rb
CHANGED
@@ -77,21 +77,26 @@ module Resque
|
|
77
77
|
item = nil
|
78
78
|
begin
|
79
79
|
if timestamp = Resque.next_delayed_timestamp
|
80
|
-
|
81
|
-
begin
|
82
|
-
handle_shutdown do
|
83
|
-
if item = Resque.next_item_for_timestamp(timestamp)
|
84
|
-
log "queuing #{item['class']} [delayed]"
|
85
|
-
queue = item['queue'] || Resque.queue_from_class(constantize(item['class']))
|
86
|
-
Job.create(queue, item['class'], *item['args'])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
# continue processing until there are no more ready items in this timestamp
|
90
|
-
end while !item.nil?
|
80
|
+
enqueue_delayed_items_for_timestamp(timestamp)
|
91
81
|
end
|
92
82
|
# continue processing until there are no more ready timestamps
|
93
83
|
end while !timestamp.nil?
|
94
84
|
end
|
85
|
+
|
86
|
+
# Enqueues all delayed jobs for a timestamp
|
87
|
+
def enqueue_delayed_items_for_timestamp(timestamp)
|
88
|
+
item = nil
|
89
|
+
begin
|
90
|
+
handle_shutdown do
|
91
|
+
if item = Resque.next_item_for_timestamp(timestamp)
|
92
|
+
log "queuing #{item['class']} [delayed]"
|
93
|
+
queue = item['queue'] || Resque.queue_from_class(constantize(item['class']))
|
94
|
+
Job.create(queue, item['class'], *item['args'])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
# continue processing until there are no more ready items in this timestamp
|
98
|
+
end while !item.nil?
|
99
|
+
end
|
95
100
|
|
96
101
|
def handle_shutdown
|
97
102
|
exit if @shutdown
|
@@ -38,6 +38,12 @@ module ResqueScheduler
|
|
38
38
|
# Is there a better way to specify alternate template locations with sinatra?
|
39
39
|
erb File.read(File.join(File.dirname(__FILE__), 'server/views/delayed_timestamp.erb'))
|
40
40
|
end
|
41
|
+
|
42
|
+
post "/delayed/queue_now" do
|
43
|
+
timestamp = params['timestamp']
|
44
|
+
Resque::Scheduler.enqueue_delayed_items_for_timestamp(timestamp.to_i) if timestamp.present?
|
45
|
+
redirect url("/overview")
|
46
|
+
end
|
41
47
|
|
42
48
|
end
|
43
49
|
|
@@ -10,6 +10,7 @@
|
|
10
10
|
|
11
11
|
<table>
|
12
12
|
<tr>
|
13
|
+
<th></th>
|
13
14
|
<th>Timestamp</th>
|
14
15
|
<th>Job count</th>
|
15
16
|
<th>Class</th>
|
@@ -17,6 +18,12 @@
|
|
17
18
|
</tr>
|
18
19
|
<% resque.delayed_queue_peek(start, start+20).each do |timestamp| %>
|
19
20
|
<tr>
|
21
|
+
<td>
|
22
|
+
<form action="<%= url "/delayed/queue_now" %>" method="post">
|
23
|
+
<input type="hidden" name="timestamp" value="<%= timestamp.to_i %>">
|
24
|
+
<input type="submit" value="Queue now">
|
25
|
+
</form>
|
26
|
+
</td>
|
20
27
|
<td><a href="<%= url "delayed/#{timestamp}" %>"><%= format_time(Time.at(timestamp)) %></a></td>
|
21
28
|
<td><%= delayed_timestamp_size = resque.delayed_timestamp_size(timestamp) %></td>
|
22
29
|
<% job = resque.delayed_timestamp_peek(timestamp, 0, 1).first %>
|
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.8.
|
8
|
+
s.version = "1.8.2"
|
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-
|
12
|
+
s.date = %q{2010-06-04}
|
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
@@ -116,6 +116,22 @@ class Resque::DelayedQueueTest < Test::Unit::TestCase
|
|
116
116
|
Resque.expects(:queue_from_class).never # Should NOT need to load the class
|
117
117
|
Resque::Scheduler.handle_delayed_items
|
118
118
|
end
|
119
|
+
|
120
|
+
def test_enqueue_delayed_items_for_timestamp
|
121
|
+
t = Time.now + 60
|
122
|
+
|
123
|
+
Resque.enqueue_at(t, SomeIvarJob)
|
124
|
+
Resque.enqueue_at(t, SomeIvarJob)
|
125
|
+
|
126
|
+
# 2 SomeIvarJob jobs should be created in the "ivar" queue
|
127
|
+
Resque::Job.expects(:create).twice.with('ivar', 'SomeIvarJob', nil)
|
128
|
+
Resque.expects(:queue_from_class).never # Should NOT need to load the class
|
129
|
+
|
130
|
+
Resque::Scheduler.enqueue_delayed_items_for_timestamp(t)
|
131
|
+
|
132
|
+
# delayed queue for timestamp should be empty
|
133
|
+
assert_equal(0, Resque.delayed_timestamp_peek(t, 0, 3).length)
|
134
|
+
end
|
119
135
|
|
120
136
|
def test_works_with_out_specifying_queue__upgrade_case
|
121
137
|
t = Time.now - 60
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben VandenBos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-06-04 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|