resque-scheduler 4.4.0 → 4.11.0
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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +12 -0
- data/.github/funding.yml +4 -0
- data/.github/workflows/codeql-analysis.yml +59 -0
- data/.github/workflows/rubocop.yml +27 -0
- data/.github/workflows/ruby.yml +82 -0
- data/AUTHORS.md +8 -0
- data/CHANGELOG.md +81 -2
- data/Gemfile +20 -3
- data/README.md +90 -19
- data/Rakefile +2 -5
- data/lib/resque/scheduler/cli.rb +2 -1
- data/lib/resque/scheduler/configuration.rb +45 -9
- data/lib/resque/scheduler/delaying_extensions.rb +86 -47
- data/lib/resque/scheduler/env.rb +5 -5
- data/lib/resque/scheduler/lock/base.rb +2 -2
- data/lib/resque/scheduler/locking.rb +1 -1
- data/lib/resque/scheduler/logger_builder.rb +17 -6
- data/lib/resque/scheduler/plugin.rb +9 -0
- data/lib/resque/scheduler/scheduling_extensions.rb +6 -5
- data/lib/resque/scheduler/server/views/delayed.erb +12 -11
- data/lib/resque/scheduler/server/views/delayed_schedules.erb +1 -1
- data/lib/resque/scheduler/server/views/delayed_timestamp.erb +1 -1
- data/lib/resque/scheduler/server/views/scheduler.erb +2 -2
- data/lib/resque/scheduler/server/views/search.erb +2 -5
- data/lib/resque/scheduler/server/views/search_form.erb +1 -5
- data/lib/resque/scheduler/server.rb +1 -1
- data/lib/resque/scheduler/signal_handling.rb +2 -2
- data/lib/resque/scheduler/util.rb +1 -1
- data/lib/resque/scheduler/version.rb +1 -1
- data/lib/resque/scheduler.rb +81 -18
- data/resque-scheduler.gemspec +15 -7
- metadata +25 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4ecd4f957b7c3df8c89bc85ffb8951b5df6cc18b004379b29ebcfc3be982621
|
4
|
+
data.tar.gz: 7aacc351234c1f367d8b73cda10d43b97ff26e89a3319e0afa76b51abea70430
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e668259967505827e06a40a83cb2e3b7c7c165df440c914c8e688c4d871594c46ac512ebb8a99856f4e3cf37f45625f5144bc6beeda1157c7b2d146eec9055cc
|
7
|
+
data.tar.gz: 32e7b921643fb62600d133db156c5f4c28d863a893a92d18ba1b1f7317b0371dd38cd11b0a1e2adcccfa211265f9d285b452d2e524d3637487e7c982c8563032
|
data/.github/funding.yml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
name: "CodeQL"
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master, '*-stable' ]
|
6
|
+
pull_request:
|
7
|
+
# The branches below must be a subset of the branches above
|
8
|
+
branches: [ master ]
|
9
|
+
schedule:
|
10
|
+
- cron: '44 16 * * 6'
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
analyze:
|
14
|
+
name: Analyze
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
permissions:
|
17
|
+
actions: read
|
18
|
+
contents: read
|
19
|
+
security-events: write
|
20
|
+
|
21
|
+
strategy:
|
22
|
+
fail-fast: false
|
23
|
+
matrix:
|
24
|
+
language: [ 'ruby' ]
|
25
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
26
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
27
|
+
|
28
|
+
steps:
|
29
|
+
- name: Checkout repository
|
30
|
+
uses: actions/checkout@v4
|
31
|
+
|
32
|
+
# Initializes the CodeQL tools for scanning.
|
33
|
+
- name: Initialize CodeQL
|
34
|
+
uses: github/codeql-action/init@v3
|
35
|
+
with:
|
36
|
+
languages: ${{ matrix.language }}
|
37
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
38
|
+
# By default, queries listed here will override any specified in a config file.
|
39
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
40
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
41
|
+
|
42
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
43
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
44
|
+
- name: Autobuild
|
45
|
+
uses: github/codeql-action/autobuild@v3
|
46
|
+
|
47
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
48
|
+
# 📚 https://git.io/JvXDl
|
49
|
+
|
50
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
51
|
+
# and modify them (or add more) to build your code if your project
|
52
|
+
# uses a compiled language
|
53
|
+
|
54
|
+
#- run: |
|
55
|
+
# make bootstrap
|
56
|
+
# make release
|
57
|
+
|
58
|
+
- name: Perform CodeQL Analysis
|
59
|
+
uses: github/codeql-action/analyze@v3
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Rubocop
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
rubocop:
|
11
|
+
name: Rubocop
|
12
|
+
runs-on: ${{ matrix.os }}
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
os: [ubuntu-latest]
|
16
|
+
ruby: [
|
17
|
+
2.7
|
18
|
+
]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v4
|
22
|
+
- uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true
|
26
|
+
- name: Ruby linter
|
27
|
+
run: bundle exec rubocop
|
@@ -0,0 +1,82 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
continue-on-error: true
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
services:
|
14
|
+
redis:
|
15
|
+
image: redis
|
16
|
+
ports:
|
17
|
+
- 6379:6379
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
ruby-version:
|
22
|
+
- 2.3
|
23
|
+
- 2.4
|
24
|
+
- 2.5
|
25
|
+
- 2.6
|
26
|
+
- 2.7
|
27
|
+
- "3.0"
|
28
|
+
- 3.1
|
29
|
+
- 3.2
|
30
|
+
- 3.3
|
31
|
+
resque-version:
|
32
|
+
- "master"
|
33
|
+
- "~> 2.4.0"
|
34
|
+
- "~> 1.27"
|
35
|
+
rufus-scheduler:
|
36
|
+
- "3.2"
|
37
|
+
- "3.4"
|
38
|
+
- "3.5"
|
39
|
+
- "3.6"
|
40
|
+
redis-version:
|
41
|
+
- "~> 4.x"
|
42
|
+
- "~> 5.x"
|
43
|
+
exclude:
|
44
|
+
- ruby-version: head
|
45
|
+
rufus-scheduler: 3.2
|
46
|
+
- ruby-version: 3.2
|
47
|
+
rufus-scheduler: 3.2
|
48
|
+
|
49
|
+
- ruby-version: 2.3
|
50
|
+
resque-version: "~> 1.27"
|
51
|
+
rufus-scheduler: 3.4
|
52
|
+
- ruby-version: 2.3
|
53
|
+
resque-version: "~> 1.27"
|
54
|
+
rufus-scheduler: 3.5
|
55
|
+
- ruby-version: 2.5
|
56
|
+
resque-version: "~> 2.4.0"
|
57
|
+
rufus-scheduler: 3.5
|
58
|
+
- ruby-version: 2.5
|
59
|
+
resque-version: master
|
60
|
+
rufus-scheduler: 3.2
|
61
|
+
|
62
|
+
- ruby-version: 2.3
|
63
|
+
redis-version: "~> 5.x"
|
64
|
+
- ruby-version: 2.4
|
65
|
+
redis-version: "~> 5.x"
|
66
|
+
|
67
|
+
- resque-version: "~> 1.27"
|
68
|
+
redis-version: "~> 5.x"
|
69
|
+
env:
|
70
|
+
REDIS_VERSION: "${{ matrix.redis-version }}"
|
71
|
+
RESQUE: "${{ matrix.resque-version }}"
|
72
|
+
RUFUS_SCHEDULER: "${{ matrix.rufus-scheduler }}"
|
73
|
+
COVERAGE: 1
|
74
|
+
|
75
|
+
steps:
|
76
|
+
- uses: actions/checkout@v4
|
77
|
+
- uses: ruby/setup-ruby@v1
|
78
|
+
with:
|
79
|
+
ruby-version: "${{ matrix.ruby-version }}"
|
80
|
+
bundler-cache: true
|
81
|
+
- run: bundle exec rake
|
82
|
+
- run: bin/bundle_console_test.sh
|
data/AUTHORS.md
CHANGED
@@ -10,6 +10,7 @@ Resque Scheduler authors
|
|
10
10
|
- Brian Landau
|
11
11
|
- Brian P O'Rourke
|
12
12
|
- Carlos Antonio da Silva
|
13
|
+
- Chris Bisnett
|
13
14
|
- Chris Kampmeier
|
14
15
|
- DJ Hartman
|
15
16
|
- Damon P. Cortesi
|
@@ -28,8 +29,10 @@ Resque Scheduler authors
|
|
28
29
|
- Henrik Nyh
|
29
30
|
- Hormoz Kheradmand
|
30
31
|
- Ian Davies
|
32
|
+
- Irving Reid
|
31
33
|
- James Le Cuirot
|
32
34
|
- Jarkko Mönkkönen
|
35
|
+
- Jimmy Chao
|
33
36
|
- John Crepezzi
|
34
37
|
- John Griffin
|
35
38
|
- Jon Larkowski and Les Hill
|
@@ -41,6 +44,7 @@ Resque Scheduler authors
|
|
41
44
|
- Justin Weiss
|
42
45
|
- Les Hill
|
43
46
|
- Luke Rodgers
|
47
|
+
- Maksymilian Chwałek
|
44
48
|
- Manuel Meurer
|
45
49
|
- Matt Aimonetti
|
46
50
|
- Matt Simpson
|
@@ -62,11 +66,13 @@ Resque Scheduler authors
|
|
62
66
|
- Scott Francis
|
63
67
|
- Sean Stephens
|
64
68
|
- Sebastian Kippe
|
69
|
+
- Sharang Dashputre
|
65
70
|
- Spring MC
|
66
71
|
- tbprojects
|
67
72
|
- Tim Liner
|
68
73
|
- Tony Lewis
|
69
74
|
- Tom Crayford
|
75
|
+
- Tsu-Shiuan Lin
|
70
76
|
- Vincent Zhu
|
71
77
|
- Vladislav Shub
|
72
78
|
- V Sreekanth
|
@@ -82,3 +88,5 @@ Resque Scheduler authors
|
|
82
88
|
- malomalo
|
83
89
|
- sawanoboly
|
84
90
|
- serek
|
91
|
+
- iloveitaly
|
92
|
+
- treacher
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,84 @@
|
|
2
2
|
|
3
3
|
**ATTN**: This project uses [semantic versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [4.10.3] - 2024-12-30
|
6
|
+
### Added
|
7
|
+
* Expose timeout for lock via environment variable configuration by @pmm4654 in #786
|
8
|
+
* Add Ruby 3.3 to the CI matrix by @santiagorodriguez96 in #797
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
* Fix schedule hooks when enqueuing configured job by @codealchemy in #792
|
12
|
+
* Fix undefined `header` method CI failures by @codealchemy in #793
|
13
|
+
|
14
|
+
### Documentation
|
15
|
+
* Fix typo by @dijonkitchen in #789
|
16
|
+
* Fix links to generated docs by @dijonkitchen in #790
|
17
|
+
|
18
|
+
### Security
|
19
|
+
* Bump github/codeql-action from 2 to 3 by @dependabot in #785
|
20
|
+
|
21
|
+
## [4.10.2] - 2023-12-15
|
22
|
+
### Fixed
|
23
|
+
* Finish fixing CVE-2022-44303, XSS in delayed_schedules by @PatrickTulskie in #783
|
24
|
+
|
25
|
+
## [4.10.1] - 2023-12-15
|
26
|
+
### Fixed
|
27
|
+
* Fix json dump crasher with JSON 2.7.0+ by @PatrickTulskie in #781
|
28
|
+
* Fix for #761, reflected XSS in delayed_schedules.erb by @PatrickTulskie in #780
|
29
|
+
|
30
|
+
## [4.10.0] - 2023-08-20
|
31
|
+
### Added
|
32
|
+
* Add logfmt option for logging output (#763)
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
* Rubocop Fixes (#771)
|
36
|
+
|
37
|
+
## [4.9.0] - 2023-05-31
|
38
|
+
### Changed
|
39
|
+
- Adding batching to re-queuing for timestamp by @brennen-stripe in #767
|
40
|
+
- Use non-deprecated form of Redis.sadd/srem by @irvingreid in #752
|
41
|
+
- Prompt for confirmation on 'Clear Delayed Jobs' by @mishina2228 in #754
|
42
|
+
- Address some deprecation warnings in the test suite and with srem/lrem pipelined usage by @PatrickTulskie in #770
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
- Update CI matrix and fix tests by @mishina2228 in #766
|
46
|
+
|
47
|
+
## [4.8.0] - 2023-27-1
|
48
|
+
- Replace deprecated Socket.gethostname with Addrinfo.getaddrinfo to fix deprecation warnings (#753)
|
49
|
+
|
50
|
+
## [4.7.0] - 2022-10-6
|
51
|
+
### Fixed
|
52
|
+
- Fix tests for redis-rb 5.0 (#757)
|
53
|
+
- Use Resque::DataStore#reconnect for redis-rb 5.0 compat (#757)
|
54
|
+
- Test suite runs `flushall` to prevent flakiness (#757)
|
55
|
+
|
56
|
+
## [4.6.0] - 2022-08-04
|
57
|
+
### Changed
|
58
|
+
- Remove support for Ruby < 2.3
|
59
|
+
- Configuration to use a set of truthy values to enable boolean settings instead of simply existence
|
60
|
+
- Add `delay_or_enqueue_at` for delaying existing jobs or creating a new job(#645)
|
61
|
+
- Fix deprecated uses of Redis#pipelined
|
62
|
+
- Fix reading configuration from environment for boolean values (#735)
|
63
|
+
- Unblock rufus-scheduler lock on lower than 3.7 by fixing scheduler shutdown (#736)
|
64
|
+
- Removed testing against jruby (resque doesn't test against jruby)
|
65
|
+
|
66
|
+
## [4.5.0] - 2021-09-25
|
67
|
+
### Added
|
68
|
+
- Support Ruby 3
|
69
|
+
- Add optional argument to `remove_schedule` to control reloading of the schedule
|
70
|
+
|
71
|
+
### Fixed
|
72
|
+
- Fix XSS vulnerability on the `/delayed/search` page
|
73
|
+
- Ensure that jobs are directly created for jobs enqueued at `Time.now`
|
74
|
+
- Fix queuing to custom job queues in `enqueue_delayed_selection`
|
75
|
+
- Ensure `before_enqueue` and `after_enqueue` callbacks are called in all cases of queuing a job
|
76
|
+
- Fix redis error when running resque-scheduler without Redis
|
77
|
+
|
78
|
+
### Changed
|
79
|
+
- Change CI from Travis to GitHub Actions
|
80
|
+
- Only allow rufus-scheduler versions lower than 3.7
|
81
|
+
- Update vagrant configuration
|
82
|
+
|
5
83
|
## [4.4.0] - 2019-04-11
|
6
84
|
### Added
|
7
85
|
- Support Resque 2
|
@@ -14,7 +92,7 @@
|
|
14
92
|
- Fix setting the `poll_sleep_amount` option
|
15
93
|
- Escape class names in resque-web /delayed URLs
|
16
94
|
|
17
|
-
|
95
|
+
### Changed
|
18
96
|
- Addressed redis-namespace deprecation warnings
|
19
97
|
- Ensure `enqueue_in` args are Numeric, catching a common issue passing `ActiveSupport::Duration`
|
20
98
|
|
@@ -424,7 +502,8 @@
|
|
424
502
|
### Added
|
425
503
|
- Initial release
|
426
504
|
|
427
|
-
[Unreleased]: https://github.com/resque/resque-scheduler/compare/v4.
|
505
|
+
[Unreleased]: https://github.com/resque/resque-scheduler/compare/v4.5.0...HEAD
|
506
|
+
[4.5.0]: https://github.com/resque/resque-scheduler/compare/v4.4.0...v4.5.0
|
428
507
|
[4.4.0]: https://github.com/resque/resque-scheduler/compare/v4.3.1...v4.4.0
|
429
508
|
[4.3.1]: https://github.com/resque/resque-scheduler/compare/v4.3.0...v4.3.1
|
430
509
|
[4.3.0]: https://github.com/resque/resque-scheduler/compare/v4.2.1...v4.3.0
|
data/Gemfile
CHANGED
@@ -1,12 +1,29 @@
|
|
1
1
|
# vim:fileencoding=utf-8
|
2
2
|
source 'https://rubygems.org'
|
3
3
|
|
4
|
-
case
|
5
|
-
when nil
|
4
|
+
case resque_version = ENV.fetch('RESQUE', 'master')
|
6
5
|
when 'master'
|
7
6
|
gem 'resque', git: 'https://github.com/resque/resque'
|
8
7
|
else
|
9
|
-
gem 'resque',
|
8
|
+
gem 'resque', resque_version
|
10
9
|
end
|
11
10
|
|
11
|
+
case rufus_scheduler_version = ENV.fetch('RUFUS_SCHEDULER', '3.6')
|
12
|
+
when 'master'
|
13
|
+
gem 'rufus-scheduler', git: 'https://github.com/jmettraux/rufus-scheduler'
|
14
|
+
else
|
15
|
+
gem 'rufus-scheduler', rufus_scheduler_version
|
16
|
+
end
|
17
|
+
|
18
|
+
case redis_version = ENV.fetch('REDIS_VERSION', 'latest')
|
19
|
+
when 'master'
|
20
|
+
gem 'redis', git: 'https://github.com/redis/redis-rb'
|
21
|
+
when 'latest'
|
22
|
+
gem 'redis'
|
23
|
+
else
|
24
|
+
gem 'redis', redis_version
|
25
|
+
end
|
26
|
+
|
27
|
+
gem 'sinatra', '> 2.0'
|
28
|
+
|
12
29
|
gemspec
|
data/README.md
CHANGED
@@ -2,10 +2,8 @@ resque-scheduler
|
|
2
2
|
================
|
3
3
|
|
4
4
|
|
5
|
-
[](https://gemnasium.com/github.com/resque/resque-scheduler)
|
6
5
|
[](https://badge.fury.io/rb/resque-scheduler)
|
7
|
-
[](https://ci.appveyor.com/project/resque/resque-scheduler/branch/master)
|
6
|
+
[](https://github.com/resque/resque-scheduler/actions)
|
9
7
|
[](https://codeclimate.com/github/resque/resque-scheduler)
|
10
8
|
|
11
9
|
### Description
|
@@ -30,7 +28,7 @@ Resque.enqueue_at(5.days.from_now, SomeJob, argument) # runs a job at a specific
|
|
30
28
|
|
31
29
|
This `README` covers what most people need to know. If you're looking
|
32
30
|
for details on individual methods, you might want to try the
|
33
|
-
[
|
31
|
+
[rubydoc](https://rubydoc.info/github/resque/resque-scheduler/master/frames).
|
34
32
|
|
35
33
|
### Installation
|
36
34
|
|
@@ -88,7 +86,7 @@ namespace :resque do
|
|
88
86
|
# If your schedule already has +queue+ set for each job, you don't
|
89
87
|
# need to require your jobs. This can be an advantage since it's
|
90
88
|
# less code that resque-scheduler needs to know about. But in a small
|
91
|
-
# project, it's usually easier to just include
|
89
|
+
# project, it's usually easier to just include your job classes here.
|
92
90
|
# So, something like this:
|
93
91
|
require 'jobs'
|
94
92
|
end
|
@@ -141,7 +139,7 @@ requiring `resque` and `resque/scheduler` (default empty).
|
|
141
139
|
* `RESQUE_SCHEDULER_INTERVAL` - Interval in seconds for checking if a
|
142
140
|
scheduled job must run (coerced with `Kernel#Float()`) (default `5`)
|
143
141
|
* `LOGFILE` - Log file name (default empty, meaning `$stdout`)
|
144
|
-
* `LOGFORMAT` - Log output format to use (either `'text'` or `'
|
142
|
+
* `LOGFORMAT` - Log output format to use (either `'text'`, `'json'` or `'logfmt'`,
|
145
143
|
default `'text'`)
|
146
144
|
* `PIDFILE` - If non-empty, write process PID to file (default empty)
|
147
145
|
* `QUIET` - Silence most output if non-empty (equivalent to a level of
|
@@ -160,7 +158,7 @@ following task to wherever tasks are kept, such as
|
|
160
158
|
```ruby
|
161
159
|
task 'resque:pool:setup' do
|
162
160
|
Resque::Pool.after_prefork do |job|
|
163
|
-
Resque.redis.
|
161
|
+
Resque.redis.reconnect
|
164
162
|
end
|
165
163
|
end
|
166
164
|
```
|
@@ -213,7 +211,7 @@ since the jobs are stored in a redis sorted set (zset). I can't imagine this
|
|
213
211
|
being an issue for someone since redis is stupidly fast even at log(n), but full
|
214
212
|
disclosure is always best.
|
215
213
|
|
216
|
-
#### Removing Delayed
|
214
|
+
#### Removing Delayed Jobs
|
217
215
|
|
218
216
|
If you have the need to cancel a delayed job, you can do like so:
|
219
217
|
|
@@ -257,6 +255,49 @@ Resque.enqueue_delayed_selection { |args| args[0]['account_id'] == current_accou
|
|
257
255
|
Resque.enqueue_delayed_selection { |args| args[0]['user_id'] == current_user.id }
|
258
256
|
```
|
259
257
|
|
258
|
+
#### Updating Delayed Jobs
|
259
|
+
|
260
|
+
Previously delayed jobs may be delayed even further into the future like so:
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
# after you've enqueued a job like:
|
264
|
+
Resque.enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
|
265
|
+
# delay running the job until two minutes from now
|
266
|
+
Resque.delay_or_enqueue_at(2.minutes.from_now, SendNotifications, :user_id => current_user.id)
|
267
|
+
```
|
268
|
+
|
269
|
+
You don't need to worry if a matching job has already been queued, because if no matching jobs are found a new job is created and enqueued as if you had called `enqueue_at`. This means you don't need any special conditionals to know if a job has already been queued. You simply create the job like so:
|
270
|
+
|
271
|
+
```ruby
|
272
|
+
Resque.delay_or_enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
|
273
|
+
```
|
274
|
+
|
275
|
+
If multiple matching jobs are found, all of the matching jobs will be updated to have the same timestamp even if their original timestamps were not the same.
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
# enqueue multiple jobs with different delay timestamps
|
279
|
+
Resque.enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
|
280
|
+
Resque.enqueue_at(2.minutes.from_now, SendNotifications, :user_id => current_user.id)
|
281
|
+
|
282
|
+
# delay running the two jobs until 5 minutes from now
|
283
|
+
Resque.delay_or_enqueue_at(5.minutes.from_now, SendNotifications, :user_id => current_user.id)
|
284
|
+
```
|
285
|
+
|
286
|
+
The most useful case for increasing the delay of an already delayed job is to batch together work based on multiple events. For example, if you wanted to send a notification email to a user when an event triggers but didn't want to send 10 emails if many events happened within a short period, you could use this technique to delay the noficication email until no events have triggered for a period of time. This way you could send 1 email containing the 10 notifications once no events have triggered for 2 minutes. You could implement this like so:
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
# Send a notification when an event is created.
|
290
|
+
# app/models/event.rb
|
291
|
+
after_commit on: :create do
|
292
|
+
Resque.delay_or_enqueue_in(2.minutes, SendNotifications, :user_id => user.id)
|
293
|
+
end
|
294
|
+
```
|
295
|
+
|
296
|
+
When the first event is created a job will be scheduled to send unsent notifications to the associated user. If another event is created within the 2 minute window, the timer will be reset to 2 minutes. This will continue as long as new events are created for the specific user before the 2 minute timer expires. Once the timer expires and the job is scheduled any new events that are created will schedule a new job and start the process over. By adjusting the window you can tweak the trade-off between sending notification emails quickly after an event happens and sending fewer emails.
|
297
|
+
|
298
|
+
Read more in the [original PR](https://github.com/resque/resque-scheduler/pull/645)
|
299
|
+
|
300
|
+
|
260
301
|
### Scheduled Jobs (Recurring Jobs)
|
261
302
|
|
262
303
|
Scheduled (or recurring) jobs are logically no different than a standard cron
|
@@ -306,7 +347,6 @@ If you would like to setup a job that is executed manually you can configure lik
|
|
306
347
|
|
307
348
|
```yaml
|
308
349
|
ImportOrdersManual:
|
309
|
-
description: 'Import Amazon Orders Manual'
|
310
350
|
custom_job_class: 'AmazonMws::ImportOrdersJob'
|
311
351
|
never: "* * * * *"
|
312
352
|
queue: high
|
@@ -346,6 +386,38 @@ seconds past the minute).
|
|
346
386
|
A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
|
347
387
|
for handling the heavy lifting of the actual scheduling engine.
|
348
388
|
|
389
|
+
##### Queue with parameters
|
390
|
+
|
391
|
+
It's possible to specify parameters, that must be given by the user when they manually queue the job. To enable this feature add `parameters` key to scheduled job definition.
|
392
|
+
|
393
|
+
```yaml
|
394
|
+
queue_documents_for_indexing:
|
395
|
+
cron: "0 0 * * *"
|
396
|
+
class: "QueueDocuments"
|
397
|
+
queue: high
|
398
|
+
args:
|
399
|
+
foo: "bar"
|
400
|
+
a: "b"
|
401
|
+
parameters:
|
402
|
+
foo:
|
403
|
+
description: "value of foo"
|
404
|
+
default: "baz"
|
405
|
+
|
406
|
+
description: "This job queues all content for indexing in solr"
|
407
|
+
```
|
408
|
+
|
409
|
+
One can use following options for each parameter:
|
410
|
+
* description - tooltip to be shown next to the parameter input
|
411
|
+
* default - prefilled value in the parameter input
|
412
|
+
|
413
|
+
**NOTE**: When sheduling the job, parameters are merged into job args. Assuming the example above and default parametr value, the job will be run with the following args:
|
414
|
+
|
415
|
+
```ruby
|
416
|
+
{"foo"=>"baz", "a"=>"b"}
|
417
|
+
```
|
418
|
+
|
419
|
+
**NOTE**: If user leaves the parameter value empty, it'll be sent as empty string.
|
420
|
+
|
349
421
|
#### Dynamic schedules
|
350
422
|
|
351
423
|
Dynamic schedules are programmatically set on a running `resque-scheduler`.
|
@@ -407,18 +479,17 @@ Resque.set_schedule(name, config)
|
|
407
479
|
|
408
480
|
#### Time zones
|
409
481
|
|
410
|
-
|
411
|
-
rather than the `config.time_zone` specified in Rails.
|
412
|
-
|
482
|
+
If you use the cron syntax, by default it is interpreted in the server time zone.
|
413
483
|
You can explicitly specify the time zone that rufus-scheduler will use:
|
414
|
-
|
415
484
|
```yaml
|
416
485
|
cron: "30 6 * * 1 Europe/Stockholm"
|
417
486
|
```
|
418
487
|
|
419
|
-
|
420
|
-
|
421
|
-
|
488
|
+
##### Rails
|
489
|
+
In Rails, `config.time_zone` will be used to determine the time zone for `resque-scheduler`.
|
490
|
+
|
491
|
+
Note that `config.time_zone` allows for a shorthand (e.g. "Stockholm")
|
492
|
+
that rufus-scheduler does not accept, so make sure it's the right format, e.g. with:
|
422
493
|
|
423
494
|
```ruby
|
424
495
|
ActiveSupport::TimeZone.find_tzinfo(Rails.configuration.time_zone).name
|
@@ -575,7 +646,7 @@ Now make sure you're passing that file to resque-web like so:
|
|
575
646
|
|
576
647
|
### Running in the background
|
577
648
|
|
578
|
-
|
649
|
+
There are scenarios where it's helpful for
|
579
650
|
the resque worker to run itself in the background (usually in combination with
|
580
651
|
PIDFILE). Use the BACKGROUND option so that rake will return as soon as the
|
581
652
|
worker is started.
|
@@ -592,7 +663,7 @@ are toggled by environment variables:
|
|
592
663
|
- `QUIET` will stop logging anything. Completely silent.
|
593
664
|
- `VERBOSE` opposite of 'QUIET'; will log even debug information
|
594
665
|
- `LOGFILE` specifies the file to write logs to. (default standard output)
|
595
|
-
- `LOGFORMAT` specifies either "text" or "
|
666
|
+
- `LOGFORMAT` specifies either "text", "json" or "logfmt" output format
|
596
667
|
(default "text")
|
597
668
|
|
598
669
|
All of these variables are optional and will be given the following default
|
@@ -641,7 +712,7 @@ that happens on Travis CI and Appveyor:
|
|
641
712
|
bundle install
|
642
713
|
|
643
714
|
# Make sure tests are green before you change stuff
|
644
|
-
bundle exec rake
|
715
|
+
bundle exec rubocop && bundle exec rake
|
645
716
|
# Change stuff
|
646
717
|
# Repeat
|
647
718
|
```
|
data/Rakefile
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
# vim:fileencoding=utf-8
|
2
2
|
require 'bundler/gem_tasks'
|
3
3
|
require 'rake/testtask'
|
4
|
-
require 'rubocop/rake_task'
|
5
4
|
require 'yard'
|
6
5
|
|
7
|
-
task default:
|
8
|
-
task default: [:test] if RUBY_PLATFORM =~ /java/
|
9
|
-
|
10
|
-
RuboCop::RakeTask.new
|
6
|
+
task default: :test
|
11
7
|
|
12
8
|
Rake::TestTask.new do |t|
|
13
9
|
t.libs << 'test'
|
@@ -16,6 +12,7 @@ Rake::TestTask.new do |t|
|
|
16
12
|
o << "--seed #{ENV['SEED']} " if ENV['SEED']
|
17
13
|
o << '--verbose ' if ENV['VERBOSE']
|
18
14
|
end
|
15
|
+
t.warning = false
|
19
16
|
end
|
20
17
|
|
21
18
|
YARD::Rake::YardocTask.new
|