resque-scheduler 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of resque-scheduler might be problematic. Click here for more details.
- data/.rubocop.yml +120 -0
- data/.travis.yml +10 -0
- data/AUTHORS.md +59 -0
- data/CONTRIBUTING.md +6 -0
- data/Gemfile +3 -7
- data/HISTORY.md +41 -6
- data/LICENSE +3 -1
- data/{README.markdown → README.md} +171 -103
- data/Rakefile +22 -9
- data/lib/resque/scheduler.rb +22 -9
- data/lib/resque_scheduler.rb +49 -13
- data/lib/resque_scheduler/logger_builder.rb +51 -0
- data/lib/resque_scheduler/server/views/delayed.erb +2 -1
- data/lib/resque_scheduler/server/views/scheduler.erb +3 -2
- data/lib/resque_scheduler/tasks.rb +9 -3
- data/lib/resque_scheduler/version.rb +1 -1
- data/resque-scheduler.gemspec +24 -19
- data/script/migrate_to_timestamps_set.rb +14 -0
- data/test/delayed_queue_test.rb +50 -15
- data/test/resque-web_test.rb +3 -3
- data/test/scheduler_args_test.rb +1 -1
- data/test/scheduler_setup_test.rb +59 -0
- data/test/scheduler_test.rb +11 -0
- data/test/test_helper.rb +9 -2
- metadata +102 -9
data/.rubocop.yml
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`.
|
2
|
+
# The point is for the user to remove these configuration records
|
3
|
+
# one by one as the offences are removed from the code base.
|
4
|
+
|
5
|
+
AccessControl:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
AlignParameters:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
AssignmentInCondition:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
CaseEquality:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
ClassVars:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
CollectionMethods:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
ColonMethodCall:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
CommentAnnotation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Documentation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
EmptyLines:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Encoding:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
FavorUnlessOverNegatedIf:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
FavorUntilOverNegatedWhile:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
HandleExceptions:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
HashSyntax:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
IfUnlessModifier:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
LineLength:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Loop:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
MethodCallParentheses:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
MethodLength:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
ModuleFunction:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
NumericLiterals:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
ParenthesesAroundCondition:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
PerlBackrefs:
|
75
|
+
Enabled: false
|
76
|
+
|
77
|
+
RedundantBegin:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
RescueException:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
RescueModifier:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
SingleLineMethods:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
SpaceAfterComma:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
SpaceAroundBlockBraces:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
SpaceAroundEqualsInParameterDefault:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
SpaceAroundOperators:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
SpaceInsideHashLiteralBraces:
|
102
|
+
Enabled: false
|
103
|
+
|
104
|
+
SpecialGlobalVars:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
StringLiterals:
|
108
|
+
Enabled: false
|
109
|
+
|
110
|
+
TrailingBlankLines:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
TrailingWhitespace:
|
114
|
+
Enabled: false
|
115
|
+
|
116
|
+
TrivialAccessors:
|
117
|
+
Enabled: false
|
118
|
+
|
119
|
+
UselessAssignment:
|
120
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/AUTHORS.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Resque Scheduler authors
|
2
|
+
========================
|
3
|
+
|
4
|
+
- Aaron Suggs
|
5
|
+
- Alexander Simonov
|
6
|
+
- Ben VandenBos
|
7
|
+
- Bernerd Schaefer
|
8
|
+
- Bogdan Gusiev
|
9
|
+
- Brian Landau
|
10
|
+
- Brian P O'Rourke
|
11
|
+
- Carlos Antonio da Silva
|
12
|
+
- Chris Kampmeier
|
13
|
+
- DJ Hartman
|
14
|
+
- Damon P. Cortesi
|
15
|
+
- Dan Buch
|
16
|
+
- Dave Grijalva
|
17
|
+
- David Backeus
|
18
|
+
- David Balatero
|
19
|
+
- David Doan
|
20
|
+
- David Yang
|
21
|
+
- Denis Yagofarov
|
22
|
+
- Evan Tahler
|
23
|
+
- Giovanni Cappellotto
|
24
|
+
- Henrik Nyh
|
25
|
+
- James Le Cuirot
|
26
|
+
- John Crepezzi
|
27
|
+
- John Griffin
|
28
|
+
- Jon Larkowski and Les Hill
|
29
|
+
- Jonathan Hyman
|
30
|
+
- Jonathan Owens
|
31
|
+
- Joshua Szmajda
|
32
|
+
- Justin Weiss
|
33
|
+
- Les Hill
|
34
|
+
- Manuel Meurer
|
35
|
+
- Matt Aimonetti
|
36
|
+
- Matt Simpson
|
37
|
+
- Matteo Centenaro
|
38
|
+
- Michael Lovitt
|
39
|
+
- Michael Nikitochkin
|
40
|
+
- Michael Rykov
|
41
|
+
- Nickolas Means
|
42
|
+
- Olek Janiszewski
|
43
|
+
- Olivier Brisse
|
44
|
+
- Petteri Räty
|
45
|
+
- Phil Cohen
|
46
|
+
- Russell Branca
|
47
|
+
- Ryan Biesemeyer
|
48
|
+
- Ryan Carver
|
49
|
+
- Sebastian Kippe
|
50
|
+
- Tim Liner
|
51
|
+
- Tony Lewis
|
52
|
+
- V Sreekanth
|
53
|
+
- andreas
|
54
|
+
- bbauer
|
55
|
+
- fallwith
|
56
|
+
- gravis
|
57
|
+
- hpoydar
|
58
|
+
- malomalo
|
59
|
+
- sawanoboly
|
data/CONTRIBUTING.md
ADDED
data/Gemfile
CHANGED
data/HISTORY.md
CHANGED
@@ -1,4 +1,32 @@
|
|
1
|
-
## 2.
|
1
|
+
## 2.1.0 (2013-09-20)
|
2
|
+
|
3
|
+
* Locking to resque < 1.25.0 (for now)
|
4
|
+
* Ensuring `Resque.schedule=` sets rather than appends
|
5
|
+
* Process daemonization fixes including stdio redirection and redis client
|
6
|
+
reconnection
|
7
|
+
* Add `#scheduled_at` which returns an array of timestamps at which the
|
8
|
+
specified job is scheduled
|
9
|
+
* Syncing stdout/stderr
|
10
|
+
* Add `#enqueue_delayed` for enqueueing specific delayed jobs immediately
|
11
|
+
* Show server local time in resque-web
|
12
|
+
* Enqueue immediately if job is being enqueued in the past
|
13
|
+
* Using a logger instead of `#puts`, configurable via `LOGFILE`, `VERBOSE`, and
|
14
|
+
`MUTE` environmental variables, as well as being settable via
|
15
|
+
`Resque::Scheduler#logger`
|
16
|
+
* Fixing scheduler template when arrays are passed to rufus-scheduler
|
17
|
+
* Add support for configuring `Resque::Scheduler.poll_sleep_amount` via the
|
18
|
+
`INTERVAL` environmental variable.
|
19
|
+
* Fixed shutdown in ruby 2.0.0
|
20
|
+
* Removed dependency on `Resque::Helpers`
|
21
|
+
|
22
|
+
## 2.0.1 (2013-03-20)
|
23
|
+
|
24
|
+
* Adding locking to support master failover
|
25
|
+
* Allow custom job classes to be used in `Resque.enqueue_at`
|
26
|
+
* More efficient `#remove_delayed` implementation
|
27
|
+
* Allowing `#enqueue_at` to call `#scheduled` when `Resque.inline` is `true`
|
28
|
+
|
29
|
+
## 2.0.0 (2012-05-04)
|
2
30
|
|
3
31
|
* Add support for Resque.inline configuration (carlosantoniodasilva)
|
4
32
|
* Fixing possible job loss race condition around deleting delayed queues
|
@@ -11,14 +39,14 @@
|
|
11
39
|
### 2.0.0.f (2011-11-03)
|
12
40
|
|
13
41
|
* TODO: address race condition with delayed jobs (using redis transactions)
|
14
|
-
* Support ENV['BACKGROUND'] flag for daemonizing (bernerdschaefer)
|
15
|
-
* Added support for before_schedule and after_schedule hooks (yaauie)
|
16
|
-
* Added remove_delayed_job_from_timestamp to remove delayed jobs from
|
42
|
+
* Support `ENV['BACKGROUND']` flag for daemonizing (bernerdschaefer)
|
43
|
+
* Added support for `before_schedule` and `after_schedule` hooks (yaauie)
|
44
|
+
* Added `remove_delayed_job_from_timestamp` to remove delayed jobs from
|
17
45
|
a given timestamp.
|
18
46
|
|
19
47
|
### 2.0.0.e (2011-09-16)
|
20
48
|
|
21
|
-
* Adding enqueue_at_with_queue
|
49
|
+
* Adding `enqueue_at_with_queue`/`enqueue_in_with_queue` support (niralisse)
|
22
50
|
* Adding `Resque::Scheduler.poll_sleep_amount` to allow for configuring
|
23
51
|
the sleep time b/w delayed queue polls.
|
24
52
|
* Add a "Clear Delayed Jobs" button to the Delayed Jobs page (john-griffin)
|
@@ -41,6 +69,13 @@
|
|
41
69
|
* Dynamic schedule support (brianjlandau, davidyang)
|
42
70
|
* Now depends on redis >=1.3
|
43
71
|
|
72
|
+
## 1.9.10 (2013-09-19)
|
73
|
+
|
74
|
+
* Backported `#enqueue_at_with_queue`
|
75
|
+
* Locking to resque < 1.25.0
|
76
|
+
* Mocha setup compatibility
|
77
|
+
* Ruby 1.8 compatibility in scheduler tab when schedule keys are symbols
|
78
|
+
|
44
79
|
## 1.9.9 (2011-03-29)
|
45
80
|
|
46
81
|
* Compatibility with resque 1.15.0
|
@@ -53,7 +88,7 @@
|
|
53
88
|
## 1.9.7 (2010-11-09)
|
54
89
|
|
55
90
|
* Support for rufus-scheduler "every" syntax (fallwith)
|
56
|
-
* Ability to pass a Time to handle_delayed_items for testing/staging (rcarver)
|
91
|
+
* Ability to pass a Time to `handle_delayed_items` for testing/staging (rcarver)
|
57
92
|
|
58
93
|
## 1.9.6 (2010-10-08)
|
59
94
|
|
data/LICENSE
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
resque-scheduler
|
2
2
|
================
|
3
3
|
|
4
|
+
[![Dependency Status](https://gemnasium.com/resque/resque-scheduler.png)](https://gemnasium.com/resque/resque-scheduler)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/resque-scheduler.png)](http://badge.fury.io/rb/resque-scheduler)
|
6
|
+
[![Build Status](https://travis-ci.org/resque/resque-scheduler.png?branch=master)](https://travis-ci.org/resque/resque-scheduler)
|
7
|
+
|
4
8
|
### Description
|
5
9
|
|
6
|
-
Resque-scheduler is an extension to [Resque](http://github.com/
|
10
|
+
Resque-scheduler is an extension to [Resque](http://github.com/resque/resque)
|
7
11
|
that adds support for queueing items in the future.
|
8
12
|
|
9
13
|
This table explains the version requirements for redis
|
@@ -21,9 +25,11 @@ Scheduled jobs are like cron jobs, recurring on a regular basis. Delayed
|
|
21
25
|
jobs are resque jobs that you want to run at some point in the future.
|
22
26
|
The syntax is pretty explanatory:
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
```ruby
|
29
|
+
Resque.enqueue_in(5.days, SendFollowupEmail) # run a job in 5 days
|
30
|
+
# or
|
31
|
+
Resque.enqueue_at(5.days.from_now, SomeJob) # run SomeJob at a specific time
|
32
|
+
```
|
27
33
|
|
28
34
|
### Documentation
|
29
35
|
|
@@ -38,11 +44,15 @@ To install:
|
|
38
44
|
|
39
45
|
If you use a Gemfile, you may want to specify the `:require` explicitly:
|
40
46
|
|
41
|
-
|
47
|
+
```ruby
|
48
|
+
gem 'resque-scheduler', :require => 'resque_scheduler'
|
49
|
+
```
|
42
50
|
|
43
51
|
Adding the resque:scheduler rake task:
|
44
52
|
|
45
|
-
|
53
|
+
```ruby
|
54
|
+
require 'resque_scheduler/tasks'
|
55
|
+
```
|
46
56
|
|
47
57
|
There are three things `resque-scheduler` needs to know about in order to do
|
48
58
|
it's jobs: the schedule, where redis lives, and which queues to use. The
|
@@ -52,40 +62,41 @@ probably already have this task, lets just put our configuration there.
|
|
52
62
|
`resque-scheduler` pretty much needs to know everything `resque` needs
|
53
63
|
to know.
|
54
64
|
|
65
|
+
```ruby
|
66
|
+
# Resque tasks
|
67
|
+
require 'resque/tasks'
|
68
|
+
require 'resque_scheduler/tasks'
|
55
69
|
|
56
|
-
|
57
|
-
|
58
|
-
require '
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
require 'jobs'
|
87
|
-
end
|
88
|
-
end
|
70
|
+
namespace :resque do
|
71
|
+
task :setup do
|
72
|
+
require 'resque'
|
73
|
+
require 'resque_scheduler'
|
74
|
+
require 'resque/scheduler'
|
75
|
+
|
76
|
+
# you probably already have this somewhere
|
77
|
+
Resque.redis = 'localhost:6379'
|
78
|
+
|
79
|
+
# If you want to be able to dynamically change the schedule,
|
80
|
+
# uncomment this line. A dynamic schedule can be updated via the
|
81
|
+
# Resque::Scheduler.set_schedule (and remove_schedule) methods.
|
82
|
+
# When dynamic is set to true, the scheduler process looks for
|
83
|
+
# schedule changes and applies them on the fly.
|
84
|
+
# Note: This feature is only available in >=2.0.0.
|
85
|
+
#Resque::Scheduler.dynamic = true
|
86
|
+
|
87
|
+
# The schedule doesn't need to be stored in a YAML, it just needs to
|
88
|
+
# be a hash. YAML is usually the easiest.
|
89
|
+
Resque.schedule = YAML.load_file('your_resque_schedule.yml')
|
90
|
+
|
91
|
+
# If your schedule already has +queue+ set for each job, you don't
|
92
|
+
# need to require your jobs. This can be an advantage since it's
|
93
|
+
# less code that resque-scheduler needs to know about. But in a small
|
94
|
+
# project, it's usually easier to just include you job classes here.
|
95
|
+
# So, something like this:
|
96
|
+
require 'jobs'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
89
100
|
|
90
101
|
The scheduler process is just a rake task which is responsible for both
|
91
102
|
queueing items from the schedule and polling the delayed queue for items
|
@@ -105,7 +116,9 @@ supersedes `VERBOSE`.
|
|
105
116
|
Delayed jobs are one-off jobs that you want to be put into a queue at some point
|
106
117
|
in the future. The classic example is sending email:
|
107
118
|
|
108
|
-
|
119
|
+
```ruby
|
120
|
+
Resque.enqueue_in(5.days, SendFollowUpEmail, :user_id => current_user.id)
|
121
|
+
```
|
109
122
|
|
110
123
|
This will store the job for 5 days in the resque delayed queue at which time
|
111
124
|
the scheduler process will pull it from the delayed queue and put it in the
|
@@ -136,10 +149,12 @@ disclosure is always best.
|
|
136
149
|
|
137
150
|
If you have the need to cancel a delayed job, you can do like so:
|
138
151
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
152
|
+
```ruby
|
153
|
+
# after you've enqueued a job like:
|
154
|
+
Resque.enqueue_at(5.days.from_now, SendFollowUpEmail, :user_id => current_user.id)
|
155
|
+
# remove the job with exactly the same parameters:
|
156
|
+
Resque.remove_delayed(SendFollowUpEmail, :user_id => current_user.id)
|
157
|
+
```
|
143
158
|
|
144
159
|
### Scheduled Jobs (Recurring Jobs)
|
145
160
|
|
@@ -151,26 +166,28 @@ The schedule is a list of Resque worker classes with arguments and a
|
|
151
166
|
schedule frequency (in crontab syntax). The schedule is just a hash, but
|
152
167
|
is most likely stored in a YAML like so:
|
153
168
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
169
|
+
```yaml
|
170
|
+
CancelAbandonedOrders:
|
171
|
+
cron: "*/5 * * * *"
|
172
|
+
|
173
|
+
queue_documents_for_indexing:
|
174
|
+
cron: "0 0 * * *"
|
175
|
+
# you can use rufus-scheduler "every" syntax in place of cron if you prefer
|
176
|
+
# every: 1hr
|
177
|
+
# By default the job name (hash key) will be taken as worker class name.
|
178
|
+
# If you want to have a different job name and class name, provide the 'class' option
|
179
|
+
class: QueueDocuments
|
180
|
+
queue: high
|
181
|
+
args:
|
182
|
+
description: "This job queues all content for indexing in solr"
|
183
|
+
|
184
|
+
clear_leaderboards_contributors:
|
185
|
+
cron: "30 6 * * 1"
|
186
|
+
class: ClearLeaderboards
|
187
|
+
queue: low
|
188
|
+
args: contributors
|
189
|
+
description: "This job resets the weekly leaderboard for contributions"
|
190
|
+
```
|
174
191
|
|
175
192
|
The queue value is optional, but if left unspecified resque-scheduler will
|
176
193
|
attempt to get the queue from the job class, which means it needs to be
|
@@ -180,16 +197,19 @@ need to either set the queue in the schedule or require your jobs in your
|
|
180
197
|
|
181
198
|
You can provide options to "every" or "cron" via Array:
|
182
199
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
200
|
+
```yaml
|
201
|
+
clear_leaderboards_moderator:
|
202
|
+
every:
|
203
|
+
- "30s"
|
204
|
+
- :first_in: "120s"
|
205
|
+
class: CheckDaemon
|
206
|
+
queue: daemons
|
207
|
+
description: "This job will check Daemon every 30 seconds after 120 seconds after start"
|
208
|
+
```
|
189
209
|
|
190
210
|
NOTE: Six parameter cron's are also supported (as they supported by
|
191
211
|
rufus-scheduler which powers the resque-scheduler process). This allows you
|
192
|
-
to schedule jobs per second (ie: "30 * * * * *" would fire a job every 30
|
212
|
+
to schedule jobs per second (ie: `"30 * * * * *"` would fire a job every 30
|
193
213
|
seconds past the minute).
|
194
214
|
|
195
215
|
A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
|
@@ -203,13 +223,17 @@ rather than the `config.time_zone` specified in Rails.
|
|
203
223
|
|
204
224
|
You can explicitly specify the time zone that rufus-scheduler will use:
|
205
225
|
|
206
|
-
|
226
|
+
```yaml
|
227
|
+
cron: "30 6 * * 1 Europe/Stockholm"
|
228
|
+
```
|
207
229
|
|
208
230
|
Also note that `config.time_zone` in Rails allows for a shorthand (e.g. "Stockholm")
|
209
231
|
that rufus-scheduler does not accept. If you write code to set the scheduler time zone
|
210
232
|
from the `config.time_zone` value, make sure it's the right format, e.g. with:
|
211
233
|
|
212
|
-
|
234
|
+
```ruby
|
235
|
+
ActiveSupport::TimeZone.find_tzinfo(Rails.configuration.time_zone).name
|
236
|
+
```
|
213
237
|
|
214
238
|
A future version of resque-scheduler may do this for you.
|
215
239
|
|
@@ -238,42 +262,48 @@ trying to support all existing and future custom job classes, instead it
|
|
238
262
|
supports a schedule flag so you can extend your custom class and make it
|
239
263
|
support scheduled job.
|
240
264
|
|
241
|
-
Let's pretend we have a JobWithStatus class called FakeLeaderboard
|
265
|
+
Let's pretend we have a `JobWithStatus` class called `FakeLeaderboard`
|
242
266
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
267
|
+
```ruby
|
268
|
+
class FakeLeaderboard < Resque::JobWithStatus
|
269
|
+
def perform
|
270
|
+
# do something and keep track of the status
|
271
|
+
end
|
272
|
+
end
|
273
|
+
```
|
248
274
|
|
249
275
|
And then a schedule:
|
250
276
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
277
|
+
```yaml
|
278
|
+
create_fake_leaderboards:
|
279
|
+
cron: "30 6 * * 1"
|
280
|
+
queue: scoring
|
281
|
+
custom_job_class: FakeLeaderboard
|
282
|
+
args:
|
283
|
+
rails_env: demo
|
284
|
+
description: "This job will auto-create leaderboards for our online demo and the status will update as the worker makes progress"
|
285
|
+
```
|
258
286
|
|
259
287
|
If your extension doesn't support scheduled job, you would need to extend the
|
260
288
|
custom job class to support the #scheduled method:
|
261
289
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
end
|
290
|
+
```ruby
|
291
|
+
module Resque
|
292
|
+
class JobWithStatus
|
293
|
+
# Wrapper API to forward a Resque::Job creation API call into
|
294
|
+
# a JobWithStatus call.
|
295
|
+
def self.scheduled(queue, klass, *args)
|
296
|
+
create(*args)
|
270
297
|
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
```
|
271
301
|
|
272
302
|
### Redundancy and Fail-Over
|
273
303
|
|
274
304
|
*>= 2.0.1 only. Prior to 2.0.1, it is not recommended to run multiple resque-scheduler processes and will result in duplicate jobs.*
|
275
305
|
|
276
|
-
You may want to have resque-scheduler running on multiple machines for
|
306
|
+
You may want to have resque-scheduler running on multiple machines for
|
277
307
|
redudancy. Electing a master and failover is built in and default. Simply
|
278
308
|
run resque-scheduler on as many machine as you want pointing to the same
|
279
309
|
redis instance and schedule. The scheduler processes will use redis to
|
@@ -311,14 +341,18 @@ include the `resque-scheduler` plugin and the resque-schedule server extension
|
|
311
341
|
to the resque-web sinatra app. Unless you're running redis on localhost, you
|
312
342
|
probably already have this file. It probably looks something like this:
|
313
343
|
|
314
|
-
|
315
|
-
|
344
|
+
```ruby
|
345
|
+
require 'resque' # include resque so we can configure it
|
346
|
+
Resque.redis = "redis_server:6379" # tell Resque where redis lives
|
347
|
+
```
|
316
348
|
|
317
349
|
Now, you want to add the following:
|
318
350
|
|
319
|
-
|
320
|
-
|
321
|
-
|
351
|
+
```ruby
|
352
|
+
# This will make the tabs show up.
|
353
|
+
require 'resque_scheduler'
|
354
|
+
require 'resque_scheduler/server'
|
355
|
+
```
|
322
356
|
|
323
357
|
That should make the scheduler tabs show up in `resque-web`.
|
324
358
|
|
@@ -330,7 +364,9 @@ process aware of the schedule because it reads it from redis. But prior to
|
|
330
364
|
2.0, you'll want to make sure you load the schedule in this file as well.
|
331
365
|
Something like this:
|
332
366
|
|
333
|
-
|
367
|
+
```ruby
|
368
|
+
Resque.schedule = YAML.load_file(File.join(RAILS_ROOT, 'config/resque_schedule.yml')) # load the schedule
|
369
|
+
```
|
334
370
|
|
335
371
|
Now make sure you're passing that file to resque-web like so:
|
336
372
|
|
@@ -347,6 +383,32 @@ worker is started.
|
|
347
383
|
$ PIDFILE=./resque-scheduler.pid BACKGROUND=yes \
|
348
384
|
rake resque:scheduler
|
349
385
|
|
386
|
+
|
387
|
+
### Logging
|
388
|
+
|
389
|
+
There are several options to toggle the way scheduler logs its actions. They
|
390
|
+
are toggled by environment variables:
|
391
|
+
|
392
|
+
- `MUTE` will stop logging anything. Completely silent;
|
393
|
+
- `VERBOSE` opposite to 'mute' will log even debug information;
|
394
|
+
- `LOGFILE` specifies the file to write logs to. Default is standard output.
|
395
|
+
|
396
|
+
All those variables are non-mandatory and default values are
|
397
|
+
|
398
|
+
```ruby
|
399
|
+
Resque::Scheduler.mute = false
|
400
|
+
Resque::Scheduler.verbose = false
|
401
|
+
Resque::Scheduler.logfile = nil # that means, all messages go to STDOUT
|
402
|
+
```
|
403
|
+
|
404
|
+
|
405
|
+
### Polling frequency
|
406
|
+
|
407
|
+
You can pass an INTERVAL option which is a integer representing the polling frequency.
|
408
|
+
The default is 5 seconds, but for a semi-active app you may want to use a smaller (integer) value.
|
409
|
+
|
410
|
+
$ INTERVAL=1 rake resque:scheduler
|
411
|
+
|
350
412
|
### Plagiarism alert
|
351
413
|
|
352
414
|
This was intended to be an extension to resque and so resulted in a lot of the
|
@@ -357,6 +419,12 @@ work on resque-scheduler.
|
|
357
419
|
|
358
420
|
### Contributing
|
359
421
|
|
360
|
-
|
422
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
423
|
+
|
424
|
+
### Authors
|
425
|
+
|
426
|
+
See [AUTHORS.md](AUTHORS.md)
|
427
|
+
|
428
|
+
### License
|
361
429
|
|
362
|
-
|
430
|
+
See [LICENSE](LICENSE)
|