ealdent-resque-scheduler 2.0.0.e

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ .bundle/
2
+ doc/
3
+ pkg
4
+ nbproject
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ resque-scheduler (2.0.0.e)
5
+ redis (>= 2.0.1)
6
+ resque (>= 1.15.0)
7
+ rufus-scheduler
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ mocha (0.9.9)
13
+ rake
14
+ multi_json (1.5.0)
15
+ rack (1.2.1)
16
+ rack-test (0.5.6)
17
+ rack (>= 1.0)
18
+ rake (0.8.7)
19
+ redis (3.0.2)
20
+ redis-namespace (1.2.1)
21
+ redis (~> 3.0.0)
22
+ resque (1.23.0)
23
+ multi_json (~> 1.0)
24
+ redis-namespace (~> 1.0)
25
+ sinatra (>= 0.9.2)
26
+ vegas (~> 0.1.2)
27
+ rufus-scheduler (2.0.17)
28
+ tzinfo (>= 0.3.23)
29
+ sinatra (1.2.8)
30
+ rack (~> 1.1)
31
+ tilt (>= 1.2.2, < 2.0)
32
+ tilt (1.3.3)
33
+ tzinfo (0.3.35)
34
+ vegas (0.1.11)
35
+ rack (>= 1.0.0)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (>= 1.0.0)
42
+ mocha
43
+ rack-test
44
+ resque-scheduler!
@@ -0,0 +1,121 @@
1
+ ## 2.0.0 (???)
2
+
3
+ * TODO: address race condition with delayed jobs (using redis transactions)
4
+
5
+ ## 2.0.0.e (2011-09-16)
6
+
7
+ * Adding enqueue_at_with_queue/enqueue_in_with_queue support (niralisse)
8
+ * Adding `Resque::Scheduler.poll_sleep_amount` to allow for configuring
9
+ the sleep time b/w delayed queue polls.
10
+ * Add a "Clear Delayed Jobs" button to the Delayed Jobs page (john-griffin)
11
+ * Fixed pagination issue on the Delayed tab
12
+
13
+ ## 2.0.0.d (2011-04-04)
14
+
15
+ * porting bug fixes from v1.9-stable
16
+
17
+ ## 2.0.0.c
18
+
19
+ * Rake task drop a pid file (sreeix)
20
+
21
+ ## 2.0.0.b
22
+
23
+ * Bug fixes
24
+
25
+ ## 2.0.0.a
26
+
27
+ * Dynamic schedule support (brianjlandau, davidyang)
28
+ * Now depends on redis >=1.3
29
+
30
+ ## 1.9.9 (2011-03-29)
31
+
32
+ * Compatibility with resque 1.15.0
33
+
34
+ ## 1.9.8 (???)
35
+
36
+ * Validates delayed jobs prior to insertion into the delayed queue (bogdan)
37
+ * Rescue exceptions that occur during queuing and log them (dgrijalva)
38
+
39
+ ## 1.9.7 (2010-11-09)
40
+
41
+ * Support for rufus-scheduler "every" syntax (fallwith)
42
+ * Ability to pass a Time to handle_delayed_items for testing/staging (rcarver)
43
+
44
+ ## 1.9.6 (2010-10-08)
45
+
46
+ * Support for custom job classes (like resque-status) (mattetti)
47
+
48
+ ## 1.9.5 (2010-09-09)
49
+
50
+ * Updated scheduler rake task to allow for an alternate setup task
51
+ to avoid loading the entire stack. (chewbranca)
52
+ * Fixed sig issue on win32 (#25)
53
+
54
+ ## 1.9.4 (2010-07-29)
55
+
56
+ * Adding ability to remove jobs from delayed queue (joshsz)
57
+ * Fixing issue #23 (removing .present? reference)
58
+
59
+ ## 1.9.3 (2010-07-07)
60
+
61
+ * Bug fix (#19)
62
+
63
+ ## 1.9.2 (2010-06-16)
64
+
65
+ * Fixing issue with redis gem 2.0.1 and redis server 1.2.6 (dbackeus)
66
+
67
+ ## 1.9.1 (2010-06-04)
68
+
69
+ * Fixing issue with redis server 1.2.6 and redis gem 2.0.1
70
+
71
+ ## 1.9.0 (2010-06-04)
72
+
73
+ * Adding redis 2.0 support (bpo)
74
+
75
+ ## 1.8.2 (2010-06-04)
76
+
77
+ * Adding queue now functionality to delayed timestamps (daviddoan)
78
+
79
+ ## 1.8.1 (2010-05-19)
80
+
81
+ * Adding rails_env for scheduled jobs to support scoping jobs by
82
+ RAILS_ENV (gravis).
83
+ * Fixing ruby 1.8.6 compatibility issue.
84
+ * Adding gemspec for bundler support.
85
+
86
+ ## 1.8.0 (2010-04-14)
87
+
88
+ * Moving version to match corresponding resque version
89
+ * Sorting schedule on Scheduler tab
90
+ * Adding tests for resque-web (gravis)
91
+
92
+ ## 1.0.5 (2010-03-01)
93
+
94
+ * Fixed support for overriding queue from schedule config.
95
+ * Removed resque-web dependency on loading the job classes for "Queue Now",
96
+ provided "queue" is specified in the schedule.
97
+ * The queue is now stored with the job and arguments in the delayed queue so
98
+ there is no longer a need for the scheduler to load job classes to introspect
99
+ the queue.
100
+
101
+ ## 1.0.4 (2010-02-26)
102
+
103
+ * Added support for specifying the queue to put the job onto. This allows for
104
+ you to have one job that can go onto multiple queues and be able to schedule
105
+ jobs without having to load the job classes.
106
+
107
+ ## 1.0.3 (2010-02-11)
108
+
109
+ * Added support for scheduled jobs with empty crons. This is helpful to have
110
+ jobs that you don't want on a schedule, but do want to be able to queue by
111
+ clicking a button.
112
+
113
+ ## 1.0.2 (2010-02-?)
114
+
115
+ * Change Delayed Job tab to display job details if only 1 job exists
116
+ for a given timestamp
117
+
118
+ ## 1.0.1 (2010-01-?)
119
+
120
+ * Bugfix: delayed jobs close together resulted in a 5 second sleep
121
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Ben VandenBos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -0,0 +1,283 @@
1
+ resque-scheduler
2
+ ================
3
+
4
+ ### Description
5
+
6
+ Resque-scheduler is an extension to [Resque](http://github.com/defunkt/resque)
7
+ that adds support for queueing items in the future.
8
+
9
+ Requires redis >=1.3.
10
+
11
+ Job scheduling is supported in two different way: Recurring (scheduled) and
12
+ Delayed.
13
+
14
+ Scheduled jobs are like cron jobs, recurring on a regular basis. Delayed
15
+ jobs are resque jobs that you want to run at some point in the future.
16
+ The syntax is pretty explanatory:
17
+
18
+ Resque.enqueue_in(5.days, SendFollowupEmail) # run a job in 5 days
19
+ # or
20
+ Resque.enqueue_at(5.days.from_now, SomeJob) # run SomeJob at a specific time
21
+
22
+ ### Documentation
23
+
24
+ This README covers what most people need to know. If you're looking for
25
+ details on individual methods, you might want to try the [rdoc](http://rdoc.info/github/bvandenbos/resque-scheduler/master/frames).
26
+
27
+ ### Installation
28
+
29
+ To install:
30
+
31
+ gem install resque-scheduler
32
+
33
+ Adding the resque:scheduler rake task:
34
+
35
+ require 'resque_scheduler/tasks'
36
+
37
+ There are three things `resque-scheduler` needs to know about in order to do
38
+ it's jobs: the schedule, where redis lives, and which queues to use. The
39
+ easiest way to configure these things is via the rake task. By default,
40
+ `resque-scheduler` depends on the "resque:setup" rake task. Since you
41
+ probably already have this task, lets just put our configuration there.
42
+ `resque-scheduler` pretty much needs to know everything `resque` needs
43
+ to know.
44
+
45
+
46
+ # Resque tasks
47
+ require 'resque/tasks'
48
+ require 'resque_scheduler/tasks'
49
+
50
+ namespace :resque do
51
+ task :setup do
52
+ require 'resque'
53
+ require 'resque_scheduler'
54
+ require 'resque/scheduler'
55
+
56
+ # you probably already have this somewhere
57
+ Resque.redis = 'localhost:6379'
58
+
59
+ # The schedule doesn't need to be stored in a YAML, it just needs to
60
+ # be a hash. YAML is usually the easiest.
61
+ Resque.schedule = YAML.load_file('your_resque_schedule.yml')
62
+
63
+ # If your schedule already has +queue+ set for each job, you don't
64
+ # need to require your jobs. This can be an advantage since it's
65
+ # less code that resque-scheduler needs to know about. But in a small
66
+ # project, it's usually easier to just include you job classes here.
67
+ # So, someting like this:
68
+ require 'jobs'
69
+
70
+ # If you want to be able to dynamically change the schedule,
71
+ # uncomment this line. A dynamic schedule can be updated via the
72
+ # Resque::Scheduler.set_schedule (and remove_schedule) methods.
73
+ # When dynamic is set to true, the scheduler process looks for
74
+ # schedule changes and applies them on the fly.
75
+ # Note: This feature is only available in >=2.0.0.
76
+ #Resque::Scheduler.dynamic = true
77
+ end
78
+ end
79
+
80
+ The scheduler process is just a rake task which is responsible for both
81
+ queueing items from the schedule and polling the delayed queue for items
82
+ ready to be pushed on to the work queues. For obvious reasons, this process
83
+ never exits.
84
+
85
+ $ rake resque:scheduler
86
+
87
+ Supported environment variables are `VERBOSE` and `MUTE`. If either is set to
88
+ any nonempty value, they will take effect. `VERBOSE` simply dumps more output
89
+ to stdout. `MUTE` does the opposite and silences all output. `MUTE`
90
+ supersedes `VERBOSE`.
91
+
92
+ NOTE: You DO NOT want to run >1 instance of the scheduler. Doing so will
93
+ result in the same job being queued more than once. You only need one
94
+ instnace of the scheduler running per resque instance (regardless of number
95
+ of machines).
96
+
97
+ If the scheduler process goes down for whatever reason, the delayed items
98
+ that should have fired during the outage will fire once the scheduler process
99
+ is started back up again (regardless of it being on a new machine). Missed
100
+ scheduled jobs, however, will not fire upon recovery of the scheduler process.
101
+
102
+
103
+
104
+ ### Delayed jobs
105
+
106
+ Delayed jobs are one-off jobs that you want to be put into a queue at some point
107
+ in the future. The classic example is sending email:
108
+
109
+ Resque.enqueue_in(5.days, SendFollowUpEmail, :user_id => current_user.id)
110
+
111
+ This will store the job for 5 days in the resque delayed queue at which time
112
+ the scheduler process will pull it from the delayed queue and put it in the
113
+ appropriate work queue for the given job and it will be processed as soon as
114
+ a worker is available (just like any other resque job).
115
+
116
+ NOTE: The job does not fire **exactly** at the time supplied. Rather, once that
117
+ time is in the past, the job moves from the delayed queue to the actual resque
118
+ work queue and will be completed as workers as free to process it.
119
+
120
+ Also supported is `Resque.enqueue_at` which takes a timestamp to queue the
121
+ job, and `Resque.enqueue_at_with_queue` which takes both a timestamp and a
122
+ queue name.
123
+
124
+ The delayed queue is stored in redis and is persisted in the same way the
125
+ standard resque jobs are persisted (redis writing to disk). Delayed jobs differ
126
+ from scheduled jobs in that if your scheduler process is down or workers are
127
+ down when a particular job is supposed to be queue, they will simply "catch up"
128
+ once they are started again. Jobs are guaranteed to run (provided they make it
129
+ into the delayed queue) after their given queue_at time has passed.
130
+
131
+ One other thing to note is that insertion into the delayed queue is O(log(n))
132
+ since the jobs are stored in a redis sorted set (zset). I can't imagine this
133
+ being an issue for someone since redis is stupidly fast even at log(n), but full
134
+ disclosure is always best.
135
+
136
+ ##### Removing Delayed jobs
137
+
138
+ If you have the need to cancel a delayed job, you can do like so:
139
+
140
+ # after you've enqueued a job like:
141
+ Resque.enqueue_at(5.days.from_now, SendFollowUpEmail, :user_id => current_user.id)
142
+ # remove the job with exactly the same parameters:
143
+ Resque.remove_delayed(SendFollowUpEmail, :user_id => current_user.id)
144
+
145
+ ### Scheduled Jobs (Recurring Jobs)
146
+
147
+ Scheduled (or recurring) jobs are logically no different than a standard cron
148
+ job. They are jobs that run based on a fixed schedule which is set at
149
+ startup.
150
+
151
+ The schedule is a list of Resque worker classes with arguments and a
152
+ schedule frequency (in crontab syntax). The schedule is just a hash, but
153
+ is most likely stored in a YAML like so:
154
+
155
+ queue_documents_for_indexing:
156
+ cron: "0 0 * * *"
157
+ # you can use rufus-scheduler "every" syntax in place of cron if you prefer
158
+ # every: 1hr
159
+ class: QueueDocuments
160
+ queue: high
161
+ args:
162
+ description: "This job queues all content for indexing in solr"
163
+
164
+ clear_leaderboards_contributors:
165
+ cron: "30 6 * * 1"
166
+ class: ClearLeaderboards
167
+ queue: low
168
+ args: contributors
169
+ description: "This job resets the weekly leaderboard for contributions"
170
+
171
+ The queue value is optional, but if left unspecified resque-scheduler will
172
+ attempt to get the queue from the job class, which means it needs to be
173
+ defined. If you're getting "uninitialized constant" errors, you probably
174
+ need to either set the queue in the schedule or require your jobs in your
175
+ "resque:setup" rake task.
176
+
177
+ NOTE: Six parameter cron's are also supported (as they supported by
178
+ rufus-scheduler which powers the resque-scheduler process). This allows you
179
+ to schedule jobs per second (ie: "30 * * * * *" would fire a job every 30
180
+ seconds past the minute).
181
+
182
+ A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
183
+ for handling the heavy lifting of the actual scheduling engine.
184
+
185
+
186
+ ##### Support for resque-status (and other custom jobs)
187
+
188
+ Some Resque extensions like
189
+ [resque-status](http://github.com/quirkey/resque-status) use custom job
190
+ classes with a slightly different API signature. Resque-scheduler isn't
191
+ trying to support all existing and future custom job classes, instead it
192
+ supports a schedule flag so you can extend your custom class and make it
193
+ support scheduled job.
194
+
195
+ Let's pretend we have a JobWithStatus class called FakeLeaderboard
196
+
197
+ class FakeLeaderboard < Resque::JobWithStatus
198
+ def perform
199
+ # do something and keep track of the status
200
+ end
201
+ end
202
+
203
+ And then a schedule:
204
+
205
+ create_fake_leaderboards:
206
+ cron: "30 6 * * 1"
207
+ queue: scoring
208
+ custom_job_class: FakeLeaderboard
209
+ args:
210
+ rails_env: demo
211
+ description: "This job will auto-create leaderboards for our online demo and the status will update as the worker makes progress"
212
+
213
+ If your extension doesn't support scheduled job, you would need to extend the
214
+ custom job class to support the #scheduled method:
215
+
216
+ module Resque
217
+ class JobWithStatus
218
+ # Wrapper API to forward a Resque::Job creation API call into
219
+ # a JobWithStatus call.
220
+ def self.scheduled(queue, klass, *args)
221
+ create(*args)
222
+ end
223
+ end
224
+ end
225
+
226
+
227
+
228
+ ### resque-web Additions
229
+
230
+ Resque-scheduler also adds to tabs to the resque-web UI. One is for viewing
231
+ (and manually queueing) the schedule and one is for viewing pending jobs in
232
+ the delayed queue.
233
+
234
+ The Schedule tab:
235
+
236
+ ![The Schedule Tab](http://img.skitch.com/20100111-km2f5gmtpbq23enpujbruj6mgk.png)
237
+
238
+ The Delayed tab:
239
+
240
+ ![The Delayed Tab](http://img.skitch.com/20100111-ne4fcqtc5emkcuwc5qtais2kwx.jpg)
241
+
242
+ To get these to show up you need to pass a file to `resque-web` to tell it to
243
+ include the `resque-scheduler` plugin. Unless you're running redis on
244
+ localhost, you probably already have this file. It probably looks something
245
+ like this:
246
+
247
+ require 'resque' # include resque so we can configure it
248
+ Resque.redis = "redis_server:6379" # tell Resque where redis lives
249
+
250
+ Now, you want to add the following:
251
+
252
+ # This will make the tabs show up.
253
+ require 'resque_scheduler'
254
+
255
+ As of resque-scheduler 2.0, it's no longer necessary to have the resque-web
256
+ process aware of the schedule because it reads it from redis. But prior to
257
+ 2.0, you'll want to make sure you load the schedule in this file as well.
258
+ Something like this:
259
+
260
+ Resque.schedule = YAML.load_file(File.join(RAILS_ROOT, 'config/resque_schedule.yml')) # load the schedule
261
+
262
+ Now make sure you're passing that file to resque-web like so:
263
+
264
+ resque-web ~/yourapp/config/resque_config.rb
265
+
266
+ That should make the scheduler tabs show up in `resque-web`.
267
+
268
+ ### Plagiarism alert
269
+
270
+ This was intended to be an extension to resque and so resulted in a lot of the
271
+ code looking very similar to resque, particularly in resque-web and the views. I
272
+ wanted it to be similar enough that someone familiar with resque could easily
273
+ work on resque-scheduler.
274
+
275
+
276
+ ### Contributing
277
+
278
+ For bugs or suggestions, please just open an issue in github.
279
+
280
+ Patches are always welcome.
281
+
282
+
283
+