dynamodb-sidekiq-scheduler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 41f36be732670f63a04e4433e7409238af7b88d906ca8eab82bdd2df2c4f12cc
4
+ data.tar.gz: 59a18452ec604d55fc61d634c5b0e93d5929f2086221205d7947a2a336af1296
5
+ SHA512:
6
+ metadata.gz: 3e6b963abf528bfd3f0d935b6efc09e56e0f28b165514a477e2dd78b6804d9ccf7e52ba58f6bc5590613677832b02e8475053a08b2eea8038068c2331ad72fea
7
+ data.tar.gz: eff22625d062361600412dab4985f662c7fdad8b49b1c0a978d930013f1106c975315bd3378a48b3b58efd6011d21493aa6d6bbac1c9c382fcd9764ec854dfc3
data/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ # 5.0.2
2
+
3
+ - [**FIX**] Fix YARD docblocks. [#427](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/427)
4
+ - [**FIX**] Fix dependency requirement on Sidekiq reverted unintentionally. [#429](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/429)
5
+
6
+ # 5.0.1
7
+
8
+ - [**ENHANCEMENT**] Adds Ruby 3.2 to the CI matrix. [#420](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/420)
9
+ - [**DOCS**] README: refer to v5 as released. [#421](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/421)
10
+ - [**FIX**] Fix dependency on Rails `.present?` method. [#425](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/425)
11
+
12
+ # 5.0.0
13
+
14
+ - [**FIX**] Ensure generated scheduled time has a precision of 3 miliseconds. [#418](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/418)
15
+
16
+ *Note 1:* Check [# 5.0.0.beta1](#500beta1) & [# 5.0.0.beta2](#500beta2) releases for breaking changes.
17
+
18
+ *Note 2:* Sidekiq Embedding is yet not supported, see [#419](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/419) for more details.
19
+
20
+
21
+ # 5.0.0.beta2
22
+
23
+ - [**FIX**] Drop explicit redis dependency [#416](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/416)
24
+
25
+ # 5.0.0.beta1
26
+
27
+ - [**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)
28
+ - 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.
29
+ - 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.
30
+
31
+ - [**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)
32
+
33
+ - [**FIX**] Add support for Sidekiq 7 [#410](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/410)
34
+
35
+
36
+ # 4.0.3
37
+
38
+ - [**GH Actions**] Add dependabot for GitHub Actions [#390](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/390)
39
+ - [**ENHANCEMENT**] Add «Enable all» and «Disable all» buttons [#398](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/398)
40
+ - [**ENHANCEMENT**] Allow for multiple applications to share a Redis DB [#401](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/401)
41
+ - [**FIX**] Fix metadata for Sidekiq strict_args! [#403](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/403)
42
+ - [**FIX**] Redis 5.0 compatibility [#404](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/404)
43
+ - [**FIX**] Fix the constantize method [#408](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/408)
44
+
45
+ # 4.0.2
46
+
47
+ - [**FIX**] Fix sidekiq deprecation warning when Sidekiq 6.5+ [#385](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/385)
48
+ - [**FIX**] Fix `#print_schedule` calling a method that doesn't exist in rufus scheduler [#388](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/388)
49
+
50
+ # 4.0.1
51
+
52
+ - [**FIX**] Add support for sidekiq 6.5 [#382](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/382)
53
+
54
+ # 4.0.0
55
+
56
+ - [**FIX**] Fix CSS not loading on Rails app when Sidekiq < 6 [#377](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/377)
57
+ - [**BREAKING CHANGE**] Drop support for Sidekiq 3 [f15e7ca1a5f3ab5b6fd3d7664d67723dba1fa1f1](https://github.com/sidekiq-scheduler/sidekiq-scheduler/commit/f15e7ca1a5f3ab5b6fd3d7664d67723dba1fa1f1)
58
+
59
+ # 4.0.0.alpha1
60
+
61
+ - [**FIX**] Fix deprecated uses of Redis#pipelined [#357](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/357)
62
+ - [**DOCS**] Add docs for running multi-sidekiq configurations [#362](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/362)
63
+ - [**FIX**] Prevent sidekiq_options from overriding ActiveJob queue settings [#367](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/367)
64
+ - [**ENHANCEMENT**] Highlight disabled jobs [#369](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/369)
65
+ - [**BREAKING CHANGE**] Require redis 4.2.0 [#370](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/370)
66
+ - [**FIX**] Fixes redis deprecation warning regarding `exists` [#370](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/370)
67
+ - [**BREAKING CHANGE**] Remove dependecy on thwait and e2mmap [#371](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/371)
68
+ - Support Ruby 3.1 [#373](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/373)
69
+ - [**BREAKING CHANGE**] Set rufus_scheduler_options via sidekiq.yml file as configuration option [#375](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/375)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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.
data/README.md ADDED
@@ -0,0 +1,521 @@
1
+ # sidekiq-scheduler
2
+
3
+ <p align="center">
4
+ <a href="http://sidekiq-scheduler.github.io/sidekiq-scheduler/">
5
+ <img src="https://sidekiq-scheduler.github.io/sidekiq-scheduler/images/small-logo.svg" width="468px" height="200px" alt="Sidekiq Scheduler" />
6
+ </a>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://badge.fury.io/rb/sidekiq-scheduler">
11
+ <img src="https://badge.fury.io/rb/sidekiq-scheduler.svg" alt="Gem Version">
12
+ </a>
13
+ <a href="http://www.rubydoc.info/github/sidekiq-scheduler/sidekiq-scheduler">
14
+ <img src="https://img.shields.io/badge/yard-docs-blue.svg" alt="Documentation">
15
+ </a>
16
+ </p>
17
+
18
+ `sidekiq-scheduler` is an extension to [Sidekiq](http://github.com/mperham/sidekiq) that
19
+ pushes jobs in a scheduled way, mimicking cron utility.
20
+
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
+
23
+ ## Installation
24
+
25
+ ``` shell
26
+ gem install sidekiq-scheduler
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Hello World
32
+
33
+
34
+ ``` ruby
35
+ # hello-scheduler.rb
36
+
37
+ require 'sidekiq-scheduler'
38
+
39
+ class HelloWorld
40
+ include Sidekiq::Worker
41
+
42
+ def perform
43
+ puts 'Hello world'
44
+ end
45
+ end
46
+ ```
47
+
48
+ ``` yaml
49
+ # config/sidekiq.yml
50
+
51
+ :scheduler:
52
+ :schedule:
53
+ hello_world:
54
+ cron: '0 * * * * *' # Runs once per minute
55
+ class: HelloWorld
56
+ ```
57
+
58
+ Run sidekiq:
59
+
60
+ ``` sh
61
+ sidekiq -r ./hello-scheduler.rb
62
+ ```
63
+
64
+ You'll see the following output:
65
+
66
+ ```
67
+ 2016-12-10T11:53:08.561Z 6452 TID-ovouhwvm4 INFO: Loading Schedule
68
+ 2016-12-10T11:53:08.561Z 6452 TID-ovouhwvm4 INFO: Scheduling HelloWorld {"cron"=>"0 * * * * *", "class"=>"HelloWorld"}
69
+ 2016-12-10T11:53:08.562Z 6452 TID-ovouhwvm4 INFO: Schedules Loaded
70
+
71
+ 2016-12-10T11:54:00.212Z 6452 TID-ovoulivew HelloWorld JID-b35f36a562733fcc5e58444d INFO: start
72
+ Hello world
73
+ 2016-12-10T11:54:00.213Z 6452 TID-ovoulivew HelloWorld JID-b35f36a562733fcc5e58444d INFO: done: 0.001 sec
74
+
75
+ 2016-12-10T11:55:00.287Z 6452 TID-ovoulist0 HelloWorld JID-b7e2b244c258f3cd153c2494 INFO: start
76
+ Hello world
77
+ 2016-12-10T11:55:00.287Z 6452 TID-ovoulist0 HelloWorld JID-b7e2b244c258f3cd153c2494 INFO: done: 0.001 sec
78
+ ```
79
+
80
+ ## Configuration options
81
+
82
+ Configuration options are placed inside `sidekiq.yml` config file.
83
+
84
+ Available options are:
85
+
86
+ ``` yaml
87
+ :scheduler:
88
+ :dynamic: <if true the schedule can be modified in runtime [false by default]>
89
+ :dynamic_every: <if dynamic is true, the schedule is reloaded every interval [5s by default]>
90
+ :enabled: <enables scheduler if true [true by default]>
91
+ :listened_queues_only: <push jobs whose queue is being listened by sidekiq [false by default]>
92
+ :rufus_scheduler_options: <Set custom options for rufus scheduler, like max_work_threads [{} by default]>
93
+ ```
94
+
95
+ ## Schedule configuration
96
+
97
+ The schedule is configured through the `:scheduler:` -> `:schedule` config entry in the sidekiq config file:
98
+
99
+ ``` yaml
100
+ :scheduler:
101
+ :schedule:
102
+ CancelAbandonedOrders:
103
+ cron: '0 */5 * * * *' # Runs when second = 0, every 5 minutes
104
+
105
+ queue_documents_for_indexing:
106
+ cron: '0 0 * * * *' # Runs every hour
107
+
108
+ # By default the job name will be taken as worker class name.
109
+ # If you want to have a different job name and class name, provide the 'class' option
110
+ class: QueueDocuments
111
+
112
+ queue: slow
113
+ args: ['*.pdf']
114
+ description: "This job queues pdf content for indexing in solr"
115
+
116
+ # Enable the `metadata` argument which will pass a Hash containing the schedule metadata
117
+ # as the last argument of the `perform` method. `false` by default.
118
+ include_metadata: true
119
+
120
+ # Enable / disable a job. All jobs are enabled by default.
121
+ enabled: true
122
+ ```
123
+
124
+ ### Schedule metadata
125
+ You can configure Sidekiq-scheduler to pass an argument with metadata about the scheduling process
126
+ to the worker's `perform` method.
127
+
128
+ In the configuration file add the following on each worker class entry:
129
+
130
+ ```yaml
131
+
132
+ SampleWorker:
133
+ include_metadata: true
134
+ ```
135
+
136
+ On your `perform` method, expect an additional argument:
137
+
138
+ ```ruby
139
+ def perform(args, ..., metadata)
140
+ # Do something with the metadata
141
+ end
142
+ ```
143
+
144
+ The `metadata` hash contains the following keys:
145
+
146
+ ```ruby
147
+ metadata.keys =>
148
+ [
149
+ :scheduled_at # The epoch when the job was scheduled to run
150
+ ]
151
+ ```
152
+
153
+ ## Schedule types
154
+
155
+ Supported types are `cron`, `every`, `interval`, `at`, `in`.
156
+
157
+ Cron, every, and interval types push jobs into sidekiq in a recurrent manner.
158
+
159
+ `cron` follows the same pattern as cron utility, with seconds resolution.
160
+
161
+ ``` yaml
162
+ :scheduler:
163
+ :schedule:
164
+ HelloWorld:
165
+ cron: '0 * * * * *' # Runs when second = 0
166
+ ```
167
+
168
+ `every` triggers following a given frequency:
169
+
170
+ ``` yaml
171
+ every: '45m' # Runs every 45 minutes
172
+ ```
173
+
174
+ The value is parsed by [`Fugit::Duration.parse`](https://github.com/floraison/fugit#fugitduration). It understands quite a number of formats, including human-readable ones:
175
+
176
+ ``` yaml
177
+ every: 45 minutes
178
+ every: 2 hours and 30 minutes
179
+ every: 1.5 hours
180
+ ```
181
+
182
+ `interval` is similar to `every`, the difference between them is that `interval` type schedules the
183
+ next execution after the interval has elapsed counting from its last job enqueue.
184
+
185
+ Note that `every` and `interval` count from when the Sidekiq process (re)starts. So `every: '48h'` will never run if the Sidekiq process is restarted daily, for example. You can do `every: ['48h', first_in: '0s']` to make the job run immediately after a restart, and then have the worker check when it was last run.
186
+
187
+ At, and in types push jobs only once. `at` schedules in a point in time:
188
+ ``` yaml
189
+ at: '3001/01/01'
190
+ ```
191
+
192
+ You can specify any string that `DateTime.parse` and `Chronic` understand. To enable Chronic
193
+ strings, you must add it as a dependency.
194
+
195
+ `in` triggers after a time duration has elapsed:
196
+
197
+ ``` yaml
198
+ in: 1h # pushes a sidekiq job in 1 hour, after start-up
199
+ ```
200
+
201
+ You can provide options to `every` or `cron` via an Array:
202
+
203
+ ``` yaml
204
+ every: ['30s', first_in: '120s']
205
+ ```
206
+
207
+ See https://github.com/jmettraux/rufus-scheduler for more information.
208
+
209
+ ## Load the schedule from a different file
210
+
211
+ You can place the schedule configuration in a separate file from `config/sidekiq.yml`
212
+
213
+ ``` yaml
214
+ # sidekiq_scheduler.yml
215
+
216
+ clear_leaderboards_contributors:
217
+ cron: '0 30 6 * * 1'
218
+ class: ClearLeaderboards
219
+ queue: low
220
+ args: contributors
221
+ description: 'This job resets the weekly leaderboard for contributions'
222
+ ```
223
+
224
+ Please notice that the `schedule` root key is not present in the separate file.
225
+
226
+ To load the schedule:
227
+
228
+ ``` ruby
229
+ require 'sidekiq'
230
+ require 'sidekiq-scheduler'
231
+
232
+ Sidekiq.configure_server do |config|
233
+ config.on(:startup) do
234
+ Sidekiq.schedule = YAML.load_file(File.expand_path('../../sidekiq_scheduler.yml', __FILE__))
235
+ SidekiqScheduler::Scheduler.instance.reload_schedule!
236
+ end
237
+ end
238
+ ```
239
+
240
+ The above code can be placed in an initializer (in `config/initializers`) that runs every time the app starts up.
241
+
242
+ ## Dynamic schedule
243
+
244
+ The schedule can be modified after startup. To add / update a schedule, you have to:
245
+
246
+ ``` ruby
247
+ Sidekiq.set_schedule('heartbeat', { 'every' => ['1m'], 'class' => 'HeartbeatWorker' })
248
+ ```
249
+
250
+ If the schedule did not exist it will be created, if it existed it will be updated.
251
+
252
+ When `:dynamic` flag is set to `true`, schedule changes are loaded every 5 seconds. Use the `:dynamic_every` flag for a different interval.
253
+
254
+ ``` yaml
255
+ # config/sidekiq.yml
256
+ :scheduler:
257
+ :dynamic: true
258
+ ```
259
+
260
+ If `:dynamic` flag is set to `false`, you'll have to reload the schedule manually in sidekiq
261
+ side:
262
+
263
+ ``` ruby
264
+ SidekiqScheduler::Scheduler.instance.reload_schedule!
265
+ ```
266
+
267
+ Invoke `Sidekiq.get_schedule` to obtain the current schedule:
268
+
269
+ ``` ruby
270
+ Sidekiq.get_schedule
271
+ # => { 'every' => '1m', 'class' => 'HardWorker' }
272
+ ```
273
+
274
+ ## Time zones
275
+
276
+ Note that if you use the cron syntax and are not running a Rails app, this will be interpreted in the server time zone.
277
+
278
+ In a Rails app, [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) (>= 3.3.3) will use the `config.time_zone` specified in Rails.
279
+
280
+ You can explicitly specify the time zone that rufus-scheduler will use:
281
+
282
+ ``` yaml
283
+ cron: '0 30 6 * * 1 Europe/Stockholm'
284
+ ```
285
+
286
+ Also note that `config.time_zone` in Rails allows for a shorthand (e.g. "Stockholm")
287
+ that rufus-scheduler does not accept. If you write code to set the scheduler time zone
288
+ from the `config.time_zone` value, make sure it's the right format, e.g. with:
289
+
290
+ ``` ruby
291
+ ActiveSupport::TimeZone.find_tzinfo(Rails.configuration.time_zone).name
292
+ ```
293
+
294
+ ## Notes about connection pooling
295
+
296
+ If you're configuring your own Redis connection pool, you need to make sure the size is adequate to be inclusive of both Sidekiq's own connection pool and Rufus Scheduler's.
297
+
298
+ That's a minimum of `concurrency` + 5 (per the [Sidekiq wiki](https://github.com/mperham/sidekiq/wiki/Using-Redis#complete-control)) + `Rufus::Scheduler::MAX_WORK_THREADS` (28 as of this writing; per the [Rufus README](https://github.com/jmettraux/rufus-scheduler#max_work_threads)), for a total of 58 with the default `concurrency` of 25.
299
+
300
+ You can also override the thread pool size in Rufus Scheduler by setting the following in your `sidekiq.yml` config:
301
+
302
+ ```yaml
303
+ ---
304
+ ...
305
+
306
+ :scheduler:
307
+ rufus_scheduler_options:
308
+ max_work_threads: 5
309
+
310
+ ...
311
+ ```
312
+
313
+ ## Notes about running on Multiple Hosts
314
+
315
+ Under normal conditions, `cron` and `at` jobs are pushed once regardless of the number of `sidekiq-scheduler` running instances,
316
+ assumming that time deltas between hosts is less than 24 hours.
317
+
318
+ Non-normal conditions that could push a specific job multiple times are:
319
+ - high cpu load + a high number of jobs scheduled at the same time, like 100 jobs
320
+ - network / redis latency + 28 (see `MAX_WORK_THREADS` https://github.com/jmettraux/rufus-scheduler/blob/master/lib/rufus/scheduler.rb#L41) or more jobs scheduled within the same network latency window
321
+
322
+ `every`, `interval` and `in` jobs will be pushed once per host.
323
+
324
+ ### Suggested setup for Multiple Hosts using Heroku and Rails
325
+
326
+ 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.
327
+
328
+ 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.
329
+
330
+ Suppose we are using Rails and have the following schedule:
331
+
332
+ ```yaml
333
+ # config/scheduler.yml
334
+ MyRegularJob:
335
+ description: "We want this job to run very often, but we do not want to run more of them as we scale"
336
+ interval: ["1m"]
337
+ queue: default
338
+ ```
339
+
340
+ Then we can conditionally load it via an initializer:
341
+
342
+ ```ruby
343
+ # config/initializer/sidekiq.rb
344
+ if ENV.fetch("IS_SCHEDULER", false)
345
+ Sidekiq.configure_server do |config|
346
+ config.on(:startup) do
347
+ Sidekiq.schedule = YAML.load_file(File.expand_path("../scheduler.yml", File.dirname(__FILE__)))
348
+ Sidekiq::Scheduler.reload_schedule!
349
+ end
350
+ end
351
+ end
352
+ ```
353
+
354
+ 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:
355
+
356
+ ```yaml
357
+ # Procfile
358
+ web: bin/rails server
359
+ worker: bundle exec sidekiq -q default
360
+ scheduler: IS_SCHEDULER=true bundle exec sidekiq -q default
361
+ ```
362
+
363
+ 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.
364
+
365
+ ## Notes on when Sidekiq worker is down
366
+
367
+ 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.
368
+
369
+ Possible solutions include:
370
+ - Simply ignoring this fact, if you only run frequent periodic jobs, that can tolerate some increased interval
371
+ - Abstaining from deploys/restarts during time when critical jobs are usually scheduled
372
+ - Making your infrequent jobs idempotent (so that they can be enqueued multiple times but still produce result as if was run once) and scheduling them multiple times to reduce likelihood of not being run
373
+ - Zero downtime deploy for sidekiq workers: keep at least one worker up during whole deploy and only restart/shut it down after when new one has started
374
+ - Running scheduler inside your unicorn/rails processes (if you already have zero downtime deploy set up for these)
375
+
376
+ Each option has it's own pros and cons.
377
+
378
+ ## Notes when running multiple Sidekiq processors on the same Redis
379
+
380
+ ### TL;DR
381
+
382
+ Be **sure** to include the `:enabled: false` top-level key on any additional
383
+ configurations to avoid any possibility of the `schedules` definition being
384
+ wiped by the second Sidekiq process.
385
+
386
+ To illustrate what we mean:
387
+
388
+ Say you have one process with the schedule:
389
+ ```yaml
390
+ # e.g., config/sidekiq.yml
391
+
392
+ :queues:
393
+ - default
394
+ :scheduler:
395
+ :schedule:
396
+ do_something_every_minute:
397
+ class: DoSomethingJob
398
+ args: matey
399
+ queue: :scheduler
400
+ cron: '0 * * * * * America/Los_Angeles'
401
+ ```
402
+
403
+ And a separate separate configured process without one:
404
+ ```yaml
405
+ # e.g., config/sidekiq_other.yml
406
+ :queues:
407
+ - scheduler
408
+
409
+ ## NOTE Disable the Scheduler
410
+ :scheduler:
411
+ :enabled: false
412
+ ```
413
+
414
+ ### Details
415
+
416
+ This gem stores the configured schedule in Redis on boot. It's used, primarily,
417
+ to display in the Web Integration, and allow you to interact with that schedule
418
+ via that integration.
419
+
420
+ If you're running multiple Sidekiq processes on the same Redis namespace with
421
+ different configurations, **you'll want to explicitly _disable_ Sidekiq
422
+ Scheduler** for the other processes not responsible for the schedule. If you
423
+ don't, the last booted Sidekiq processes' schedule will be what is stored in
424
+ Redis.
425
+
426
+ See https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/361 for a more details.
427
+
428
+ ## Notes when running multiple applications in the same Redis database
429
+
430
+ _NOTE_: **Although we support this option, we recommend having separate redis databases for each application. Choosing this option is at your own risk.**
431
+
432
+ 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.
433
+
434
+ 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.
435
+
436
+ ```ruby
437
+ Rails.application.reloader.to_prepare do
438
+ SidekiqScheduler::RedisManager.key_prefix = "my-app"
439
+ end
440
+ ```
441
+
442
+ 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.
443
+
444
+ ## Sidekiq Web Integration
445
+
446
+ sidekiq-scheduler provides an extension to the Sidekiq web interface that adds a `Recurring Jobs` page.
447
+
448
+ ``` ruby
449
+ # config.ru
450
+
451
+ require 'sidekiq/web'
452
+ require 'sidekiq-scheduler/web'
453
+
454
+ run Sidekiq::Web
455
+ ```
456
+
457
+ ![Sidekiq Web Integration](https://github.com/sidekiq-scheduler/sidekiq-scheduler/raw/master/images/recurring-jobs-ui-tab.png)
458
+
459
+ ## ActiveJob integration
460
+
461
+ When using sidekiq-scheduler with ActiveJob your jobs can just extend `ApplicationJob` as usual, without the `require` and `include` boilerplate. Under the hood Rails will load up the scheduler and include the worker module for you.
462
+
463
+ ```rb
464
+ class HelloWorld < ApplicationJob
465
+ def perform
466
+ puts 'Hello world'
467
+ end
468
+ end
469
+ ```
470
+
471
+ ## The Spring preloader and Testing your initializer via Rails console
472
+
473
+ 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 interefere with testing via the Rails console.
474
+
475
+ **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.
476
+
477
+ To see your updated schedule, be sure to reload Spring by stopping it prior to booting the Rails console.
478
+
479
+ Run `spring stop` to stop Spring.
480
+
481
+ For more information, see [this issue](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/35#issuecomment-48067183) and [Spring's README](https://github.com/rails/spring/blob/master/README.md).
482
+
483
+
484
+ ## Manage tasks from Unicorn/Rails server
485
+
486
+ If you want start sidekiq-scheduler only from Unicorn/Rails, but not from sidekiq you can have
487
+ something like this in an initializer:
488
+
489
+ ``` ruby
490
+ # config/initializers/sidekiq_scheduler.rb
491
+ require 'sidekiq'
492
+ require 'sidekiq-scheduler'
493
+
494
+ puts "Sidekiq.server? is #{Sidekiq.server?.inspect}"
495
+ puts "defined?(Rails::Server) is #{defined?(Rails::Server).inspect}"
496
+ puts "defined?(Unicorn) is #{defined?(Unicorn).inspect}"
497
+
498
+ if Rails.env == 'production' && (defined?(Rails::Server) || defined?(Unicorn))
499
+ Sidekiq.configure_server do |config|
500
+
501
+ config.on(:startup) do
502
+ Sidekiq.schedule = YAML.load_file(File.expand_path('../../scheduler.yml', __FILE__))
503
+ SidekiqScheduler::Scheduler.instance.reload_schedule!
504
+ end
505
+ end
506
+ else
507
+ SidekiqScheduler::Scheduler.instance.enabled = false
508
+ puts "SidekiqScheduler::Scheduler.instance.enabled is #{SidekiqScheduler::Scheduler.instance.enabled.inspect}"
509
+ end
510
+ ```
511
+
512
+ ## License
513
+
514
+ MIT License
515
+
516
+ ## Copyright
517
+
518
+ - Copyright 2021 - 2022 Marcelo Lauxen.
519
+ - Copyright 2013 - 2022 Moove-IT.
520
+ - Copyright 2012 Morton Jonuschat.
521
+ - Some parts copyright 2010 Ben VandenBos.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SidekiqScheduler'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rspec/core/rake_task'
26
+
27
+ RSpec::Core::RakeTask.new('spec')
28
+
29
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ require 'sidekiq-scheduler/scheduler'
2
+
3
+ Sidekiq::Scheduler = SidekiqScheduler::Scheduler