resque-scheduler 4.2.1 → 4.5.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.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/rubocop.yml +27 -0
- data/.github/workflows/ruby.yml +48 -0
- data/AUTHORS.md +7 -0
- data/CHANGELOG.md +495 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/README.md +37 -17
- data/Rakefile +1 -5
- data/{bin → exe}/resque-scheduler +0 -0
- data/lib/resque/scheduler/cli.rb +1 -0
- data/lib/resque/scheduler/delaying_extensions.rb +38 -6
- data/lib/resque/scheduler/env.rb +8 -4
- data/lib/resque/scheduler/lock/resilient.rb +19 -12
- data/lib/resque/scheduler/locking.rb +2 -2
- data/lib/resque/scheduler/scheduling_extensions.rb +4 -3
- data/lib/resque/scheduler/server/views/delayed.erb +1 -1
- data/lib/resque/scheduler/server/views/search_form.erb +1 -1
- data/lib/resque/scheduler/server.rb +1 -1
- data/lib/resque/scheduler/version.rb +1 -1
- data/lib/resque/scheduler.rb +39 -16
- data/resque-scheduler.gemspec +29 -10
- metadata +62 -66
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -18
- data/.rubocop_todo.yml +0 -71
- data/.simplecov +0 -3
- data/.travis.yml +0 -26
- data/.vagrant-provision-as-vagrant.sh +0 -15
- data/.vagrant-provision.sh +0 -23
- data/.vagrant-skel/bash_profile +0 -7
- data/.vagrant-skel/bashrc +0 -7
- data/HISTORY.md +0 -303
- data/Vagrantfile +0 -14
- data/examples/Rakefile +0 -2
- data/examples/config/initializers/resque-web.rb +0 -37
- data/examples/dynamic-scheduling/README.md +0 -28
- data/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +0 -52
- data/examples/dynamic-scheduling/app/jobs/send_email_job.rb +0 -9
- data/examples/dynamic-scheduling/app/models/user.rb +0 -16
- data/examples/dynamic-scheduling/config/resque.yml +0 -4
- data/examples/dynamic-scheduling/config/static_schedule.yml +0 -7
- data/examples/dynamic-scheduling/lib/tasks/resque.rake +0 -48
- data/examples/run-resque-web +0 -3
- data/script/migrate_to_timestamps_set.rb +0 -16
- data/tasks/resque_scheduler.rake +0 -2
- data/test/cli_test.rb +0 -231
- data/test/delayed_queue_test.rb +0 -925
- data/test/env_test.rb +0 -47
- data/test/multi_process_test.rb +0 -125
- data/test/resque-web_test.rb +0 -364
- data/test/scheduler_args_test.rb +0 -222
- data/test/scheduler_hooks_test.rb +0 -55
- data/test/scheduler_locking_test.rb +0 -316
- data/test/scheduler_setup_test.rb +0 -141
- data/test/scheduler_task_test.rb +0 -72
- data/test/scheduler_test.rb +0 -473
- data/test/test_helper.rb +0 -147
- data/test/util_test.rb +0 -17
data/HISTORY.md
DELETED
@@ -1,303 +0,0 @@
|
|
1
|
-
# Resque Scheduler History / ChangeLog / Release Notes
|
2
|
-
|
3
|
-
## 4.2.1 (2016-06-08)
|
4
|
-
* Optimization of `find_delayed_selection`
|
5
|
-
* More defensive code around redis disconnects
|
6
|
-
* Only trap existing signals on given platform
|
7
|
-
* RuboCop auto-fixes
|
8
|
-
* Dependency updates
|
9
|
-
* Docs improvements
|
10
|
-
|
11
|
-
## 4.2.0 (2016-04-29)
|
12
|
-
* Bugfix for a race condition in concurrent restarts
|
13
|
-
* Clean up and simplify the scheduling extension
|
14
|
-
* Make `Resque::Scheduler.logger` accessible to user
|
15
|
-
* Failure hook support for better extensibility
|
16
|
-
* Default failure handler now outputs stacktrace
|
17
|
-
* Add index column to scheduler tab
|
18
|
-
* Update rufus-scheduler
|
19
|
-
* Bugfix for displaying schedules appropriate to the `env`
|
20
|
-
in scheduler UI
|
21
|
-
|
22
|
-
## 4.1.0 (2016-02-10)
|
23
|
-
* View helper to cut down on repetition
|
24
|
-
* Bugfix to check thread life only if present
|
25
|
-
* New `Resque.(find|enqueue)_delayed_selection` methods to complement
|
26
|
-
`Resque.remove_delayed_selection`
|
27
|
-
* Leave undefined env vars unset in internal options hash
|
28
|
-
* Insulate checking `Rails.env`
|
29
|
-
* Documentation updates and typo fixes
|
30
|
-
|
31
|
-
## 4.0.0 (2014-12-21)
|
32
|
-
* Bump rufus-scheduler dependency to `~> 3.0`
|
33
|
-
* Address warning from redis-namespace related to `#unwatch`
|
34
|
-
* Show current master in the web UI
|
35
|
-
* Bugfix related to schedule check when no jobs are in the queue
|
36
|
-
* Documentation updates
|
37
|
-
|
38
|
-
## 3.1.0 (2014-12-21)
|
39
|
-
* Note in README.md about production redis deployment configuration
|
40
|
-
* Bugfix to only override configuration options if provided
|
41
|
-
* Avoid use of redis `KEYS` command in `Resque.remove_delayed_selection`
|
42
|
-
* Better PID file cleanup
|
43
|
-
* Added option to filter by job class in `Resque.remove_delayed_selection`
|
44
|
-
* Bugfix to only release master lock if it belongs to us
|
45
|
-
* Tell-don't-ask with `Resque.schedule` to enable atomic clear & set
|
46
|
-
|
47
|
-
## 3.0.0 (2014-05-27)
|
48
|
-
* The grand re-namespacing of
|
49
|
-
`resque_scheduler/(.*)` => `resque/scheduler/\1`
|
50
|
-
* Cleanup of a ton of rubocop offenses
|
51
|
-
* Vagrant setup
|
52
|
-
* Documentation updates
|
53
|
-
* "Refactoring"
|
54
|
-
* Added support for last execution information through the web
|
55
|
-
* Handling signals while "sleeping" by relying on `Thread#wakeup`
|
56
|
-
* CodeClimate integration
|
57
|
-
* Addition of `Resque.delayed?` and `Resque.next_delayed_schedule`
|
58
|
-
* Testing against same rubies as resque (+ 2.1.1)
|
59
|
-
* Renamed `Resque.set_last_run` to `Resque.last_enqueued_at`
|
60
|
-
* Allow scheduled jobs to be deleted via resque web
|
61
|
-
* Fixed duplicated layout for `search_form` partial template.
|
62
|
-
* Fix issue where Web UI was ONLY showing jobs that only run in the current
|
63
|
-
environment
|
64
|
-
|
65
|
-
## 2.5.5 (2014-02-27)
|
66
|
-
* Only showing link to job with args if job is present
|
67
|
-
* Only showing scheduled jobs that match current env or omit env
|
68
|
-
* Ensuring lock and acquire lua scripts are refreshed on timeout change
|
69
|
-
* Switch to using `mono_logger` instead of stdlib `logger`
|
70
|
-
|
71
|
-
## 2.5.4 (2014-02-17)
|
72
|
-
* Documentation updates
|
73
|
-
|
74
|
-
## 2.5.3 (2014-02-12)
|
75
|
-
* Handling signals during poll sleep
|
76
|
-
|
77
|
-
## 2.5.2 (2014-02-11)
|
78
|
-
* Pinning down dependency versions more tightly
|
79
|
-
|
80
|
-
## 2.5.1 (2014-02-09)
|
81
|
-
* Make signal handling (really) Ruby 2 compatible
|
82
|
-
|
83
|
-
## 2.5.0 (2014-02-09)
|
84
|
-
* Use `logger.error` when logging errors from `handle_errors`
|
85
|
-
* Added search feature to the Delayed tab in Resque Web
|
86
|
-
* Fix confusion with redis version requirements in `README.md`
|
87
|
-
|
88
|
-
## 2.4.0 (2014-01-14)
|
89
|
-
|
90
|
-
* Including optional env name in procline
|
91
|
-
* Fixing an explosion regarding `every` in the views
|
92
|
-
* Bumping the copyright year
|
93
|
-
* Corrected doc for syntax of class and every keys
|
94
|
-
* Adding a standalone executable
|
95
|
-
* **POSSIBLE BREAKING CHANGE**: Dropping support for ree
|
96
|
-
* Add support for persistence of dynamic schedules
|
97
|
-
* Fix unsafe shutdown in Ruby 2
|
98
|
-
* Adding `.configure` convenience method for block-style configuration
|
99
|
-
* Add `.remove_delayed_selection` method to remove based on result of a block
|
100
|
-
* Add support for viewing all schedules for a job in web UI
|
101
|
-
* Use resque redis namespace in the master lock key
|
102
|
-
* Including optional app name in procline
|
103
|
-
* Various test improvements, :bug: fixes, and documentation updates!
|
104
|
-
|
105
|
-
## 2.3.1 (2013-11-20)
|
106
|
-
|
107
|
-
* Correcting `require_paths` in gemspec
|
108
|
-
|
109
|
-
## 2.3.0 (2013-11-07)
|
110
|
-
|
111
|
-
* Fix re-introduced `ThreadError` on Ruby 2
|
112
|
-
* **BREAKING CHANGE**: Added `RESQUE_SCHEDULER_INTERVAL` in place of `INTERVAL`
|
113
|
-
* Use `Float()` instead of `Integer()` to calculate poll sleep amount
|
114
|
-
* Upgraded dependence of Resque to support 1.25
|
115
|
-
* Add rufus scheduler `every` notice to README
|
116
|
-
* Use `Resque.validate` instead of custom `.validate_job!`
|
117
|
-
* Specify MIT license in gemspec
|
118
|
-
|
119
|
-
## 2.2.0 (2013-10-13)
|
120
|
-
|
121
|
-
* Locking rufus-scheduler dependency to `~> 2.0`
|
122
|
-
* Updated redis dependency to `>= 3.0.0`
|
123
|
-
* Add support for parameterized resque jobs.
|
124
|
-
* Allowing prefix for `master_lock_key`.
|
125
|
-
* Add `Resque.clean_schedules` method, which is useful when setting up the
|
126
|
-
scheduler for the first time.
|
127
|
-
* Bug fixes related to first time schedule retrieval and missing schedules.
|
128
|
-
|
129
|
-
## 2.1.0 (2013-09-20)
|
130
|
-
|
131
|
-
* Locking to resque < 1.25.0 (for now)
|
132
|
-
* Ensuring `Resque.schedule=` sets rather than appends
|
133
|
-
* Process daemonization fixes including stdio redirection and redis client
|
134
|
-
reconnection
|
135
|
-
* Add `#scheduled_at` which returns an array of timestamps at which the
|
136
|
-
specified job is scheduled
|
137
|
-
* Syncing stdout/stderr
|
138
|
-
* Add `#enqueue_delayed` for enqueueing specific delayed jobs immediately
|
139
|
-
* Show server local time in resque-web
|
140
|
-
* Enqueue immediately if job is being enqueued in the past
|
141
|
-
* Using a logger instead of `#puts`, configurable via `LOGFILE`, `VERBOSE`, and
|
142
|
-
`MUTE` environmental variables, as well as being settable via
|
143
|
-
`Resque::Scheduler#logger`
|
144
|
-
* Fixing scheduler template when arrays are passed to rufus-scheduler
|
145
|
-
* Add support for configuring `Resque::Scheduler.poll_sleep_amount` via the
|
146
|
-
`INTERVAL` environmental variable.
|
147
|
-
* Fixed shutdown in ruby 2.0.0
|
148
|
-
* Removed dependency on `Resque::Helpers`
|
149
|
-
|
150
|
-
## 2.0.1 (2013-03-20)
|
151
|
-
|
152
|
-
* Adding locking to support master failover
|
153
|
-
* Allow custom job classes to be used in `Resque.enqueue_at`
|
154
|
-
* More efficient `#remove_delayed` implementation
|
155
|
-
* Allowing `#enqueue_at` to call `#scheduled` when `Resque.inline` is `true`
|
156
|
-
|
157
|
-
## 2.0.0 (2012-05-04)
|
158
|
-
|
159
|
-
* Add support for Resque.inline configuration (carlosantoniodasilva)
|
160
|
-
* Fixing possible job loss race condition around deleting delayed queues
|
161
|
-
and enqueuing a job 0 seconds in the future.
|
162
|
-
|
163
|
-
### 2.0.0.h (2012-03-19)
|
164
|
-
|
165
|
-
* Adding plugin support with hooks (andreas)
|
166
|
-
|
167
|
-
### 2.0.0.f (2011-11-03)
|
168
|
-
|
169
|
-
* TODO: address race condition with delayed jobs (using redis transactions)
|
170
|
-
* Support `ENV['BACKGROUND']` flag for daemonizing (bernerdschaefer)
|
171
|
-
* Added support for `before_schedule` and `after_schedule` hooks (yaauie)
|
172
|
-
* Added `remove_delayed_job_from_timestamp` to remove delayed jobs from
|
173
|
-
a given timestamp.
|
174
|
-
|
175
|
-
### 2.0.0.e (2011-09-16)
|
176
|
-
|
177
|
-
* Adding `enqueue_at_with_queue`/`enqueue_in_with_queue` support (niralisse)
|
178
|
-
* Adding `Resque::Scheduler.poll_sleep_amount` to allow for configuring
|
179
|
-
the sleep time b/w delayed queue polls.
|
180
|
-
* Add a "Clear Delayed Jobs" button to the Delayed Jobs page (john-griffin)
|
181
|
-
* Fixed pagination issue on the Delayed tab
|
182
|
-
|
183
|
-
### 2.0.0.d (2011-04-04)
|
184
|
-
|
185
|
-
* porting bug fixes from v1.9-stable
|
186
|
-
|
187
|
-
### 2.0.0.c
|
188
|
-
|
189
|
-
* Rake task drop a pid file (sreeix)
|
190
|
-
|
191
|
-
### 2.0.0.b
|
192
|
-
|
193
|
-
* Bug fixes
|
194
|
-
|
195
|
-
### 2.0.0.a
|
196
|
-
|
197
|
-
* Dynamic schedule support (brianjlandau, davidyang)
|
198
|
-
* Now depends on redis >=1.3
|
199
|
-
|
200
|
-
## 1.9.11 (2013-11-20)
|
201
|
-
|
202
|
-
* Fixed behavior of `#validate_job!` via `#enqueue_at_with_queue` #286
|
203
|
-
* Correcting `require_paths` in gemspec #288
|
204
|
-
|
205
|
-
## 1.9.10 (2013-09-19)
|
206
|
-
|
207
|
-
* Backported `#enqueue_at_with_queue`
|
208
|
-
* Locking to resque < 1.25.0
|
209
|
-
* Mocha setup compatibility
|
210
|
-
* Ruby 1.8 compatibility in scheduler tab when schedule keys are symbols
|
211
|
-
|
212
|
-
## 1.9.9 (2011-03-29)
|
213
|
-
|
214
|
-
* Compatibility with resque 1.15.0
|
215
|
-
|
216
|
-
## 1.9.8 (???)
|
217
|
-
|
218
|
-
* Validates delayed jobs prior to insertion into the delayed queue (bogdan)
|
219
|
-
* Rescue exceptions that occur during queuing and log them (dgrijalva)
|
220
|
-
|
221
|
-
## 1.9.7 (2010-11-09)
|
222
|
-
|
223
|
-
* Support for rufus-scheduler "every" syntax (fallwith)
|
224
|
-
* Ability to pass a Time to `handle_delayed_items` for testing/staging (rcarver)
|
225
|
-
|
226
|
-
## 1.9.6 (2010-10-08)
|
227
|
-
|
228
|
-
* Support for custom job classes (like resque-status) (mattetti)
|
229
|
-
|
230
|
-
## 1.9.5 (2010-09-09)
|
231
|
-
|
232
|
-
* Updated scheduler rake task to allow for an alternate setup task
|
233
|
-
to avoid loading the entire stack. (chewbranca)
|
234
|
-
* Fixed sig issue on win32 (#25)
|
235
|
-
|
236
|
-
## 1.9.4 (2010-07-29)
|
237
|
-
|
238
|
-
* Adding ability to remove jobs from delayed queue (joshsz)
|
239
|
-
* Fixing issue #23 (removing .present? reference)
|
240
|
-
|
241
|
-
## 1.9.3 (2010-07-07)
|
242
|
-
|
243
|
-
* Bug fix (#19)
|
244
|
-
|
245
|
-
## 1.9.2 (2010-06-16)
|
246
|
-
|
247
|
-
* Fixing issue with redis gem 2.0.1 and redis server 1.2.6 (dbackeus)
|
248
|
-
|
249
|
-
## 1.9.1 (2010-06-04)
|
250
|
-
|
251
|
-
* Fixing issue with redis server 1.2.6 and redis gem 2.0.1
|
252
|
-
|
253
|
-
## 1.9.0 (2010-06-04)
|
254
|
-
|
255
|
-
* Adding redis 2.0 support (bpo)
|
256
|
-
|
257
|
-
## 1.8.2 (2010-06-04)
|
258
|
-
|
259
|
-
* Adding queue now functionality to delayed timestamps (daviddoan)
|
260
|
-
|
261
|
-
## 1.8.1 (2010-05-19)
|
262
|
-
|
263
|
-
* Adding `rails_env` for scheduled jobs to support scoping jobs by
|
264
|
-
`RAILS_ENV` (gravis).
|
265
|
-
* Fixing ruby 1.8.6 compatibility issue.
|
266
|
-
* Adding gemspec for bundler support.
|
267
|
-
|
268
|
-
## 1.8.0 (2010-04-14)
|
269
|
-
|
270
|
-
* Moving version to match corresponding resque version
|
271
|
-
* Sorting schedule on Scheduler tab
|
272
|
-
* Adding tests for resque-web (gravis)
|
273
|
-
|
274
|
-
## 1.0.5 (2010-03-01)
|
275
|
-
|
276
|
-
* Fixed support for overriding queue from schedule config.
|
277
|
-
* Removed resque-web dependency on loading the job classes for "Queue Now",
|
278
|
-
provided "queue" is specified in the schedule.
|
279
|
-
* The queue is now stored with the job and arguments in the delayed queue so
|
280
|
-
there is no longer a need for the scheduler to load job classes to introspect
|
281
|
-
the queue.
|
282
|
-
|
283
|
-
## 1.0.4 (2010-02-26)
|
284
|
-
|
285
|
-
* Added support for specifying the queue to put the job onto. This allows for
|
286
|
-
you to have one job that can go onto multiple queues and be able to schedule
|
287
|
-
jobs without having to load the job classes.
|
288
|
-
|
289
|
-
## 1.0.3 (2010-02-11)
|
290
|
-
|
291
|
-
* Added support for scheduled jobs with empty crons. This is helpful to have
|
292
|
-
jobs that you don't want on a schedule, but do want to be able to queue by
|
293
|
-
clicking a button.
|
294
|
-
|
295
|
-
## 1.0.2 (2010-02-?)
|
296
|
-
|
297
|
-
* Change Delayed Job tab to display job details if only 1 job exists
|
298
|
-
for a given timestamp
|
299
|
-
|
300
|
-
## 1.0.1 (2010-01-?)
|
301
|
-
|
302
|
-
* Bugfix: delayed jobs close together resulted in a 5 second sleep
|
303
|
-
|
data/Vagrantfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# vim:filetype=ruby
|
2
|
-
|
3
|
-
Vagrant.configure('2') do |config|
|
4
|
-
config.vm.hostname = 'resque-scheduler'
|
5
|
-
config.vm.box = 'precise64'
|
6
|
-
config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/precise/' <<
|
7
|
-
'current/precise-server-cloudimg-amd64-vagrant-disk1.box'
|
8
|
-
|
9
|
-
config.vm.network :private_network, ip: '33.33.33.10', auto_correct: true
|
10
|
-
config.vm.network :forwarded_port, guest: 5678, host: 15678,
|
11
|
-
auto_correct: true
|
12
|
-
|
13
|
-
config.vm.provision :shell, path: '.vagrant-provision.sh'
|
14
|
-
end
|
data/examples/Rakefile
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# vim:fileencoding=utf-8
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
require 'yaml'
|
5
|
-
require 'resque'
|
6
|
-
|
7
|
-
redis_env_var = ENV['REDIS_PROVIDER'] || 'REDIS_URL'
|
8
|
-
Resque.redis = ENV[redis_env_var] || 'localhost:6379'
|
9
|
-
|
10
|
-
require 'resque-scheduler'
|
11
|
-
require 'resque/scheduler/server'
|
12
|
-
|
13
|
-
schedule_yml = ENV['RESQUE_SCHEDULE_YML']
|
14
|
-
if schedule_yml
|
15
|
-
Resque.schedule = if File.exist?(schedule_yml)
|
16
|
-
YAML.load_file(schedule_yml)
|
17
|
-
else
|
18
|
-
YAML.load(schedule_yml)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
schedule_json = ENV['RESQUE_SCHEDULE_JSON']
|
23
|
-
if schedule_json
|
24
|
-
Resque.schedule = if File.exist?(schedule_json)
|
25
|
-
JSON.parse(File.read(schedule_json))
|
26
|
-
else
|
27
|
-
JSON.parse(schedule_json)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Putter
|
32
|
-
@queue = 'putting'
|
33
|
-
|
34
|
-
def self.perform(*args)
|
35
|
-
args.each { |arg| puts arg }
|
36
|
-
end
|
37
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
Dynamic Scheduling Example
|
2
|
-
==========================
|
3
|
-
|
4
|
-
Possible workaround for
|
5
|
-
https://github.com/resque/resque-scheduler/issues/269
|
6
|
-
|
7
|
-
This folder contains just the relevant files you would have to put into
|
8
|
-
a rails application.
|
9
|
-
|
10
|
-
The problem we want to fix is that when resque-scheduler is restarted,
|
11
|
-
any dynamically added jobs are wiped. To fix it, we will run a
|
12
|
-
statically scheduled job that dynamically reschedules any missing
|
13
|
-
dynamic schedules.
|
14
|
-
|
15
|
-
This workaround uses both a dynamic schedule (every time a user is
|
16
|
-
created, a schedule is dynamically added to send him a daily email) and
|
17
|
-
a static schedule (a job runs hourly, starting 10 seconds after starting
|
18
|
-
resque-scheduler, to check that there is a scheduled job to send an
|
19
|
-
email for every user; missing schedules are added).
|
20
|
-
|
21
|
-
This way even though a resque-scheduler restart wipes all dynamic
|
22
|
-
schedules, they are recreated by the `fix_schedules` job that runs in
|
23
|
-
the static schedule. Even if dynamic schedules were lost for any reason
|
24
|
-
(data loss in redis clusters, whatever), they will be recreated hourly.
|
25
|
-
|
26
|
-
This workaround requires that enough information is saved in the
|
27
|
-
database to recreate all dynamic schedules. In this case we create one
|
28
|
-
dynamically scheduled job for every user in the database.
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# vim:fileencoding=utf-8
|
2
|
-
#
|
3
|
-
# Background job to fix the schedule for email sending. Any missing
|
4
|
-
# schedule will be added to resque-schedule.
|
5
|
-
#
|
6
|
-
# Recent resque-scheduler versions wipe all dynamic schedules when
|
7
|
-
# restarting. This means all dynamic schedules, which are added via the
|
8
|
-
# API, are wiped on each application redeployment. A workaround for this
|
9
|
-
# sometimes undesirable behavior is to make this job part of a static
|
10
|
-
# schedule (see config/initializers/resque.rb and
|
11
|
-
# config/static_schedule.yml). This job will be scheduled to run every
|
12
|
-
# hour even after restarting resque-schedule, and will add back the
|
13
|
-
# dynamic schedules that were wiped on restart. It also serves as
|
14
|
-
# safeguard against schedules getting lost for any reason.
|
15
|
-
#
|
16
|
-
# For more detail about this unfortunate behavior of resque-scheduler see:
|
17
|
-
#
|
18
|
-
# https://github.com/resque/resque-scheduler/issues/269
|
19
|
-
#
|
20
|
-
# The perform method of this class will be invoked from a Resque worker.
|
21
|
-
|
22
|
-
class FixSchedulesJob
|
23
|
-
@queue = :send_emails
|
24
|
-
|
25
|
-
# Fix email sending schedules. Any user which does not have scheduled
|
26
|
-
# sending of emails will be detected, and the missing scheduled job
|
27
|
-
# will be added to resque-schedule.
|
28
|
-
#
|
29
|
-
# This method is intended to be invoked from Resque, which means it is
|
30
|
-
# performed in the background.
|
31
|
-
def self.perform
|
32
|
-
users_unscheduled = []
|
33
|
-
|
34
|
-
User.all.each do |user|
|
35
|
-
# get schedule for the user
|
36
|
-
schedule = Resque.fetch_schedule("send_email_#{user.id}")
|
37
|
-
# if a user has no schedule, add it to the array
|
38
|
-
users_unscheduled << user if schedule.nil?
|
39
|
-
end
|
40
|
-
|
41
|
-
unless users_unscheduled.empty?
|
42
|
-
users_unscheduled.each do |user|
|
43
|
-
name = "send_email_#{user.id}"
|
44
|
-
config = {}
|
45
|
-
config[:class] = 'SendEmailJob'
|
46
|
-
config[:args] = user.id
|
47
|
-
config[:every] = '1d'
|
48
|
-
Resque.set_schedule(name, config)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# vim:fileencoding=utf-8
|
2
|
-
|
3
|
-
class User < ActiveRecord::Base
|
4
|
-
after_create :schedule_send_email
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def schedule_send_email
|
9
|
-
name = "send_email_#{id}"
|
10
|
-
config = {}
|
11
|
-
config[:class] = 'SendEmailJob'
|
12
|
-
config[:args] = id
|
13
|
-
config[:every] = '1d'
|
14
|
-
Resque.set_schedule(name, config)
|
15
|
-
end
|
16
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# vim:fileencoding=utf-8
|
2
|
-
|
3
|
-
require 'resque/tasks'
|
4
|
-
require 'resque/scheduler/tasks'
|
5
|
-
require 'yaml'
|
6
|
-
|
7
|
-
namespace :resque do
|
8
|
-
task :setup do
|
9
|
-
require 'resque'
|
10
|
-
require 'resque-scheduler'
|
11
|
-
|
12
|
-
rails_root = ENV['RAILS_ROOT'] || File.expand_path('../../../', __FILE__)
|
13
|
-
rails_env = ENV['RAILS_ENV'] || 'development'
|
14
|
-
|
15
|
-
# In resque-only servers we must require each job class individually,
|
16
|
-
# because we're not running the full Rails app
|
17
|
-
require "#{rails_root}/app/jobs/send_email_job"
|
18
|
-
require "#{rails_root}/app/jobs/fix_schedules_job"
|
19
|
-
|
20
|
-
resque_config = YAML.load_file(
|
21
|
-
File.join(rails_root.to_s, 'config', 'resque.yml')
|
22
|
-
)
|
23
|
-
Resque.redis = resque_config[rails_env]
|
24
|
-
|
25
|
-
# If you want to be able to dynamically change the schedule,
|
26
|
-
# uncomment this line. A dynamic schedule can be updated via the
|
27
|
-
# Resque::Scheduler.set_schedule (and remove_schedule) methods.
|
28
|
-
# When dynamic is set to true, the scheduler process looks for
|
29
|
-
# schedule changes and applies them on the fly.
|
30
|
-
# Note: This feature is only available in >=2.0.0.
|
31
|
-
Resque::Scheduler.dynamic = true
|
32
|
-
|
33
|
-
# Load static schedule (only in background servers).
|
34
|
-
# The schedule doesn't need to be stored in a YAML, it just needs to
|
35
|
-
# be a hash. YAML is usually the easiest.
|
36
|
-
Resque.schedule = YAML.load_file(
|
37
|
-
File.join(rails_root.to_s, 'config', 'static_schedule.yml')
|
38
|
-
)
|
39
|
-
|
40
|
-
Resque.before_fork do |job|
|
41
|
-
# Reconnect to the DB before running each job. Otherwise we get errors if
|
42
|
-
# the DB is restarted after starting Resque.
|
43
|
-
# Absolutely necessary on Heroku, otherwise we get a "PG::Error: SSL
|
44
|
-
# SYSCALL error: EOF detected" exception
|
45
|
-
ActiveRecord::Base.establish_connection
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/examples/run-resque-web
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# vim:fileencoding=utf-8
|
2
|
-
|
3
|
-
require 'redis'
|
4
|
-
require 'resque'
|
5
|
-
|
6
|
-
if ARGV.size != 1
|
7
|
-
puts 'migrate_to_timestamps_set.rb <redis-host:redis-port>'
|
8
|
-
exit
|
9
|
-
end
|
10
|
-
|
11
|
-
Resque.redis = ARGV[0]
|
12
|
-
redis = Resque.redis
|
13
|
-
Array(redis.keys('delayed:*')).each do |key|
|
14
|
-
jobs = redis.lrange(key, 0, -1)
|
15
|
-
jobs.each { |job| redis.sadd("timestamps:#{job}", key) }
|
16
|
-
end
|
data/tasks/resque_scheduler.rake
DELETED