sidekiq-cron 1.12.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaa6af217265c4e60b29018b984b43a4316b2618e52ce874db670e41ecadf85b
4
- data.tar.gz: f70a50a90508ceb32bad90b8b2b6a880fb460f308dfa81f7380152742bb939cf
3
+ metadata.gz: dce1f7b341e293e80c0b8981c03b24293c2922f4133f62882bcbee62fa3b12d6
4
+ data.tar.gz: 210bcfa247b4801bdb86a0d1f5c0454721172abebf0c2e5354be24caee1d6628
5
5
  SHA512:
6
- metadata.gz: ef95b33d15c1867a3dc6cc096080af6f2fab50c4460d8be24948bcd887c6c278dc3ca1a8c92db8d1ce386d24e0ceb95f53f6add336c3315fec04f808b7451475
7
- data.tar.gz: e30e02e3bcc13f8604426d5d9e5f30e24c46a85bfd7679544975a3bdfcc0510631d363ef041f948c8a51e289a02a222fd27bba572cf57ac1697aabb917673a01
6
+ metadata.gz: cd604c51a98b3b2d1a0af7fdf59afb599f9e9af717043bbbe2816a519be5824694415b59ebd8ec21fa09069798e71bb2d69ae9a62fbf177864f3adcf3c4fc1d3
7
+ data.tar.gz: '08ebb6f111498fd8f9b377eed43f17be760caace33185fec69b68e7e5f8ef89d5ee0bd34fe91d714d2c4d5af995e7297909a14e827cf4dce43b7974a859ae50f'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 2.0.0.rc1
6
+
7
+ - Introduce `Namespacing` (https://github.com/sidekiq-cron/sidekiq-cron/pull/268)
8
+ - Human readable cron format in UI (https://github.com/sidekiq-cron/sidekiq-cron/pull/445)
9
+ - Add Bahasa Indonesia locale (https://github.com/sidekiq-cron/sidekiq-cron/pull/446)
10
+ - Fetch queue name from ActiveJob class (https://github.com/sidekiq-cron/sidekiq-cron/pull/448)
11
+ - Allows symbol keys in `.load_from_array!` (https://github.com/sidekiq-cron/sidekiq-cron/pull/458)
12
+ - Add natural language parsing mode (https://github.com/sidekiq-cron/sidekiq-cron/pull/459)
13
+ - Add ability to configure the past scheduled time threshold (https://github.com/sidekiq-cron/sidekiq-cron/pull/465)
14
+ - Docs: clarify worker vs process terminology (https://github.com/sidekiq-cron/sidekiq-cron/issues/453)
15
+
5
16
  ## 1.12.0
6
17
 
7
18
  - Remove Sidekiq.server? check from schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/436)
@@ -61,7 +72,7 @@ All notable changes to this project will be documented in this file.
61
72
 
62
73
  ## 1.5.1
63
74
 
64
- - Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
75
+ - Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
65
76
 
66
77
  ## 1.5.0
67
78
 
@@ -156,6 +167,6 @@ All notable changes to this project will be documented in this file.
156
167
 
157
168
  ## 0.3.0
158
169
 
159
- - Suport for Active Job
170
+ - Support for Active Job
160
171
  - Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
161
172
  - Add load_from_hash! and load_from_array! which cleanup jobs before adding new ones
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
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)).
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
 
@@ -51,6 +51,7 @@ gem "sidekiq-cron"
51
51
  'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, ...
52
52
  'class' => 'MyClass',
53
53
  # OPTIONAL
54
+ 'namespace' => 'YourNamespace', # groups jobs together in a namespace (Default value is 'default'),
54
55
  'source' => 'dynamic', # source of the job, `schedule`/`dynamic` (default: `dynamic`)
55
56
  'queue' => 'name of queue',
56
57
  'args' => '[Array or Hash] of arguments which will be passed to perform method',
@@ -63,6 +64,8 @@ gem "sidekiq-cron"
63
64
  }
64
65
  ```
65
66
 
67
+ **NOTE** The `status` of a job does not get changed in Redis when a job gets reloaded unless the `status` property is explicitly set.
68
+
66
69
  ### Time, cron and Sidekiq-Cron
67
70
 
68
71
  For testing your cron notation you can use [crontab.guru](https://crontab.guru).
@@ -85,6 +88,38 @@ Since sidekiq-cron `v1.7.0`, you can use the natural-language formats supported
85
88
 
86
89
  See [the relevant part of Fugit documentation](https://github.com/floraison/fugit#fugitnat) for details.
87
90
 
91
+ There are multiple modes that determine how natural-language cron strings will be parsed.
92
+
93
+ 1. `:single` (default)
94
+
95
+ ```ruby
96
+ Sidekiq::Cron.configure do |config|
97
+ # Note: This doesn't need to be specified since it's the default.
98
+ config.natural_cron_parsing_mode = :single
99
+ end
100
+ ```
101
+
102
+ This parses the first possible cron line from the given string and then ignores any additional cron lines.
103
+
104
+ Ex. `every day at 3:15 and 4:30`
105
+
106
+ - Equivalent to `15 3 * * *`.
107
+ - `30 4 * * *` gets ignored.
108
+
109
+ 2. `:strict`
110
+
111
+ ```ruby
112
+ Sidekiq::Cron.configure do |config|
113
+ config.natural_cron_parsing_mode = :strict
114
+ end
115
+ ```
116
+
117
+ This throws an error if the given string would be parsed into multiple cron lines.
118
+
119
+ Ex. `every day at 3:15 and 4:30`
120
+
121
+ - Would throw an error and the associated cron job would be invalid
122
+
88
123
  #### Second-precision (sub-minute) cronlines
89
124
 
90
125
  In addition to the standard 5-parameter cronline format, sidekiq-cron supports scheduling jobs with second-precision using a modified 6-parameter cronline format:
@@ -101,6 +136,60 @@ Sidekiq::Options[:cron_poll_interval] = 10
101
136
 
102
137
  The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
103
138
 
139
+ ### Namespacing
140
+
141
+ #### Default namespace
142
+
143
+ When not giving a namespace, the `default` one will be used.
144
+
145
+ In the case you'd like to change this value, create a new initializer like so:
146
+
147
+ `config/initializers/sidekiq-cron.rb`:
148
+
149
+ ```ruby
150
+ Sidekiq::Cron.configure do |config|
151
+ config.default_namespace = 'statics'
152
+ end
153
+ ```
154
+
155
+ #### Usage
156
+
157
+ 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.
158
+
159
+ ```ruby
160
+ Sidekiq::Cron::Job.create(
161
+ name: 'Hard worker - every 5min',
162
+ namespace: 'Foo',
163
+ cron: '*/5 * * * *',
164
+ class: 'HardWorker'
165
+ )
166
+ # INFO: Cron Jobs - add job with name Hard worker - every 5min in the namespace Foo
167
+
168
+ # Without specifying the namespace, Sidekiq::Cron use the `default` one, therefore `count` return 0.
169
+ Sidekiq::Cron::Job.count
170
+ #=> 0
171
+
172
+ # Searching in the job's namespace returns 1.
173
+ Sidekiq::Cron::Job.count 'Foo'
174
+ #=> 1
175
+
176
+ # Same applies to `all`. Without a namespace, no jobs found.
177
+ Sidekiq::Cron::Job.all
178
+
179
+ # But giving the job's namespace returns it.
180
+ Sidekiq::Cron::Job.all 'Foo'
181
+ #=> [#<Sidekiq::Cron::Job:0x00007f7848a326a0 ... @name="Hard worker - every 5min", @namespace="Foo", @cron="*/5 * * * *", @klass="HardWorker", @status="enabled" ... >]
182
+
183
+ # If you'd like to get all the jobs across all the namespaces then pass an asterisk:
184
+ Sidekiq::Cron::Job.all '*'
185
+ #=> [#<Sidekiq::Cron::Job ...>]
186
+
187
+ job = Sidekiq::Cron::Job.find('Hard worker - every 5min', 'Foo').first
188
+ job.destroy
189
+ # INFO: Cron Jobs - deleted job with name Hard worker - every 5min from namespace Foo
190
+ #=> true
191
+ ```
192
+
104
193
  ### What objects/classes can be scheduled
105
194
 
106
195
  #### Sidekiq Worker
@@ -117,7 +206,9 @@ class HardWorker
117
206
  end
118
207
  ```
119
208
 
120
- #### Active Job Worker
209
+ 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.).
210
+
211
+ #### Active Job
121
212
 
122
213
  You can schedule `ExampleJob` which looks like:
123
214
 
@@ -134,7 +225,7 @@ end
134
225
  For Active jobs you can use `symbolize_args: true` in `Sidekiq::Cron::Job.create` or in Hash configuration,
135
226
  which will ensure that arguments you are passing to it will be symbolized when passed back to `perform` method in worker.
136
227
 
137
- #### Adding Cron job
228
+ ### Adding Cron jobs
138
229
 
139
230
  Refer to [Schedule vs Dynamic jobs](#schedule-vs-dynamic-jobs) to understand the difference.
140
231
 
@@ -168,7 +259,7 @@ unless job.save
168
259
  end
169
260
  ```
170
261
 
171
- Use ActiveRecord models as arguments
262
+ Use ActiveRecord models as arguments:
172
263
 
173
264
  ```rb
174
265
  class Person < ApplicationRecord
@@ -182,7 +273,6 @@ class HardWorker < ActiveJob::Base
182
273
  end
183
274
  end
184
275
 
185
-
186
276
  person = Person.create(id: 1)
187
277
  Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker', args: person)
188
278
  # => true
@@ -233,7 +323,9 @@ Sidekiq::Cron::Job.load_from_hash! hash
233
323
  Sidekiq::Cron::Job.load_from_array! array
234
324
  ```
235
325
 
236
- Or from YAML (same notation as Resque-scheduler):
326
+ ### Loading jobs from schedule file
327
+
328
+ You can also load multiple jobs from a YAML (same notation as `Resque-scheduler`) file:
237
329
 
238
330
  ```yaml
239
331
  # config/schedule.yml
@@ -359,6 +451,16 @@ Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can chang
359
451
  Sidekiq::Options[:cron_poll_interval] = 10
360
452
  ```
361
453
 
454
+ 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:
455
+
456
+ ```ruby
457
+ # config/initializers/sidekiq-cron.rb
458
+
459
+ Sidekiq::Cron.configure do |config|
460
+ config.reschedule_grace_period = 600 # 10 minutes in seconds
461
+ end
462
+ ```
463
+
362
464
  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
465
 
364
466
  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.
@@ -383,6 +485,39 @@ You can execute the test suite by running:
383
485
  $ bundle exec rake test
384
486
  ```
385
487
 
488
+ ### Using Docker
489
+
490
+ [Docker](https://www.docker.com) allows you to run things in containers easing the development process.
491
+
492
+ 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:
493
+
494
+ 1. Build the Docker image (only the first time):
495
+ ```
496
+ docker compose -f docker/docker-compose.yml build
497
+ ```
498
+ 2. Run the test suite:
499
+ ```
500
+ docker compose -f docker/docker-compose.yml run --rm tests
501
+ ```
502
+ _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._
503
+
504
+ #### Running other commands
505
+
506
+ In the case you need to run a command in the gem's container, you would do it like so:
507
+
508
+ ```
509
+ docker compose -f docker/docker-compose.yml run --rm tests <HERE IS YOUR COMMAND>
510
+ ```
511
+ _Note that `tests` is the Docker Compose service name defined in the `docker/docker-compose.yml` file._
512
+
513
+ #### Running a single test file
514
+
515
+ 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:
516
+
517
+ ```
518
+ docker compose -f docker/docker-compose.yml run --rm --env TEST=test/unit/web_extension_test.rb tests
519
+ ```
520
+
386
521
  ## License
387
522
 
388
523
  Copyright (c) 2013 Ondrej Bartas. See [LICENSE](LICENSE.txt) for further details.