sidekiq-cron 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{Changes.md → CHANGELOG.md} +5 -0
- data/README.md +11 -37
- data/lib/sidekiq/cron/job.rb +2 -1
- data/lib/sidekiq/cron/schedule_loader.rb +14 -0
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/cron.rb +1 -0
- data/sidekiq-cron.gemspec +1 -1
- data/test/unit/job_test.rb +10 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccf886f1cd7a1369e8a3dc9a9b9bff96c0742e22e751d9ae61e66f9fa376f873
|
4
|
+
data.tar.gz: 7ad6cd7f4637e0264cdfe529a960891275cd37c03e8bb3eb5e856bfadaa879a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d285a52788e04f6eb253f9f1b215e82a2ab68dc225eb3a4f4f6e2424cfbc190e629a9fa36238b03510cbcc1e2868d9dbf66efd8adbcd68d0aa48a5362e6ba2
|
7
|
+
data.tar.gz: cb48a228304927385f5ea69da2d233fb338efe85875c1e1bd14c3d8b52bf0cf286c307d0c841b04fc98b71453167cb4e932b7f67a15f27faadef580154be4a1f
|
data/{Changes.md → CHANGELOG.md}
RENAMED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## 1.6.0
|
6
|
+
|
7
|
+
- Adds support for auto-loading the config/schedule.yml file (https://github.com/ondrejbartas/sidekiq-cron/pull/337)
|
8
|
+
- Fix Sidekiq.options deprecation warning (https://github.com/ondrejbartas/sidekiq-cron/pull/338)
|
9
|
+
|
5
10
|
## 1.5.1
|
6
11
|
|
7
12
|
- Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/ondrejbartas/sidekiq-cron/pull/335)
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Please be aware that Sidekiq-Cron < 1.0 was relying on rufus-scheduler < 3.5. Us
|
|
27
27
|
|
28
28
|
## Changelog
|
29
29
|
|
30
|
-
Before upgrading to a new version, please read our [Changelog](
|
30
|
+
Before upgrading to a new version, please read our [Changelog](CHANGELOG.md).
|
31
31
|
|
32
32
|
## Installation
|
33
33
|
|
@@ -94,7 +94,7 @@ For example: `"*/30 * * * * *"` would schedule a job to run every 30 seconds.
|
|
94
94
|
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:
|
95
95
|
|
96
96
|
```ruby
|
97
|
-
Sidekiq
|
97
|
+
Sidekiq[:average_scheduled_poll_interval] = 10
|
98
98
|
```
|
99
99
|
|
100
100
|
The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
|
@@ -227,21 +227,19 @@ second_job:
|
|
227
227
|
hard: "stuff"
|
228
228
|
```
|
229
229
|
|
230
|
-
|
231
|
-
# config/initializers/sidekiq.rb
|
232
|
-
schedule_file = "config/schedule.yml"
|
233
|
-
|
234
|
-
if File.exist?(schedule_file) && Sidekiq.server?
|
235
|
-
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
236
|
-
end
|
237
|
-
```
|
230
|
+
There are multiple ways to load the jobs from a YAML file
|
238
231
|
|
239
|
-
|
232
|
+
1. The gem will automatically load the jobs mentioned in `config/schedule.yml` file.
|
233
|
+
2. When you want to load jobs from a different filename, mention the filename in sidekiq configuration,
|
234
|
+
i.e. `cron_schedule_file: "config/users_schedule.yml"`
|
235
|
+
3. Load the file manually as follows
|
240
236
|
|
241
237
|
```ruby
|
238
|
+
# config/initializers/sidekiq.rb
|
239
|
+
|
242
240
|
Sidekiq.configure_server do |config|
|
243
241
|
config.on(:startup) do
|
244
|
-
schedule_file = "config/
|
242
|
+
schedule_file = "config/users_schedule.yml"
|
245
243
|
|
246
244
|
if File.exist?(schedule_file)
|
247
245
|
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
@@ -316,30 +314,6 @@ With this, you will get:
|
|
316
314
|
|
317
315
|
![Web UI](examples/web-cron-ui.png)
|
318
316
|
|
319
|
-
### Forking Processes or problem with `NotImplementedError`
|
320
|
-
|
321
|
-
If you're using a forking web server like Unicorn you may run into an issue where the Redis connection is used
|
322
|
-
before the process forks, causing the following exception to occur:
|
323
|
-
|
324
|
-
```
|
325
|
-
Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.
|
326
|
-
```
|
327
|
-
|
328
|
-
To avoid this, wrap your job creation in the call to `Sidekiq.configure_server`:
|
329
|
-
|
330
|
-
```ruby
|
331
|
-
Sidekiq.configure_server do |config|
|
332
|
-
config.on(:startup) do
|
333
|
-
schedule_file = "config/schedule.yml"
|
334
|
-
|
335
|
-
if File.exist?(schedule_file)
|
336
|
-
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
```
|
341
|
-
|
342
|
-
**NOTE** This API is only available in Sidekiq 3.x.
|
343
317
|
|
344
318
|
## Under the hood
|
345
319
|
|
@@ -350,7 +324,7 @@ Sidekiq-Cron adds itself into this start procedure and starts another thread wit
|
|
350
324
|
Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
|
351
325
|
|
352
326
|
```ruby
|
353
|
-
Sidekiq
|
327
|
+
Sidekiq[:average_scheduled_poll_interval] = 10
|
354
328
|
```
|
355
329
|
|
356
330
|
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.
|
data/lib/sidekiq/cron/job.rb
CHANGED
@@ -478,7 +478,8 @@ module Sidekiq
|
|
478
478
|
jid: jid,
|
479
479
|
enqueued: @last_enqueue_time
|
480
480
|
}
|
481
|
-
|
481
|
+
cron_history_size = Sidekiq.respond_to?(:[]) ? Sidekiq[:cron_history_size] : Sidekiq.options[:cron_history_size]
|
482
|
+
@history_size ||= (cron_history_size || 10).to_i - 1
|
482
483
|
Sidekiq.redis do |conn|
|
483
484
|
conn.lpush jid_history_key,
|
484
485
|
Sidekiq.dump_json(jid_history)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "sidekiq"
|
2
|
+
require "sidekiq/cron/job"
|
3
|
+
|
4
|
+
if Sidekiq.server?
|
5
|
+
Sidekiq.configure_server do |config|
|
6
|
+
schedule_file = config.options[:cron_schedule_file] || "config/schedule.yml"
|
7
|
+
|
8
|
+
if File.exist?(schedule_file)
|
9
|
+
config.on(:startup) do
|
10
|
+
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/sidekiq/cron/version.rb
CHANGED
data/lib/sidekiq/cron.rb
CHANGED
data/sidekiq-cron.gemspec
CHANGED
data/test/unit/job_test.rb
CHANGED
@@ -1030,6 +1030,16 @@ describe "Cron Job" do
|
|
1030
1030
|
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
|
1031
1031
|
end
|
1032
1032
|
|
1033
|
+
it "duplicate jobs are not loaded" do
|
1034
|
+
out = Sidekiq::Cron::Job.load_from_hash @jobs_hash
|
1035
|
+
assert_equal out.size, 0, "should have no errors"
|
1036
|
+
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
|
1037
|
+
|
1038
|
+
out_2 = Sidekiq::Cron::Job.load_from_hash @jobs_hash
|
1039
|
+
assert_equal out_2.size, 0, "should have no errors"
|
1040
|
+
assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after loading again"
|
1041
|
+
end
|
1042
|
+
|
1033
1043
|
it "return errors on loaded jobs" do
|
1034
1044
|
assert_equal Sidekiq::Cron::Job.all.size, 0, "Should have 0 jobs before load"
|
1035
1045
|
#set something bag to hash
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-cron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondrej Bartas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fugit
|
@@ -144,7 +144,7 @@ extra_rdoc_files:
|
|
144
144
|
- LICENSE.txt
|
145
145
|
- README.md
|
146
146
|
files:
|
147
|
-
-
|
147
|
+
- CHANGELOG.md
|
148
148
|
- Gemfile
|
149
149
|
- LICENSE.txt
|
150
150
|
- README.md
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/sidekiq/cron/locales/ru.yml
|
161
161
|
- lib/sidekiq/cron/locales/zh-CN.yml
|
162
162
|
- lib/sidekiq/cron/poller.rb
|
163
|
+
- lib/sidekiq/cron/schedule_loader.rb
|
163
164
|
- lib/sidekiq/cron/support.rb
|
164
165
|
- lib/sidekiq/cron/version.rb
|
165
166
|
- lib/sidekiq/cron/views/cron.erb
|
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
192
|
- !ruby/object:Gem::Version
|
192
193
|
version: '0'
|
193
194
|
requirements: []
|
194
|
-
rubygems_version: 3.1.
|
195
|
+
rubygems_version: 3.1.4
|
195
196
|
signing_key:
|
196
197
|
specification_version: 4
|
197
198
|
summary: Sidekiq-Cron helps to add repeated scheduled jobs
|