sidekiq-scheduler 4.0.2 → 5.0.6
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/CHANGELOG.md +77 -1
- data/README.md +136 -48
- data/lib/sidekiq-scheduler/config.rb +91 -0
- data/lib/sidekiq-scheduler/extensions/web.rb +20 -7
- data/lib/sidekiq-scheduler/job_presenter.rb +1 -1
- data/lib/sidekiq-scheduler/manager.rb +26 -26
- data/lib/sidekiq-scheduler/redis_manager.rb +49 -20
- data/lib/sidekiq-scheduler/rufus_utils.rb +2 -2
- data/lib/sidekiq-scheduler/schedule.rb +2 -4
- data/lib/sidekiq-scheduler/scheduler.rb +52 -22
- data/lib/sidekiq-scheduler/sidekiq_adapter.rb +91 -0
- data/lib/sidekiq-scheduler/utils.rb +47 -7
- data/lib/sidekiq-scheduler/version.rb +1 -1
- data/lib/sidekiq-scheduler/web.rb +6 -1
- data/lib/sidekiq-scheduler.rb +6 -17
- data/web/assets/{stylesheets → recurring_jobs/stylesheets-scheduler}/recurring_jobs.css +15 -0
- data/web/locales/cs.yml +1 -0
- data/web/locales/de.yml +3 -0
- data/web/locales/en.yml +3 -0
- data/web/locales/es.yml +1 -0
- data/web/locales/fr.yml +5 -1
- data/web/locales/gd.yml +17 -0
- data/web/locales/it.yml +1 -0
- data/web/locales/ja.yml +1 -0
- data/web/locales/nl.yml +1 -0
- data/web/locales/pl.yml +1 -0
- data/web/locales/pt-BR.yml +2 -1
- data/web/locales/ru.yml +3 -0
- data/web/locales/sv.yml +1 -0
- data/web/locales/zh-cn.yml +1 -0
- data/web/views/recurring_jobs.erb +15 -24
- metadata +33 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2d6cf0887d66e27d2ce10ec96eabcb2b89bd89c515af8e38d54b366b38a8df2
|
4
|
+
data.tar.gz: c0da1db9ad45afdaf3b6055ce22ccc24ac90a392f7a2b5787136bbdeb6456fd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d845a756d2ba958cfedadcf52f6ba6f19811eb5b88c94fc50989b6a6f2bf523dbc7d2f8eb8e44c9d0c20a483f5896e5c313e5428f2369368de12479a2472163
|
7
|
+
data.tar.gz: 797ebac76066faa408f2f43290f6aead6a4ff335cb966811efdeea5c70c7ca5a4f93e6bda15f864987294e505583999bff64d05f33f2f2b9d0c92f512487d905
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,79 @@
|
|
1
|
+
# 5.0.6
|
2
|
+
- [**FIX**] Fix typo in `config#to_hash` method [#479](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/479)
|
3
|
+
- [**FIX**] Correctly clear scheduled jobs with Scheduler#clear_schedule! [#485](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/485)
|
4
|
+
- [**FIX**] Fix scheduling of aperiodic cron jobs [#487](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/487) (see [#484](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/484) for more details as well)
|
5
|
+
|
6
|
+
# 5.0.5
|
7
|
+
- [**FIX**] Use correct folder structure for assets [#476](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/476)
|
8
|
+
|
9
|
+
# 5.0.4
|
10
|
+
- [**FIX**] Ensure rufus-scheduler has a default rufus_scheduler_options value [#434](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/426)
|
11
|
+
- [**ENHANCEMENT**] Remove code related to sidekiq < 6 [#443](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/443)
|
12
|
+
- [**ENHANCEMENT**] Change cache-control to `private` [#446](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/446)
|
13
|
+
- [**ENHANCEMENT**] Increase compatibility range with tilt dependency [#458](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/458)
|
14
|
+
- [**ENHANCEMENT**] Ensure we support Ruby 3.3 [#461](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/461)
|
15
|
+
- [**ENHANCEMENT**] Use Redis MULTI command (https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/464)
|
16
|
+
- [**ENHANCEMENT**] Don't attempt to set jon next_time when job is nil [#466](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/466)
|
17
|
+
- [**ENHANCEMENT**] Improvements to prevent jobs been enqueued multiple times due to a delay in job execution [#463](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/463)
|
18
|
+
- [**FIX**] Prevent stack level too deep error by implementing `to_hash` method [#470](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/470)
|
19
|
+
- [**ENHANCEMENT**] Support new Sidekiq model for registering UI plugins [#472](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/472)
|
20
|
+
- [**ENHANCEMENT**] Stop testing against Ruby 2.7 and 3.0 [#472](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/472#discussion_r1663197863)
|
21
|
+
- [**ENHANCEMENT**] Display `at` and `in` in the dashboard [#291](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/291)
|
22
|
+
- [**ENHANCEMENT**] Docs enhancements [#442](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/442), [#449](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/449), [#457](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/457), [#465](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/465), [58e1835](https://github.com/sidekiq-scheduler/sidekiq-scheduler/commit/58e18351054fc3c264b2b5a684173316f674c386)
|
23
|
+
|
24
|
+
|
25
|
+
# 5.0.3
|
26
|
+
|
27
|
+
- [**FIX**] Fix "uppercase character in header name: Cache-Control" [#432](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/432)
|
28
|
+
- [**ENHANCEMENT**] Add gd translation [#433](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/433)
|
29
|
+
- [**ENHANCEMENT**] Add French translation [#435](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/435)
|
30
|
+
- [**FIX**] Remove usage of deprecated Redis command `zrangebyscore` [#437](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/437)
|
31
|
+
- [**ENHANCEMENT**] Add the ability to force a job args hash to be deconstructed to keyword arguments [#440](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/440)
|
32
|
+
|
33
|
+
# 5.0.2
|
34
|
+
|
35
|
+
- [**FIX**] Fix YARD docblocks. [#427](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/427)
|
36
|
+
- [**FIX**] Fix dependency requirement on Sidekiq reverted unintentionally. [#429](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/429)
|
37
|
+
|
38
|
+
# 5.0.1
|
39
|
+
|
40
|
+
- [**ENHANCEMENT**] Adds Ruby 3.2 to the CI matrix. [#420](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/420)
|
41
|
+
- [**DOCS**] README: refer to v5 as released. [#421](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/421)
|
42
|
+
- [**FIX**] Fix dependency on Rails `.present?` method. [#425](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/425)
|
43
|
+
|
44
|
+
# 5.0.0
|
45
|
+
|
46
|
+
- [**FIX**] Ensure generated scheduled time has a precision of 3 milliseconds. [#418](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/418)
|
47
|
+
|
48
|
+
*Note 1:* Check [# 5.0.0.beta1](#500beta1) & [# 5.0.0.beta2](#500beta2) releases for breaking changes.
|
49
|
+
|
50
|
+
*Note 2:* Sidekiq Embedding is yet not supported, see [#419](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/419) for more details.
|
51
|
+
|
52
|
+
|
53
|
+
# 5.0.0.beta2
|
54
|
+
|
55
|
+
- [**FIX**] Drop explicit redis dependency [#416](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/416)
|
56
|
+
|
57
|
+
# 5.0.0.beta1
|
58
|
+
|
59
|
+
- [**BREAKING CHANGE**] Moves all sidekiq-scheduler config options under the `scheduler` key in the `sidekiq.yml` file [#412](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/412)
|
60
|
+
- If you're migrating from v4 to v5, any `sidekiq-scheduler` config you may have in your `sidekiq.yml` should be moved under the `scheduler` key.
|
61
|
+
- See [#412](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/412) to see which are the config options that you need to move under the `scheduler` key.
|
62
|
+
|
63
|
+
- [**BREAKING CHANGE**] Drop support for EOL Ruby & Sidekiq versions (Ruby: `2.5.x` & `2.6.x`; Sidekiq: `4.x` & `5.x`) [#411](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/411)
|
64
|
+
|
65
|
+
- [**FIX**] Add support for Sidekiq 7 [#410](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/410)
|
66
|
+
|
67
|
+
|
68
|
+
# 4.0.3
|
69
|
+
|
70
|
+
- [**GH Actions**] Add dependabot for GitHub Actions [#390](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/390)
|
71
|
+
- [**ENHANCEMENT**] Add «Enable all» and «Disable all» buttons [#398](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/398)
|
72
|
+
- [**ENHANCEMENT**] Allow for multiple applications to share a Redis DB [#401](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/401)
|
73
|
+
- [**FIX**] Fix metadata for Sidekiq strict_args! [#403](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/403)
|
74
|
+
- [**FIX**] Redis 5.0 compatibility [#404](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/404)
|
75
|
+
- [**FIX**] Fix the constantize method [#408](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/408)
|
76
|
+
|
1
77
|
# 4.0.2
|
2
78
|
|
3
79
|
- [**FIX**] Fix sidekiq deprecation warning when Sidekiq 6.5+ [#385](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/385)
|
@@ -20,6 +96,6 @@
|
|
20
96
|
- [**ENHANCEMENT**] Highlight disabled jobs [#369](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/369)
|
21
97
|
- [**BREAKING CHANGE**] Require redis 4.2.0 [#370](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/370)
|
22
98
|
- [**FIX**] Fixes redis deprecation warning regarding `exists` [#370](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/370)
|
23
|
-
- [**BREAKING CHANGE**] Remove
|
99
|
+
- [**BREAKING CHANGE**] Remove dependency on thwait and e2mmap [#371](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/371)
|
24
100
|
- Support Ruby 3.1 [#373](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/373)
|
25
101
|
- [**BREAKING CHANGE**] Set rufus_scheduler_options via sidekiq.yml file as configuration option [#375](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/375)
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
`sidekiq-scheduler` is an extension to [Sidekiq](http://github.com/mperham/sidekiq) that
|
19
19
|
pushes jobs in a scheduled way, mimicking cron utility.
|
20
20
|
|
21
|
-
__Note:__ Current branch contains work of the
|
21
|
+
__Note:__ Current branch contains work of the v5 release, if you are looking for version 2.2.\*, 3.\*, or 4.\*, go to [2.2-stable branch](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/2.2-stable) / [v3-stable](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/v3-stable) / [v4-stable](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/v4-stable).
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
@@ -45,15 +45,21 @@ class HelloWorld
|
|
45
45
|
end
|
46
46
|
```
|
47
47
|
|
48
|
+
__Note:__ In Sidekiq v6.3 `Sidekiq::Job` was introduced as an alias for `Sidekiq::Worker`. `Sidekiq::Worker` has been officially deprecated in Sidekiq v7 although it still exists for backwards compatibility. It is therefore recommended to use `include Sidekiq::Job` in the above example unless an older version of Sidekiq is required.
|
49
|
+
|
48
50
|
``` yaml
|
49
51
|
# config/sidekiq.yml
|
50
52
|
|
51
|
-
:
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
:scheduler:
|
54
|
+
:schedule:
|
55
|
+
hello_world:
|
56
|
+
cron: '0 * * * * *' # Runs once per minute
|
57
|
+
class: HelloWorld
|
55
58
|
```
|
56
59
|
|
60
|
+
> [!NOTE]
|
61
|
+
> sidekiq-scheduler uses [fugit](https://github.com/floraison/fugit) under the hood, which supports up to six arguments as the cron string, [see](https://github.com/floraison/fugit?tab=readme-ov-file#the-second-extension).
|
62
|
+
|
57
63
|
Run sidekiq:
|
58
64
|
|
59
65
|
``` sh
|
@@ -83,40 +89,60 @@ Configuration options are placed inside `sidekiq.yml` config file.
|
|
83
89
|
Available options are:
|
84
90
|
|
85
91
|
``` yaml
|
86
|
-
:dynamic: <if true the schedule can be modified in runtime [false by default]>
|
87
|
-
:dynamic_every: <if dynamic is true, the schedule is reloaded every interval [5s by default]>
|
88
|
-
:enabled: <enables scheduler if true [true by default]>
|
89
92
|
:scheduler:
|
93
|
+
:dynamic: <if true the schedule can be modified in runtime [false by default]>
|
94
|
+
:dynamic_every: <if dynamic is true, the schedule is reloaded every interval [5s by default]>
|
95
|
+
:enabled: <enables scheduler if true [true by default]>
|
90
96
|
:listened_queues_only: <push jobs whose queue is being listened by sidekiq [false by default]>
|
91
|
-
:rufus_scheduler_options: <Set custom options for rufus scheduler, like max_work_threads [{} by default]>
|
97
|
+
:rufus_scheduler_options: <Set custom options for rufus scheduler, like max_work_threads [{} by default]>
|
92
98
|
```
|
93
99
|
|
94
100
|
## Schedule configuration
|
95
101
|
|
96
|
-
The schedule is configured through the `:schedule` config entry in the sidekiq config file:
|
102
|
+
The schedule is configured through the `:scheduler:` -> `:schedule` config entry in the sidekiq config file:
|
97
103
|
|
98
104
|
``` yaml
|
99
|
-
:
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
105
|
+
:scheduler:
|
106
|
+
:schedule:
|
107
|
+
CancelAbandonedOrders:
|
108
|
+
cron: '0 */5 * * * *' # Runs when second = 0, every 5 minutes
|
109
|
+
|
110
|
+
queue_documents_for_indexing:
|
111
|
+
cron: '0 0 * * * *' # Runs every hour
|
112
|
+
|
113
|
+
# By default the job name will be taken as worker class name.
|
114
|
+
# If you want to have a different job name and class name, provide the 'class' option
|
115
|
+
class: QueueDocuments
|
116
|
+
|
117
|
+
queue: slow
|
118
|
+
args: ['*.pdf']
|
119
|
+
description: "This job queues pdf content for indexing in solr"
|
120
|
+
|
121
|
+
# Enable the `metadata` argument which will pass a Hash containing the schedule metadata
|
122
|
+
# as the last argument of the `perform` method. `false` by default.
|
123
|
+
include_metadata: true
|
124
|
+
|
125
|
+
# Enable / disable a job. All jobs are enabled by default.
|
126
|
+
enabled: true
|
127
|
+
|
128
|
+
# Deconstructs a hash defined as the `args` to keyword arguments.
|
129
|
+
#
|
130
|
+
# `false` by default.
|
131
|
+
#
|
132
|
+
# Example
|
133
|
+
#
|
134
|
+
# my_job:
|
135
|
+
# cron: '0 0 * * * *'
|
136
|
+
# class: MyJob
|
137
|
+
# args: { foo: 'bar', hello: 'world' }
|
138
|
+
# keyword_argument: true
|
139
|
+
#
|
140
|
+
# class MyJob < ActiveJob::Base
|
141
|
+
# def perform(foo:, hello:)
|
142
|
+
# # ...
|
143
|
+
# end
|
144
|
+
# end
|
145
|
+
keyword_argument: true
|
120
146
|
```
|
121
147
|
|
122
148
|
### Schedule metadata
|
@@ -157,9 +183,10 @@ Cron, every, and interval types push jobs into sidekiq in a recurrent manner.
|
|
157
183
|
`cron` follows the same pattern as cron utility, with seconds resolution.
|
158
184
|
|
159
185
|
``` yaml
|
160
|
-
:
|
161
|
-
|
162
|
-
|
186
|
+
:scheduler:
|
187
|
+
:schedule:
|
188
|
+
HelloWorld:
|
189
|
+
cron: '0 * * * * *' # Runs when second = 0
|
163
190
|
```
|
164
191
|
|
165
192
|
`every` triggers following a given frequency:
|
@@ -186,7 +213,7 @@ At, and in types push jobs only once. `at` schedules in a point in time:
|
|
186
213
|
at: '3001/01/01'
|
187
214
|
```
|
188
215
|
|
189
|
-
You can specify any string that `DateTime.parse` and `Chronic` understand. To enable Chronic
|
216
|
+
You can specify any string that `DateTime.parse` and `Chronic` understand. To enable [Chronic](https://github.com/mojombo/chronic)
|
190
217
|
strings, you must add it as a dependency.
|
191
218
|
|
192
219
|
`in` triggers after a time duration has elapsed:
|
@@ -250,7 +277,8 @@ When `:dynamic` flag is set to `true`, schedule changes are loaded every 5 secon
|
|
250
277
|
|
251
278
|
``` yaml
|
252
279
|
# config/sidekiq.yml
|
253
|
-
:
|
280
|
+
:scheduler:
|
281
|
+
:dynamic: true
|
254
282
|
```
|
255
283
|
|
256
284
|
If `:dynamic` flag is set to `false`, you'll have to reload the schedule manually in sidekiq
|
@@ -299,8 +327,9 @@ You can also override the thread pool size in Rufus Scheduler by setting the fol
|
|
299
327
|
---
|
300
328
|
...
|
301
329
|
|
302
|
-
|
303
|
-
|
330
|
+
:scheduler:
|
331
|
+
rufus_scheduler_options:
|
332
|
+
max_work_threads: 5
|
304
333
|
|
305
334
|
...
|
306
335
|
```
|
@@ -308,7 +337,7 @@ rufus_scheduler_options:
|
|
308
337
|
## Notes about running on Multiple Hosts
|
309
338
|
|
310
339
|
Under normal conditions, `cron` and `at` jobs are pushed once regardless of the number of `sidekiq-scheduler` running instances,
|
311
|
-
|
340
|
+
assuming that time deltas between hosts is less than 24 hours.
|
312
341
|
|
313
342
|
Non-normal conditions that could push a specific job multiple times are:
|
314
343
|
- high cpu load + a high number of jobs scheduled at the same time, like 100 jobs
|
@@ -316,6 +345,47 @@ Non-normal conditions that could push a specific job multiple times are:
|
|
316
345
|
|
317
346
|
`every`, `interval` and `in` jobs will be pushed once per host.
|
318
347
|
|
348
|
+
### Suggested setup for Multiple Hosts using Heroku and Rails
|
349
|
+
|
350
|
+
Configuration options `every`, `interval` and `in` will push once per host. This may be undesirable. One way to achieve single jobs per the schedule would be to manually designate a host as the scheduler. The goal is to have a single scheduler process running across all your hosts.
|
351
|
+
|
352
|
+
This can be achieved by using an environment variable and controlling the number of dynos. In Rails, you can read this variable during initialization and then conditionally load your config file.
|
353
|
+
|
354
|
+
Suppose we are using Rails and have the following schedule:
|
355
|
+
|
356
|
+
```yaml
|
357
|
+
# config/scheduler.yml
|
358
|
+
MyRegularJob:
|
359
|
+
description: "We want this job to run very often, but we do not want to run more of them as we scale"
|
360
|
+
interval: ["1m"]
|
361
|
+
queue: default
|
362
|
+
```
|
363
|
+
|
364
|
+
Then we can conditionally load it via an initializer:
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
# config/initializers/sidekiq.rb
|
368
|
+
if ENV.fetch("IS_SCHEDULER", false)
|
369
|
+
Sidekiq.configure_server do |config|
|
370
|
+
config.on(:startup) do
|
371
|
+
Sidekiq.schedule = YAML.load_file(File.expand_path("../scheduler.yml", File.dirname(__FILE__)))
|
372
|
+
Sidekiq::Scheduler.reload_schedule!
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
```
|
377
|
+
|
378
|
+
Then you would just need to flag the scheduler process when you start it. If you are using a Procfile, it would look like this:
|
379
|
+
|
380
|
+
```yaml
|
381
|
+
# Procfile
|
382
|
+
web: bin/rails server
|
383
|
+
worker: bundle exec sidekiq -q default
|
384
|
+
scheduler: IS_SCHEDULER=true bundle exec sidekiq -q default
|
385
|
+
```
|
386
|
+
|
387
|
+
When running via Heroku, you set your `scheduler` process to have 1 dyno. This will ensure you have at most 1 worker loading the schedule.
|
388
|
+
|
319
389
|
## Notes on when Sidekiq worker is down
|
320
390
|
|
321
391
|
For a `cron`/`at` (and all other) job to be successfully enqueued, you need at least one sidekiq worker with scheduler to be up at that moment. Handling this is up to you and depends on your application.
|
@@ -345,12 +415,13 @@ Say you have one process with the schedule:
|
|
345
415
|
|
346
416
|
:queues:
|
347
417
|
- default
|
348
|
-
:
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
418
|
+
:scheduler:
|
419
|
+
:schedule:
|
420
|
+
do_something_every_minute:
|
421
|
+
class: DoSomethingJob
|
422
|
+
args: matey
|
423
|
+
queue: :scheduler
|
424
|
+
cron: '0 * * * * * America/Los_Angeles'
|
354
425
|
```
|
355
426
|
|
356
427
|
And a separate separate configured process without one:
|
@@ -360,7 +431,8 @@ And a separate separate configured process without one:
|
|
360
431
|
- scheduler
|
361
432
|
|
362
433
|
## NOTE Disable the Scheduler
|
363
|
-
:
|
434
|
+
:scheduler:
|
435
|
+
:enabled: false
|
364
436
|
```
|
365
437
|
|
366
438
|
### Details
|
@@ -377,6 +449,22 @@ Redis.
|
|
377
449
|
|
378
450
|
See https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/361 for a more details.
|
379
451
|
|
452
|
+
## Notes when running multiple applications in the same Redis database
|
453
|
+
|
454
|
+
_NOTE_: **Although we support this option, we recommend having separate redis databases for each application. Choosing this option is at your own risk.**
|
455
|
+
|
456
|
+
If you need to run multiple applications with differing schedules, the easiest way is to use a different Redis database per application. Doing that will ensure that each application will have its own schedule, web interface and statistics.
|
457
|
+
|
458
|
+
However, you may want to have a set of related applications share the same Redis database in order to aggregate statistics and manage them all in a single web interface. To do this while maintaining a different schedule for each application, you can configure each application to use a different `key_prefix` in Redis. This prevents the applications overwriting each others' schedules and schedule data.
|
459
|
+
|
460
|
+
```ruby
|
461
|
+
Rails.application.reloader.to_prepare do
|
462
|
+
SidekiqScheduler::RedisManager.key_prefix = "my-app"
|
463
|
+
end
|
464
|
+
```
|
465
|
+
|
466
|
+
Note that this must be set before the schedule is loaded (or it will go into the wrong key). If you are using the web integration, make sure that the prefix is set in the web process so that you see the correct schedule.
|
467
|
+
|
380
468
|
## Sidekiq Web Integration
|
381
469
|
|
382
470
|
sidekiq-scheduler provides an extension to the Sidekiq web interface that adds a `Recurring Jobs` page.
|
@@ -406,7 +494,7 @@ end
|
|
406
494
|
|
407
495
|
## The Spring preloader and Testing your initializer via Rails console
|
408
496
|
|
409
|
-
If you're pulling in your schedule from a YML file via an initializer as shown, be aware that the Spring application preloader included with Rails will
|
497
|
+
If you're pulling in your schedule from a YML file via an initializer as shown, be aware that the Spring application preloader included with Rails will interfere with testing via the Rails console.
|
410
498
|
|
411
499
|
**Spring will not reload initializers** unless the initializer is changed. Therefore, if you're making a change to your YML schedule file and reloading Rails console to see the change, Spring will make it seem like your modified schedule is not being reloaded.
|
412
500
|
|
@@ -451,7 +539,7 @@ MIT License
|
|
451
539
|
|
452
540
|
## Copyright
|
453
541
|
|
454
|
-
- Copyright 2021 -
|
542
|
+
- Copyright 2021 - 2024 Marcelo Lauxen.
|
455
543
|
- Copyright 2013 - 2022 Moove-IT.
|
456
544
|
- Copyright 2012 Morton Jonuschat.
|
457
545
|
- Some parts copyright 2010 Ben VandenBos.
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module SidekiqScheduler
|
2
|
+
class Config
|
3
|
+
# We have to set the default as nil because the scheduler could be instantiated without
|
4
|
+
# passing the sidekiq config, and in those scenarios we don't want to fail
|
5
|
+
def initialize(sidekiq_config: nil, without_defaults: false)
|
6
|
+
@sidekiq_config = sidekiq_config
|
7
|
+
@scheduler_config = fetch_scheduler_config(sidekiq_config, without_defaults)
|
8
|
+
end
|
9
|
+
|
10
|
+
def enabled?
|
11
|
+
scheduler_config[:enabled]
|
12
|
+
end
|
13
|
+
|
14
|
+
def enabled=(value)
|
15
|
+
scheduler_config[:enabled] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def dynamic?
|
19
|
+
scheduler_config[:dynamic]
|
20
|
+
end
|
21
|
+
|
22
|
+
def dynamic=(value)
|
23
|
+
scheduler_config[:dynamic] = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def dynamic_every?
|
27
|
+
scheduler_config[:dynamic_every]
|
28
|
+
end
|
29
|
+
|
30
|
+
def dynamic_every=(value)
|
31
|
+
scheduler_config[:dynamic_every] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def schedule
|
35
|
+
scheduler_config[:schedule]
|
36
|
+
end
|
37
|
+
|
38
|
+
def schedule=(value)
|
39
|
+
scheduler_config[:schedule] = value
|
40
|
+
end
|
41
|
+
|
42
|
+
def listened_queues_only?
|
43
|
+
scheduler_config[:listened_queues_only]
|
44
|
+
end
|
45
|
+
|
46
|
+
def listened_queues_only=(value)
|
47
|
+
scheduler_config[:listened_queues_only] = value
|
48
|
+
end
|
49
|
+
|
50
|
+
def rufus_scheduler_options
|
51
|
+
scheduler_config[:rufus_scheduler_options]
|
52
|
+
end
|
53
|
+
|
54
|
+
def rufus_scheduler_options=(value)
|
55
|
+
scheduler_config[:rufus_scheduler_options] = value
|
56
|
+
end
|
57
|
+
|
58
|
+
def sidekiq_queues
|
59
|
+
SidekiqScheduler::SidekiqAdapter.sidekiq_queues(sidekiq_config)
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_hash
|
63
|
+
{
|
64
|
+
enabled: enabled?,
|
65
|
+
dynamic: dynamic?,
|
66
|
+
dynamic_every: dynamic_every?,
|
67
|
+
schedule: schedule,
|
68
|
+
listened_queues_only: listened_queues_only?,
|
69
|
+
rufus_scheduler_options: rufus_scheduler_options
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
attr_reader :scheduler_config
|
76
|
+
attr_reader :sidekiq_config
|
77
|
+
|
78
|
+
DEFAULT_OPTIONS = {
|
79
|
+
enabled: true,
|
80
|
+
dynamic: false,
|
81
|
+
dynamic_every: '5s',
|
82
|
+
schedule: {},
|
83
|
+
rufus_scheduler_options: {}
|
84
|
+
}.freeze
|
85
|
+
|
86
|
+
def fetch_scheduler_config(sidekiq_config, without_defaults)
|
87
|
+
conf = SidekiqScheduler::SidekiqAdapter.fetch_scheduler_config_from_sidekiq(sidekiq_config)
|
88
|
+
without_defaults ? conf : DEFAULT_OPTIONS.merge(conf)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,14 +1,27 @@
|
|
1
1
|
require 'sidekiq/web' unless defined?(Sidekiq::Web)
|
2
2
|
|
3
|
-
|
3
|
+
if SidekiqScheduler::SidekiqAdapter::SIDEKIQ_GTE_7_3_0
|
4
4
|
|
5
|
-
|
6
|
-
Sidekiq::Web.
|
7
|
-
|
5
|
+
# Locale and asset cache is configured in `.register`
|
6
|
+
Sidekiq::Web.register(SidekiqScheduler::Web,
|
7
|
+
name: "recurring_jobs",
|
8
|
+
tab: ["Recurring Jobs"],
|
9
|
+
index: ["recurring-jobs"],
|
10
|
+
root_dir: File.expand_path("../../../web", File.dirname(__FILE__)),
|
11
|
+
asset_paths: ["stylesheets-scheduler"]) do |app|
|
12
|
+
# add middleware or additional settings here
|
13
|
+
end
|
8
14
|
|
9
|
-
|
10
|
-
|
15
|
+
else
|
16
|
+
|
17
|
+
ASSETS_PATH = File.expand_path('../../../web/assets', __dir__)
|
18
|
+
|
19
|
+
Sidekiq::Web.register(SidekiqScheduler::Web)
|
20
|
+
Sidekiq::Web.tabs['recurring_jobs'] = 'recurring-jobs'
|
21
|
+
Sidekiq::Web.locales << File.expand_path("#{File.dirname(__FILE__)}/../../../web/locales")
|
22
|
+
|
23
|
+
Sidekiq::Web.use Rack::Static, urls: ['/recurring_jobs/stylesheets-scheduler'],
|
11
24
|
root: ASSETS_PATH,
|
12
25
|
cascade: true,
|
13
|
-
header_rules: [[:all, { '
|
26
|
+
header_rules: [[:all, { 'cache-control' => 'private, max-age=86400' }]]
|
14
27
|
end
|
@@ -38,7 +38,7 @@ module SidekiqScheduler
|
|
38
38
|
#
|
39
39
|
# @return [String] with the job's interval
|
40
40
|
def interval
|
41
|
-
@attributes['cron'] || @attributes['interval'] || @attributes['every']
|
41
|
+
@attributes['cron'] || @attributes['interval'] || @attributes['every'] || @attributes['at'] || @attributes['in']
|
42
42
|
end
|
43
43
|
|
44
44
|
# Returns the queue of the job
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'redis'
|
2
|
-
|
3
1
|
require 'sidekiq-scheduler/schedule'
|
4
2
|
require 'sidekiq-scheduler/scheduler'
|
5
3
|
|
@@ -10,19 +8,12 @@ module SidekiqScheduler
|
|
10
8
|
# from Redis onto the work queues
|
11
9
|
#
|
12
10
|
class Manager
|
13
|
-
|
14
|
-
|
15
|
-
dynamic: false,
|
16
|
-
dynamic_every: '5s',
|
17
|
-
schedule: {}
|
18
|
-
}
|
19
|
-
|
20
|
-
def initialize(options)
|
21
|
-
scheduler_options = load_scheduler_options(options)
|
11
|
+
def initialize(config)
|
12
|
+
set_current_scheduler_options(config)
|
22
13
|
|
23
|
-
@scheduler_instance = SidekiqScheduler::Scheduler.new(
|
14
|
+
@scheduler_instance = SidekiqScheduler::Scheduler.new(config)
|
24
15
|
SidekiqScheduler::Scheduler.instance = @scheduler_instance
|
25
|
-
Sidekiq.schedule =
|
16
|
+
Sidekiq.schedule = config.schedule if @scheduler_instance.enabled
|
26
17
|
end
|
27
18
|
|
28
19
|
def stop
|
@@ -33,21 +24,30 @@ module SidekiqScheduler
|
|
33
24
|
@scheduler_instance.load_schedule!
|
34
25
|
end
|
35
26
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
# This method is needed to avoid exposing unnecessary information.
|
28
|
+
# Because ActiveSupport's `as_json` traverses instance values to convert the object to a hash
|
29
|
+
# unless it responds to `to_hash`.
|
30
|
+
def to_hash
|
31
|
+
{
|
32
|
+
scheduler: @scheduler_instance.to_hash
|
33
|
+
}
|
34
|
+
end
|
41
35
|
|
42
|
-
|
43
|
-
enabled: SidekiqScheduler::Scheduler.enabled,
|
44
|
-
dynamic: SidekiqScheduler::Scheduler.dynamic,
|
45
|
-
dynamic_every: SidekiqScheduler::Scheduler.dynamic_every,
|
46
|
-
schedule: Sidekiq.schedule,
|
47
|
-
listened_queues_only: SidekiqScheduler::Scheduler.listened_queues_only
|
48
|
-
}.delete_if { |_, value| value.nil? }
|
36
|
+
private
|
49
37
|
|
50
|
-
|
38
|
+
def set_current_scheduler_options(config)
|
39
|
+
enabled = SidekiqScheduler::Scheduler.enabled
|
40
|
+
dynamic = SidekiqScheduler::Scheduler.dynamic
|
41
|
+
dynamic_every = SidekiqScheduler::Scheduler.dynamic_every
|
42
|
+
listened_queues_only = SidekiqScheduler::Scheduler.listened_queues_only
|
43
|
+
|
44
|
+
config.enabled = enabled unless enabled.nil?
|
45
|
+
config.dynamic = dynamic unless dynamic.nil?
|
46
|
+
config.dynamic_every = dynamic_every unless dynamic_every.nil?
|
47
|
+
unless Sidekiq.schedule.nil? || (Sidekiq.schedule.respond_to?(:empty?) && Sidekiq.schedule.empty?)
|
48
|
+
config.schedule = Sidekiq.schedule
|
49
|
+
end
|
50
|
+
config.listened_queues_only = listened_queues_only unless listened_queues_only.nil?
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|