sidekiq-cron 1.12.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaa6af217265c4e60b29018b984b43a4316b2618e52ce874db670e41ecadf85b
4
- data.tar.gz: f70a50a90508ceb32bad90b8b2b6a880fb460f308dfa81f7380152742bb939cf
3
+ metadata.gz: e256288ae9e2ffd550dfd47aa2d2776cb75edff89c2c7605bbd11685afba79b2
4
+ data.tar.gz: 84eded49d6d3e3da996a73902daf9f27010394b334c769fdebad789acdc006c9
5
5
  SHA512:
6
- metadata.gz: ef95b33d15c1867a3dc6cc096080af6f2fab50c4460d8be24948bcd887c6c278dc3ca1a8c92db8d1ce386d24e0ceb95f53f6add336c3315fec04f808b7451475
7
- data.tar.gz: e30e02e3bcc13f8604426d5d9e5f30e24c46a85bfd7679544975a3bdfcc0510631d363ef041f948c8a51e289a02a222fd27bba572cf57ac1697aabb917673a01
6
+ metadata.gz: a329899c823ee69c96a8849eddb5abcfac3d99d5ac0003e2066f7e919c3bc25fa071518d0fe98c308d75d9076925ca22ec77c1fbc66acd1d740f14086c4c6a97
7
+ data.tar.gz: 917fd615b9855cfa55a90624be4769febc0de1d7e0012f928471f1ba5fa1aa543a39a212b8cd725f6be8eeb7d7494df5a3fb74b532abb8a5d970563ceb3b8da6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,64 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 2.3.0
6
+
7
+ - **WARNING** The default value for `available_namespaces` has changed from `nil` to `[default_namespace]`. Please refer to the [migration guide](https://github.com/sidekiq-cron/sidekiq-cron/blob/master/README.md#migrating-to-23) for further details (https://github.com/sidekiq-cron/sidekiq-cron/pull/552)
8
+ - Fix deprecation warning for using raw params in WEB extension (https://github.com/sidekiq-cron/sidekiq-cron/pull/547)
9
+ - Allow for sidekiq embedded configuration (https://github.com/sidekiq-cron/sidekiq-cron/pull/549)
10
+ - Load schedule file within sidekiq callback (https://github.com/sidekiq-cron/sidekiq-cron/pull/550)
11
+ - Fix missing default namespace if namespaces are explicitly provided (https://github.com/sidekiq-cron/sidekiq-cron/pull/551)
12
+
13
+ ## 2.2.0
14
+
15
+ - Add support for Sidekiq v8 (https://github.com/sidekiq-cron/sidekiq-cron/pull/531, https://github.com/sidekiq-cron/sidekiq-cron/pull/538)
16
+ - Always show parsed cron expression in web UI (https://github.com/sidekiq-cron/sidekiq-cron/pull/535)
17
+ - Add fallback to .yaml extension (https://github.com/sidekiq-cron/sidekiq-cron/pull/534)
18
+ - Refactor constantize helper to use Object.const_get (https://github.com/sidekiq-cron/sidekiq-cron/pull/541)
19
+ - Allow testing of schedule by library consumers (https://github.com/sidekiq-cron/sidekiq-cron/pull/543)
20
+
21
+ ## 2.1.0
22
+
23
+ - Add `available_namespaces` configuration option (https://github.com/sidekiq-cron/sidekiq-cron/pull/524)
24
+ - I18n fixes and enhancements (https://github.com/sidekiq-cron/sidekiq-cron/pull/520, https://github.com/sidekiq-cron/sidekiq-cron/pull/522)
25
+
26
+ ## 2.0.1
27
+
28
+ - Fix usage of ActiveJob::Base.queue_name (https://github.com/sidekiq-cron/sidekiq-cron/pull/517)
29
+ - Fix: Add quotes to Japanese translations containing multi-byte symbols (https://github.com/sidekiq-cron/sidekiq-cron/pull/515)
30
+
31
+ ## 2.0.0
32
+
33
+ Sidekiq-Cron v2 is here! In this release we refactored some internals, plus:
34
+
35
+ - Review web UI translations for all available locales (https://github.com/sidekiq-cron/sidekiq-cron/pull/506)
36
+ - Fix detection of ActiveJob in Sidekiq v7.3.3+ (https://github.com/sidekiq-cron/sidekiq-cron/pull/510)
37
+ - Add retry job configuration option to set Sidekiq retry job option (https://github.com/sidekiq-cron/sidekiq-cron/pull/509)
38
+
39
+ Please take a look to the RC1 and RC2 changes too if you are coming from the v1.X series.
40
+
41
+ ## 2.0.0.rc2
42
+
43
+ - Remove support for Sidekiq < 6.5 (https://github.com/sidekiq-cron/sidekiq-cron/pull/480)
44
+ - Require at least Fugit >= 1.11.1 (https://github.com/sidekiq-cron/sidekiq-cron/pull/475)
45
+ - Update how Redis values are stored on save (https://github.com/sidekiq-cron/sidekiq-cron/pull/479)
46
+ - Web extension: Add compatibility with Sidekiq 7.3+ and remove inline styles (https://github.com/sidekiq-cron/sidekiq-cron/pull/480)
47
+ - Remove support for old Redis (< 4.2) (https://github.com/sidekiq-cron/sidekiq-cron/pull/490)
48
+ - Ensure date_as_argument option can be set from true to false in Sidekiq Cron jobs (https://github.com/sidekiq-cron/sidekiq-cron/pull/485)
49
+ - Rename `enque!` to `enqueue!` (https://github.com/sidekiq-cron/sidekiq-cron/pull/494)
50
+ - Refactor gem configuration module (https://github.com/sidekiq-cron/sidekiq-cron/pull/495)
51
+
52
+ ## 2.0.0.rc1
53
+
54
+ - Introduce `Namespacing` (https://github.com/sidekiq-cron/sidekiq-cron/pull/268)
55
+ - Human readable cron format in UI (https://github.com/sidekiq-cron/sidekiq-cron/pull/445)
56
+ - Add Bahasa Indonesia locale (https://github.com/sidekiq-cron/sidekiq-cron/pull/446)
57
+ - Fetch queue name from ActiveJob class (https://github.com/sidekiq-cron/sidekiq-cron/pull/448)
58
+ - Allows symbol keys in `.load_from_array!` (https://github.com/sidekiq-cron/sidekiq-cron/pull/458)
59
+ - Add natural language parsing mode (https://github.com/sidekiq-cron/sidekiq-cron/pull/459)
60
+ - Add ability to configure the past scheduled time threshold (https://github.com/sidekiq-cron/sidekiq-cron/pull/465)
61
+ - Docs: clarify worker vs process terminology (https://github.com/sidekiq-cron/sidekiq-cron/issues/453)
62
+
5
63
  ## 1.12.0
6
64
 
7
65
  - Remove Sidekiq.server? check from schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/436)
@@ -61,7 +119,7 @@ All notable changes to this project will be documented in this file.
61
119
 
62
120
  ## 1.5.1
63
121
 
64
- - Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
122
+ - Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
65
123
 
66
124
  ## 1.5.0
67
125
 
@@ -156,6 +214,6 @@ All notable changes to this project will be documented in this file.
156
214
 
157
215
  ## 0.3.0
158
216
 
159
- - Suport for Active Job
217
+ - Support for Active Job
160
218
  - Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
161
219
  - Add load_from_hash! and load_from_array! which cleanup jobs before adding new ones
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ gemspec
4
4
 
5
5
  # To test different Sidekiq versions
6
6
  gem "sidekiq", ENV.fetch("SIDEKIQ_VERSION", ">= 6")
7
+
8
+ # To test different Rails versions
9
+ gem "rails", ENV.fetch("RAILS_VERSION", "~> 7")
data/README.md CHANGED
@@ -1,25 +1,21 @@
1
1
  ![Sidekiq-Cron](logos/cover.png)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/sidekiq-cron.svg)](https://badge.fury.io/rb/sidekiq-cron)
4
- [![Build Status](https://github.com/sidekiq-cron/sidekiq-cron/workflows/CI/badge.svg?branch=master)](https://github.com/sidekiq-cron/sidekiq-cron/actions)
4
+ [![CI](https://github.com/sidekiq-cron/sidekiq-cron/actions/workflows/ci.yml/badge.svg)](https://github.com/sidekiq-cron/sidekiq-cron/actions/workflows/ci.yml)
5
5
  [![codecov](https://codecov.io/gh/sidekiq-cron/sidekiq-cron/branch/master/graph/badge.svg?token=VK9IVLIaY8)](https://codecov.io/gh/sidekiq-cron/sidekiq-cron)
6
6
 
7
7
  > A scheduling add-on for [Sidekiq](https://sidekiq.org/)
8
8
 
9
9
  🎬 [Introduction video about Sidekiq-Cron by Drifting Ruby](https://www.driftingruby.com/episodes/periodic-tasks-with-sidekiq-cron)
10
10
 
11
- Sidekiq-Cron runs a thread alongside Sidekiq workers to schedule jobs at specified times (using cron notation `* * * * *` parsed by [Fugit](https://github.com/floraison/fugit)).
11
+ Sidekiq-Cron runs a thread alongside Sidekiq workers to schedule jobs at specified times (using cron notation `* * * * *` or natural language, powered by [Fugit](https://github.com/floraison/fugit)).
12
12
 
13
- Checks for new jobs to schedule every 30 seconds and doesn't schedule the same job multiple times when more than one Sidekiq worker is running.
13
+ Checks for new jobs to schedule every 30 seconds and doesn't schedule the same job multiple times when more than one Sidekiq process is running.
14
14
 
15
15
  Scheduling jobs are added only when at least one Sidekiq process is running, but it is safe to use Sidekiq-Cron in environments where multiple Sidekiq processes or nodes are running.
16
16
 
17
17
  If you want to know how scheduling work, check out [under the hood](#under-the-hood).
18
18
 
19
- Works with ActiveJob (Rails 4.2+).
20
-
21
- You don't need Sidekiq PRO, you can use this gem with plain Sidekiq.
22
-
23
19
  ## Changelog
24
20
 
25
21
  Before upgrading to a new version, please read our [Changelog](CHANGELOG.md).
@@ -51,18 +47,40 @@ gem "sidekiq-cron"
51
47
  'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, ...
52
48
  'class' => 'MyClass',
53
49
  # OPTIONAL
50
+ 'namespace' => 'YourNamespace', # groups jobs together in a namespace (Default value is 'default'),
54
51
  'source' => 'dynamic', # source of the job, `schedule`/`dynamic` (default: `dynamic`)
55
52
  'queue' => 'name of queue',
53
+ 'retry' => '5', # Sidekiq (not supported by ActiveJob) number of retries, or false to discard on first failure
56
54
  'args' => '[Array or Hash] of arguments which will be passed to perform method',
57
55
  'date_as_argument' => true, # add the time of execution as last argument of the perform method
58
- 'active_job' => true, # enqueue job through Rails 4.2+ Active Job interface
59
- 'queue_name_prefix' => 'prefix', # Rails 4.2+ Active Job queue with prefix
60
- 'queue_name_delimiter' => '.', # Rails 4.2+ Active Job queue with custom delimiter (default: '_')
61
- 'description' => 'A sentence describing what work this job performs'
56
+ 'active_job' => true, # enqueue job through Active Job interface
57
+ 'queue_name_prefix' => 'prefix', # Active Job queue with prefix
58
+ 'queue_name_delimiter' => '.', # Active Job queue with custom delimiter (default: '_')
59
+ 'description' => 'A sentence describing what work this job performs',
62
60
  'status' => 'disabled' # default: enabled
63
61
  }
64
62
  ```
65
63
 
64
+ **NOTE** The `status` of a job does not get changed in Redis when a job gets reloaded unless the `status` property is explicitly set.
65
+
66
+ ### Configuration
67
+
68
+ All configuration options:
69
+
70
+ ```ruby
71
+ Sidekiq::Cron.configure do |config|
72
+ config.cron_poll_interval = 10 # Default is 30
73
+ config.cron_schedule_file = 'config/my_schedule.yml' # Default is 'config/schedule.yml'
74
+ config.cron_history_size = 20 # Default is 10
75
+ config.default_namespace = 'statistics' # Default is 'default'
76
+ config.available_namespaces = %w[statistics maintenance billing] # Default is `[config.default_namespace]`
77
+ config.natural_cron_parsing_mode = :strict # Default is :single
78
+ config.reschedule_grace_period = 300 # Default is 60
79
+ end
80
+ ```
81
+
82
+ If you are using Rails, you should add the above block inside an initializer (`config/initializers/sidekiq-cron.rb`).
83
+
66
84
  ### Time, cron and Sidekiq-Cron
67
85
 
68
86
  For testing your cron notation you can use [crontab.guru](https://crontab.guru).
@@ -76,18 +94,50 @@ like this `'0 22 * * 1-5 America/Chicago'`.
76
94
 
77
95
  #### Natural-language formats
78
96
 
79
- Since sidekiq-cron `v1.7.0`, you can use the natural-language formats supported by Fugit, such as:
97
+ Since Sidekiq-Cron `v1.7.0`, you can use the natural-language formats supported by Fugit, such as:
80
98
 
81
- ```rb
99
+ ```ruby
82
100
  "every day at five" # => '0 5 * * *'
83
101
  "every 3 hours" # => '0 */3 * * *'
84
102
  ```
85
103
 
86
104
  See [the relevant part of Fugit documentation](https://github.com/floraison/fugit#fugitnat) for details.
87
105
 
106
+ There are multiple modes that determine how natural-language cron strings will be parsed.
107
+
108
+ 1. `:single` (default)
109
+
110
+ ```ruby
111
+ Sidekiq::Cron.configure do |config|
112
+ # Note: This doesn't need to be specified since it's the default.
113
+ config.natural_cron_parsing_mode = :single
114
+ end
115
+ ```
116
+
117
+ This parses the first possible cron line from the given string and then ignores any additional cron lines.
118
+
119
+ Ex. `every day at 3:15 and 4:30`
120
+
121
+ - Equivalent to `15 3 * * *`.
122
+ - `30 4 * * *` gets ignored.
123
+
124
+ 2. `:strict`
125
+
126
+ ```ruby
127
+ Sidekiq::Cron.configure do |config|
128
+ config.natural_cron_parsing_mode = :strict
129
+ end
130
+ ```
131
+
132
+ This throws an error if the given string would be parsed into multiple cron lines.
133
+
134
+ Ex. `every day at 3:15 and 4:30`
135
+
136
+ - Would throw an error and the associated cron job would be invalid
137
+
88
138
  #### Second-precision (sub-minute) cronlines
89
139
 
90
- In addition to the standard 5-parameter cronline format, sidekiq-cron supports scheduling jobs with second-precision using a modified 6-parameter cronline format:
140
+ In addition to the standard 5-parameter cronline format, Sidekiq-Cron supports scheduling jobs with second-precision using a modified 6-parameter cronline format:
91
141
 
92
142
  `Seconds Minutes Hours Days Months DayOfWeek`
93
143
 
@@ -96,11 +146,93 @@ For example: `"*/30 * * * * *"` would schedule a job to run every 30 seconds.
96
146
  Note that if you plan to schedule jobs with second precision you may need to override the default schedule poll interval so it is lower than the interval of your jobs:
97
147
 
98
148
  ```ruby
99
- Sidekiq::Options[:cron_poll_interval] = 10
149
+ Sidekiq::Cron.configure do |config|
150
+ config.cron_poll_interval = 10
151
+ end
100
152
  ```
101
153
 
102
154
  The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
103
155
 
156
+ ### Namespacing
157
+
158
+ #### Default namespace
159
+
160
+ When not giving a namespace, the `default` one will be used.
161
+
162
+ In the case you'd like to change this value, you can change it via the following configuration flag:
163
+
164
+ ```ruby
165
+ Sidekiq::Cron.configure do |config|
166
+ config.default_namespace = 'statistics'
167
+ end
168
+ ```
169
+
170
+ #### Renaming namespace
171
+
172
+ If you rename the namespace of a job that is already running, the gem will not automatically delete the cron job associated with the old namespace. This means you could end up with two cron jobs running simultaneously.
173
+
174
+ To avoid this, it is recommended to delete all existing cron jobs associated with the old namespace before making the change. You can achieve this with the following code:
175
+
176
+ ```ruby
177
+ Sidekiq::Cron::Job.all('YOUR_OLD_NAMESPACE_NAME').each { |job| job.destroy }
178
+ ```
179
+
180
+ #### Available namespaces
181
+
182
+ By default, Sidekiq Cron uses the available_namespaces configuration option to determine which namespaces your application utilizes. The default namespace (`"default"`, by default) is always included in the list of available namespaces.
183
+
184
+ If you want Sidekiq Cron to automatically detect existing namespaces from the Redis database, you can set `available_namespaces` to the special option `:auto`.
185
+
186
+ If available_namespaces is explicitly set and a job is created with an unexpected namespace, a warning will be printed, and the job will be assigned to the default namespace.
187
+
188
+ #### Migrating to 2.3
189
+
190
+ As discussed in [this issue](https://github.com/sidekiq-cron/sidekiq-cron/issues/516), the approach introduced in Sidekiq Cron 2.0 for determining available namespaces using the `KEYS` command is not acceptable. Therefore, starting from version 2.3, namespacing has been reworked:
191
+
192
+ - If you were not using the namespacing feature, no action is required. You can even remove `available_namespaces = %w[default]`, as it is now the default.
193
+
194
+ - If you were using the namespacing feature and explicitly specified available namespaces as a list, no changes are needed.
195
+
196
+ - If you were using the namespacing feature and relied on automatic namespace inference, you should either specify all used namespaces explicitly or set `available_namespaces` to `:auto` to maintain automatic detection. However, note that this approach does not scale well (see the referenced issue for details).
197
+
198
+ #### Usage
199
+
200
+ When creating a new job, you can optionally give a `namespace` attribute, and then you can pass it too in the `find` or `destroy` methods.
201
+
202
+ ```ruby
203
+ Sidekiq::Cron::Job.create(
204
+ name: 'Hard worker - every 5min',
205
+ namespace: 'Foo',
206
+ cron: '*/5 * * * *',
207
+ class: 'HardWorker'
208
+ )
209
+ # INFO: Cron Jobs - add job with name Hard worker - every 5min in the namespace Foo
210
+
211
+ # Without specifying the namespace, Sidekiq::Cron use the `default` one, therefore `count` return 0.
212
+ Sidekiq::Cron::Job.count
213
+ #=> 0
214
+
215
+ # Searching in the job's namespace returns 1.
216
+ Sidekiq::Cron::Job.count 'Foo'
217
+ #=> 1
218
+
219
+ # Same applies to `all`. Without a namespace, no jobs found.
220
+ Sidekiq::Cron::Job.all
221
+
222
+ # But giving the job's namespace returns it.
223
+ Sidekiq::Cron::Job.all 'Foo'
224
+ #=> [#<Sidekiq::Cron::Job:0x00007f7848a326a0 ... @name="Hard worker - every 5min", @namespace="Foo", @cron="*/5 * * * *", @klass="HardWorker", @status="enabled" ... >]
225
+
226
+ # If you'd like to get all the jobs across all the namespaces then pass an asterisk:
227
+ Sidekiq::Cron::Job.all '*'
228
+ #=> [#<Sidekiq::Cron::Job ...>]
229
+
230
+ job = Sidekiq::Cron::Job.find('Hard worker - every 5min', 'Foo').first
231
+ job.destroy
232
+ # INFO: Cron Jobs - deleted job with name Hard worker - every 5min from namespace Foo
233
+ #=> true
234
+ ```
235
+
104
236
  ### What objects/classes can be scheduled
105
237
 
106
238
  #### Sidekiq Worker
@@ -117,7 +249,9 @@ class HardWorker
117
249
  end
118
250
  ```
119
251
 
120
- #### Active Job Worker
252
+ For Sidekiq workers, `symbolize_args: true` in `Sidekiq::Cron::Job.create` or in Hash configuration is gonna be ignored as Sidekiq currently only allows for [simple JSON datatypes](https://github.com/sidekiq/sidekiq/wiki/The-Basics#:~:text=These%20two%20methods,not%20serialize%20properly.).
253
+
254
+ #### Active Job
121
255
 
122
256
  You can schedule `ExampleJob` which looks like:
123
257
 
@@ -131,10 +265,10 @@ class ExampleJob < ActiveJob::Base
131
265
  end
132
266
  ```
133
267
 
134
- For Active jobs you can use `symbolize_args: true` in `Sidekiq::Cron::Job.create` or in Hash configuration,
268
+ For Active Job you can use `symbolize_args: true` in `Sidekiq::Cron::Job.create` or in Hash configuration,
135
269
  which will ensure that arguments you are passing to it will be symbolized when passed back to `perform` method in worker.
136
270
 
137
- #### Adding Cron job
271
+ ### Adding Cron jobs
138
272
 
139
273
  Refer to [Schedule vs Dynamic jobs](#schedule-vs-dynamic-jobs) to understand the difference.
140
274
 
@@ -168,9 +302,9 @@ unless job.save
168
302
  end
169
303
  ```
170
304
 
171
- Use ActiveRecord models as arguments
305
+ Use ActiveRecord models as arguments:
172
306
 
173
- ```rb
307
+ ```ruby
174
308
  class Person < ApplicationRecord
175
309
  end
176
310
 
@@ -182,7 +316,6 @@ class HardWorker < ActiveJob::Base
182
316
  end
183
317
  end
184
318
 
185
-
186
319
  person = Person.create(id: 1)
187
320
  Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker', args: person)
188
321
  # => true
@@ -233,7 +366,9 @@ Sidekiq::Cron::Job.load_from_hash! hash
233
366
  Sidekiq::Cron::Job.load_from_array! array
234
367
  ```
235
368
 
236
- Or from YAML (same notation as Resque-scheduler):
369
+ ### Loading jobs from schedule file
370
+
371
+ You can also load multiple jobs from a YAML file:
237
372
 
238
373
  ```yaml
239
374
  # config/schedule.yml
@@ -254,24 +389,31 @@ second_job:
254
389
  There are multiple ways to load the jobs from a YAML file
255
390
 
256
391
  1. The gem will automatically load the jobs mentioned in `config/schedule.yml` file (it supports ERB)
257
- 2. When you want to load jobs from a different filename, mention the filename in sidekiq configuration, i.e. `cron_schedule_file: "config/users_schedule.yml"`
392
+ 2. When you want to load jobs from a different filename, mention the filename in Sidekiq configuration as follows:
393
+
394
+ ```ruby
395
+ Sidekiq::Cron.configure do |config|
396
+ config.cron_schedule_file = "config/users_schedule.yml"
397
+ end
398
+ ```
399
+
258
400
  3. Load the file manually as follows:
259
401
 
260
- ```ruby
261
- # config/initializers/sidekiq.rb
402
+ ```ruby
403
+ # config/initializers/sidekiq.rb
262
404
 
263
- Sidekiq.configure_server do |config|
264
- config.on(:startup) do
265
- schedule_file = "config/users_schedule.yml"
405
+ Sidekiq.configure_server do |config|
406
+ config.on(:startup) do
407
+ schedule_file = "config/users_schedule.yml"
266
408
 
267
- if File.exist?(schedule_file)
268
- schedule = YAML.load_file(schedule_file)
409
+ if File.exist?(schedule_file)
410
+ schedule = YAML.load_file(schedule_file)
269
411
 
270
- Sidekiq::Cron::Job.load_from_hash!(schedule, source: "schedule")
412
+ Sidekiq::Cron::Job.load_from_hash!(schedule, source: "schedule")
413
+ end
414
+ end
271
415
  end
272
- end
273
- end
274
- ```
416
+ ```
275
417
 
276
418
  ### Finding jobs
277
419
 
@@ -317,7 +459,7 @@ job.status
317
459
  # => enabled/disabled
318
460
 
319
461
  # enqueue job right now!
320
- job.enque!
462
+ job.enqueue!
321
463
  ```
322
464
 
323
465
  ### Schedule vs Dynamic jobs
@@ -356,12 +498,67 @@ Sidekiq-Cron adds itself into this start procedure and starts another thread wit
356
498
  Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
357
499
 
358
500
  ```ruby
359
- Sidekiq::Options[:cron_poll_interval] = 10
501
+ Sidekiq::Cron.configure do |config|
502
+ config.cron_poll_interval = 10
503
+ end
504
+ ```
505
+
506
+ When Sidekiq (and Sidekiq-Cron) is not used in zero-downtime deployments, after the deployment is done Sidekiq-Cron starts to catch up. It will consider older jobs that missed their schedules during that time. By default, only jobs that should have started less than 1 minute ago are considered. This is problematic for some jobs, e.g., jobs that run once a day. If on average Sidekiq is shut down for 10 minutes during deployments, you can configure Sidekiq-Cron to consider jobs that were about to be scheduled during that time:
507
+
508
+ ```ruby
509
+ Sidekiq::Cron.configure do |config|
510
+ config.reschedule_grace_period = 600 # 10 minutes in seconds
511
+ end
360
512
  ```
361
513
 
362
514
  Sidekiq-Cron is safe to use with multiple Sidekiq processes or nodes. It uses a Redis sorted set to determine that only the first process who asks can enqueue scheduled jobs into the queue.
363
515
 
364
- When running with many Sidekiq processes, the polling can add significant load to Redis. You can disable polling on some processes by setting `Sidekiq::Options[:cron_poll_interval] = 0` on these processes.
516
+ When running with many Sidekiq processes, the polling can add significant load to Redis. You can disable polling on some processes by setting:
517
+
518
+ ```ruby
519
+ Sidekiq::Cron.configure do |config|
520
+ config.cron_poll_interval = 0
521
+ end
522
+ ```
523
+
524
+ ## Testing your configuration
525
+
526
+ You can test your application's configuration by loading the schedule in your test suite. Below is an example using RSpec in a Rails project:
527
+
528
+ ```ruby
529
+ # spec/cron_schedule_spec.rb
530
+ require "rails_helper"
531
+
532
+ RSpec.describe "Cron Schedule" do
533
+ let(:schedule_loader) { Sidekiq::Cron::ScheduleLoader.new }
534
+ let(:all_jobs) { Sidekiq::Cron::Job.all }
535
+
536
+ # Confirms that `config.cron_schedule_file` points to a real file.
537
+ it "has a schedule file" do
538
+ expect(schedule_loader).to have_schedule_file
539
+ end
540
+
541
+ # Confirms that no jobs in the schedule have an invalid cron string.
542
+ it "does not return any errors" do
543
+ expect(schedule_loader.load_schedule).to be_empty
544
+ end
545
+
546
+ # May be subject to churn, but adds confidence.
547
+ it "adds the expected number of jobs" do
548
+ schedule_loader.load_schedule
549
+ expect(all_jobs.size).to eq 5
550
+ end
551
+
552
+ # Confirms that all job classes exist.
553
+ it "has a valid class for each added job" do
554
+ schedule_loader.load_schedule
555
+ # Shows that all classes exist (as we can constantize the names without raising).
556
+ job_classes = all_jobs.map { |job| job.klass.constantize }
557
+ # Naive check that classes are sidekiq jobs (as they all have `.perfrom_async`).
558
+ expect(job_classes).to all(respond_to(:perform_async))
559
+ end
560
+ end
561
+ ```
365
562
 
366
563
  ## Contributing
367
564
 
@@ -383,6 +580,39 @@ You can execute the test suite by running:
383
580
  $ bundle exec rake test
384
581
  ```
385
582
 
583
+ ### Using Docker
584
+
585
+ This project uses [Docker Compose](https://docs.docker.com/compose/) in order to orchestrate containers and get the test suite running on you local machine, and here you find the commands to run in order to get a complete environment to build and test this gem:
586
+
587
+ 1. Build the Docker image (only the first time):
588
+ ```
589
+ docker compose -f docker/docker-compose.yml build
590
+ ```
591
+
592
+ 2. Run the test suite:
593
+ ```
594
+ docker compose -f docker/docker-compose.yml run --rm tests
595
+ ```
596
+
597
+ _This command will download the first time the project's dependencies (Redis so far), create the containers and run the default command to run the tests._
598
+
599
+ **Running other commands**
600
+
601
+ In the case you need to run a command in the gem's container, you would do it like so:
602
+
603
+ ```
604
+ docker compose -f docker/docker-compose.yml run --rm tests <HERE IS YOUR COMMAND>
605
+ ```
606
+ _Note that `tests` is the Docker Compose service name defined in the `docker/docker-compose.yml` file._
607
+
608
+ **Running a single test file**
609
+
610
+ Given you only want to run the tests from the `test/unit/web_extension_test.rb` file, you need to pass its path with the `TEST` env variable, so here is the command:
611
+
612
+ ```
613
+ docker compose -f docker/docker-compose.yml run --rm --env TEST=test/unit/web_extension_test.rb tests
614
+ ```
615
+
386
616
  ## License
387
617
 
388
618
  Copyright (c) 2013 Ondrej Bartas. See [LICENSE](LICENSE.txt) for further details.