sidekiq-cron 1.8.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -32
- data/README.md +13 -18
- data/lib/sidekiq/cron/job.rb +23 -44
- data/lib/sidekiq/cron/launcher.rb +4 -4
- data/lib/sidekiq/cron/poller.rb +2 -2
- data/lib/sidekiq/cron/schedule_loader.rb +1 -1
- data/lib/sidekiq/cron/support.rb +8 -0
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/options.rb +12 -5
- data/sidekiq-cron.gemspec +2 -3
- data/test/integration/performance_test.rb +9 -12
- data/test/test_helper.rb +6 -12
- data/test/unit/fixtures/schedule_erb.yml +6 -0
- data/test/unit/job_test.rb +33 -3
- data/test/unit/launcher_test.rb +6 -6
- data/test/unit/poller_test.rb +2 -8
- data/test/unit/schedule_loader_test.rb +17 -4
- data/test/unit/web_extension_test.rb +1 -2
- metadata +10 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d751ce0280b4d30f1f43a1e0ed973166c2f398d7ac976e6fea267e66e999bb8
|
4
|
+
data.tar.gz: 352b64238d89eb4eedb0e9c046f9d54f6f298c376804de1066cbdad3481c43af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee7843b8dd62b31954de3db17c4cef76229050d2c4590bde276c77d6ad2c96bbb523620631ad41574d4b976ace4da6425130b1aa5c4a20986c4d42fdcdde1ef4
|
7
|
+
data.tar.gz: 95e74c836bdae7eb10fe1fe540fdc91ecb730c3a73bc1dd7e578d9324cf448e32054e9ad1b487036119076e966b0df1011978aa34b9215a334d996759d4bb684
|
data/CHANGELOG.md
CHANGED
@@ -2,43 +2,54 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## 1.9.1
|
6
|
+
|
7
|
+
- Always enqueue via Active Job interface when defined in cron job config (https://github.com/sidekiq-cron/sidekiq-cron/pull/381)
|
8
|
+
- Fix schedule.yml YAML load errors on Ruby 3.1 (https://github.com/sidekiq-cron/sidekiq-cron/pull/386)
|
9
|
+
- Require Fugit v1.8 to refactor internals (https://github.com/sidekiq-cron/sidekiq-cron/pull/385)
|
10
|
+
|
11
|
+
## 1.9.0
|
12
|
+
|
13
|
+
- Sidekiq v7 support (https://github.com/sidekiq-cron/sidekiq-cron/pull/369)
|
14
|
+
- Add support for ERB templates in the auto schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/373)
|
15
|
+
|
5
16
|
## 1.8.0
|
6
17
|
|
7
|
-
- Fix deprecation warnings with redis-rb v4.8.0 (https://github.com/
|
8
|
-
- Fix poller affecting Sidekiq scheduled set poller (https://github.com/
|
9
|
-
- Fix default polling interval (https://github.com/
|
10
|
-
- Add italian locale (https://github.com/
|
11
|
-
- Allow disabling of cron polling (https://github.com/
|
18
|
+
- Fix deprecation warnings with redis-rb v4.8.0 (https://github.com/sidekiq-cron/sidekiq-cron/pull/356)
|
19
|
+
- Fix poller affecting Sidekiq scheduled set poller (https://github.com/sidekiq-cron/sidekiq-cron/pull/359)
|
20
|
+
- Fix default polling interval (https://github.com/sidekiq-cron/sidekiq-cron/pull/362)
|
21
|
+
- Add italian locale (https://github.com/sidekiq-cron/sidekiq-cron/pull/367)
|
22
|
+
- Allow disabling of cron polling (https://github.com/sidekiq-cron/sidekiq-cron/pull/368)
|
12
23
|
|
13
24
|
## 1.7.0
|
14
25
|
|
15
|
-
- Enable to use cron notation in natural language (ie `every 30 minutes`) (https://github.com/
|
16
|
-
- Fix `date_as_argument` feature to add timestamp argument at every cron job execution (https://github.com/
|
17
|
-
- Introduce `Sidekiq::Options` to centralize reading/writing options from different Sidekiq versions (https://github.com/
|
18
|
-
- Make auto schedule loading compatible with Array format (https://github.com/
|
26
|
+
- Enable to use cron notation in natural language (ie `every 30 minutes`) (https://github.com/sidekiq-cron/sidekiq-cron/pull/312)
|
27
|
+
- Fix `date_as_argument` feature to add timestamp argument at every cron job execution (https://github.com/sidekiq-cron/sidekiq-cron/pull/329)
|
28
|
+
- Introduce `Sidekiq::Options` to centralize reading/writing options from different Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/341)
|
29
|
+
- Make auto schedule loading compatible with Array format (https://github.com/sidekiq-cron/sidekiq-cron/pull/345)
|
19
30
|
|
20
31
|
## 1.6.0
|
21
32
|
|
22
|
-
- Adds support for auto-loading the `config/schedule.yml` file (https://github.com/
|
23
|
-
- Fix `Sidekiq.options` deprecation warning (https://github.com/
|
33
|
+
- Adds support for auto-loading the `config/schedule.yml` file (https://github.com/sidekiq-cron/sidekiq-cron/pull/337)
|
34
|
+
- Fix `Sidekiq.options` deprecation warning (https://github.com/sidekiq-cron/sidekiq-cron/pull/338)
|
24
35
|
|
25
36
|
## 1.5.1
|
26
37
|
|
27
|
-
- Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/
|
38
|
+
- Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
|
28
39
|
|
29
40
|
## 1.5.0
|
30
41
|
|
31
|
-
- Integrate Sidekiq v6.5 breaking changes (https://github.com/
|
32
|
-
- Add portuguese translations (https://github.com/
|
42
|
+
- Integrate Sidekiq v6.5 breaking changes (https://github.com/sidekiq-cron/sidekiq-cron/pull/331)
|
43
|
+
- Add portuguese translations (https://github.com/sidekiq-cron/sidekiq-cron/pull/332)
|
33
44
|
|
34
45
|
## 1.4.0
|
35
46
|
|
36
|
-
- Fix buttons order in job show view (https://github.com/
|
37
|
-
- Dark Mode support in UI (https://github.com/
|
38
|
-
- Remove invocation of deprecated Redis functionality (https://github.com/
|
39
|
-
- Internal code cleanup (https://github.com/
|
40
|
-
- Optimize gem size (https://github.com/
|
41
|
-
- Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/
|
47
|
+
- Fix buttons order in job show view (https://github.com/sidekiq-cron/sidekiq-cron/pull/302)
|
48
|
+
- Dark Mode support in UI (https://github.com/sidekiq-cron/sidekiq-cron/pull/317/282)
|
49
|
+
- Remove invocation of deprecated Redis functionality (https://github.com/sidekiq-cron/sidekiq-cron/pull/318)
|
50
|
+
- Internal code cleanup (https://github.com/sidekiq-cron/sidekiq-cron/pull/317)
|
51
|
+
- Optimize gem size (https://github.com/sidekiq-cron/sidekiq-cron/pull/322)
|
52
|
+
- Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/sidekiq-cron/sidekiq-cron/pull/321)
|
42
53
|
- Documentation updates
|
43
54
|
|
44
55
|
## 1.3.0
|
@@ -48,12 +59,12 @@ All notable changes to this project will be documented in this file.
|
|
48
59
|
- Fix deprecation warning for Redis 4.6.x
|
49
60
|
- Fix different response from Redis#exists in different Redis versions
|
50
61
|
- All PRs:
|
51
|
-
- https://github.com/
|
52
|
-
- https://github.com/
|
53
|
-
- https://github.com/
|
54
|
-
- https://github.com/
|
55
|
-
- https://github.com/
|
56
|
-
- https://github.com/
|
62
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/275
|
63
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/287
|
64
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/309
|
65
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/299
|
66
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/314
|
67
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/288
|
57
68
|
|
58
69
|
## 1.2.0
|
59
70
|
|
@@ -122,9 +133,3 @@ All notable changes to this project will be documented in this file.
|
|
122
133
|
- Suport for Active Job
|
123
134
|
- Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
|
124
135
|
- Add load_from_hash! and load_from_array! which cleanup jobs before adding new ones
|
125
|
-
|
126
|
-
## 0.1.1
|
127
|
-
|
128
|
-
- Add Web front-end with enabled/disable job, enqueue now, delete job
|
129
|
-
- Add cron poller - enqueue cron jobs
|
130
|
-
- Add cron job - save all needed data to Redis
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# Sidekiq-Cron
|
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/
|
4
|
+
[![Build Status](https://github.com/sidekiq-cron/sidekiq-cron/workflows/CI/badge.svg?branch=master)](https://github.com/sidekiq-cron/sidekiq-cron/actions)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/github/ondrejbartas/sidekiq-cron/badge.svg?branch=master)](https://coveralls.io/github/ondrejbartas/sidekiq-cron?branch=master)
|
6
|
-
[![Join the chat at https://gitter.im/ondrejbartas/sidekiq-cron](https://badges.gitter.im/ondrejbartas/sidekiq-cron.svg)](https://gitter.im/ondrejbartas/sidekiq-cron?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
7
6
|
|
8
7
|
> A scheduling add-on for [Sidekiq](https://sidekiq.org/)
|
9
8
|
|
@@ -21,10 +20,6 @@ Works with ActiveJob (Rails 4.2+).
|
|
21
20
|
|
22
21
|
You don't need Sidekiq PRO, you can use this gem with plain Sidekiq.
|
23
22
|
|
24
|
-
## Upgrade from < 0.6 to 1.0
|
25
|
-
|
26
|
-
Please be aware that Sidekiq-Cron < 1.0 was relying on rufus-scheduler < 3.5. Using those older versions with rufus-scheduler >= 3.5 ends up with jobs failing on creation. Sidekiq-Cron 1.0 includes a patch that switches from rufus-scheduler to rufus-scheduler's core dependency, fugit.
|
27
|
-
|
28
23
|
## Changelog
|
29
24
|
|
30
25
|
Before upgrading to a new version, please read our [Changelog](CHANGELOG.md).
|
@@ -53,12 +48,13 @@ gem "sidekiq-cron"
|
|
53
48
|
|
54
49
|
## Getting Started
|
55
50
|
|
56
|
-
|
51
|
+
### Job properties
|
57
52
|
|
58
53
|
```ruby
|
59
54
|
{
|
55
|
+
# MANDATORY
|
60
56
|
'name' => 'name_of_job', # must be uniq!
|
61
|
-
'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01,
|
57
|
+
'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, ...
|
62
58
|
'class' => 'MyClass',
|
63
59
|
# OPTIONAL
|
64
60
|
'queue' => 'name of queue',
|
@@ -105,7 +101,7 @@ For example: `"*/30 * * * * *"` would schedule a job to run every 30 seconds.
|
|
105
101
|
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:
|
106
102
|
|
107
103
|
```ruby
|
108
|
-
Sidekiq[:cron_poll_interval] = 10
|
104
|
+
Sidekiq::Options[:cron_poll_interval] = 10
|
109
105
|
```
|
110
106
|
|
111
107
|
The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
|
@@ -154,7 +150,7 @@ class HardWorker
|
|
154
150
|
end
|
155
151
|
end
|
156
152
|
|
157
|
-
Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker') # execute at every 5 minutes
|
153
|
+
Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker') # execute at every 5 minutes
|
158
154
|
# => true
|
159
155
|
```
|
160
156
|
|
@@ -240,10 +236,9 @@ second_job:
|
|
240
236
|
|
241
237
|
There are multiple ways to load the jobs from a YAML file
|
242
238
|
|
243
|
-
1. The gem will automatically load the jobs mentioned in `config/schedule.yml` file
|
244
|
-
2. When you want to load jobs from a different filename, mention the filename in sidekiq configuration,
|
245
|
-
|
246
|
-
3. Load the file manually as follows
|
239
|
+
1. The gem will automatically load the jobs mentioned in `config/schedule.yml` file (it supports ERB)
|
240
|
+
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"`
|
241
|
+
3. Load the file manually as follows:
|
247
242
|
|
248
243
|
```ruby
|
249
244
|
# config/initializers/sidekiq.rb
|
@@ -311,7 +306,7 @@ job.enque!
|
|
311
306
|
Just start Sidekiq workers by running:
|
312
307
|
|
313
308
|
```
|
314
|
-
$ sidekiq
|
309
|
+
$ bundle exec sidekiq
|
315
310
|
```
|
316
311
|
|
317
312
|
### Web UI for Cron Jobs
|
@@ -332,16 +327,16 @@ Sidekiq-Cron adds itself into this start procedure and starts another thread wit
|
|
332
327
|
Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
|
333
328
|
|
334
329
|
```ruby
|
335
|
-
Sidekiq[:cron_poll_interval] = 10
|
330
|
+
Sidekiq::Options[:cron_poll_interval] = 10
|
336
331
|
```
|
337
332
|
|
338
333
|
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.
|
339
334
|
|
340
|
-
When running with many Sidekiq processes, the polling can add significant load to Redis. You can disable polling on some processes by setting `Sidekiq[:cron_poll_interval] = 0` on these processes.
|
335
|
+
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.
|
341
336
|
|
342
337
|
## Contributing
|
343
338
|
|
344
|
-
**Thanks to all [contributors](https://github.com/
|
339
|
+
**Thanks to all [contributors](https://github.com/sidekiq-cron/sidekiq-cron/graphs/contributors), you’re awesome and this wouldn’t be possible without you!**
|
345
340
|
|
346
341
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
347
342
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
data/lib/sidekiq/cron/job.rb
CHANGED
@@ -13,18 +13,17 @@ module Sidekiq
|
|
13
13
|
LAST_ENQUEUE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S %z'
|
14
14
|
|
15
15
|
# Use the exists? method if we're on a newer version of Redis.
|
16
|
-
REDIS_EXISTS_METHOD = Gem.loaded_specs['redis'].version < Gem::Version.new('4.2') ? :exists : :exists?
|
16
|
+
REDIS_EXISTS_METHOD = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("7.0.0") || Gem.loaded_specs['redis'].version < Gem::Version.new('4.2') ? :exists : :exists?
|
17
17
|
|
18
18
|
# Crucial part of whole enqueuing job.
|
19
19
|
def should_enque? time
|
20
|
-
enqueue = false
|
21
20
|
enqueue = Sidekiq.redis do |conn|
|
22
21
|
status == "enabled" &&
|
23
22
|
not_past_scheduled_time?(time) &&
|
24
23
|
not_enqueued_after?(time) &&
|
25
|
-
conn.zadd(job_enqueued_key,
|
24
|
+
conn.zadd(job_enqueued_key, formatted_enqueue_time(time), formatted_last_time(time))
|
26
25
|
end
|
27
|
-
enqueue
|
26
|
+
enqueue == true || enqueue == 1
|
28
27
|
end
|
29
28
|
|
30
29
|
# Remove previous information about run times,
|
@@ -57,7 +56,7 @@ module Sidekiq
|
|
57
56
|
|
58
57
|
jid =
|
59
58
|
if klass_const
|
60
|
-
if
|
59
|
+
if is_active_job?(klass_const)
|
61
60
|
enqueue_active_job(klass_const).try :provider_job_id
|
62
61
|
else
|
63
62
|
enqueue_sidekiq_worker(klass_const)
|
@@ -75,8 +74,8 @@ module Sidekiq
|
|
75
74
|
Sidekiq.logger.debug { "enqueued #{@name}: #{@message}" }
|
76
75
|
end
|
77
76
|
|
78
|
-
def is_active_job?
|
79
|
-
@active_job || defined?(ActiveJob::Base) && Sidekiq::Cron::Support.constantize(@klass.to_s) < ActiveJob::Base
|
77
|
+
def is_active_job?(klass = nil)
|
78
|
+
@active_job || defined?(ActiveJob::Base) && (klass || Sidekiq::Cron::Support.constantize(@klass.to_s)) < ActiveJob::Base
|
80
79
|
rescue NameError
|
81
80
|
false
|
82
81
|
end
|
@@ -159,9 +158,9 @@ module Sidekiq
|
|
159
158
|
# }
|
160
159
|
#
|
161
160
|
def self.load_from_hash hash
|
162
|
-
array = hash.
|
161
|
+
array = hash.map do |key, job|
|
163
162
|
job['name'] = key
|
164
|
-
|
163
|
+
job
|
165
164
|
end
|
166
165
|
load_from_array array
|
167
166
|
end
|
@@ -401,18 +400,18 @@ module Sidekiq
|
|
401
400
|
def to_hash
|
402
401
|
{
|
403
402
|
name: @name,
|
404
|
-
klass: @klass,
|
403
|
+
klass: @klass.to_s,
|
405
404
|
cron: @cron,
|
406
405
|
description: @description,
|
407
406
|
args: @args.is_a?(String) ? @args : Sidekiq.dump_json(@args || []),
|
408
|
-
date_as_argument:
|
407
|
+
date_as_argument: date_as_argument? ? "1" : "0",
|
409
408
|
message: @message.is_a?(String) ? @message : Sidekiq.dump_json(@message || {}),
|
410
409
|
status: @status,
|
411
|
-
active_job: @active_job,
|
410
|
+
active_job: @active_job ? "1" : "0",
|
412
411
|
queue_name_prefix: @active_job_queue_name_prefix,
|
413
412
|
queue_name_delimiter: @active_job_queue_name_delimiter,
|
414
|
-
last_enqueue_time: @last_enqueue_time,
|
415
|
-
symbolize_args:
|
413
|
+
last_enqueue_time: @last_enqueue_time.to_s,
|
414
|
+
symbolize_args: symbolize_args? ? "1" : "0",
|
416
415
|
}
|
417
416
|
end
|
418
417
|
|
@@ -429,15 +428,7 @@ module Sidekiq
|
|
429
428
|
errors << "'cron' must be set"
|
430
429
|
else
|
431
430
|
begin
|
432
|
-
|
433
|
-
|
434
|
-
# Since `Fugit.do_parse` might yield a Fugit::Duration or an EtOrbi::EoTime
|
435
|
-
# https://github.com/floraison/fugit#fugitparses
|
436
|
-
if c.is_a?(Fugit::Cron)
|
437
|
-
@parsed_cron = c
|
438
|
-
else
|
439
|
-
errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}"
|
440
|
-
end
|
431
|
+
@parsed_cron = Fugit.do_parse_cronish(@cron)
|
441
432
|
rescue => e
|
442
433
|
errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}"
|
443
434
|
end
|
@@ -472,7 +463,8 @@ module Sidekiq
|
|
472
463
|
|
473
464
|
# Add information about last time! - don't enque right after scheduler poller starts!
|
474
465
|
time = Time.now.utc
|
475
|
-
|
466
|
+
exists = conn.public_send(REDIS_EXISTS_METHOD, job_enqueued_key)
|
467
|
+
conn.zadd(job_enqueued_key, time.to_f.to_s, formatted_last_time(time).to_s) unless exists == true || exists == 1
|
476
468
|
end
|
477
469
|
Sidekiq.logger.info { "Cron Jobs - added job with name: #{@name}" }
|
478
470
|
end
|
@@ -539,20 +531,19 @@ module Sidekiq
|
|
539
531
|
parsed_cron.previous_time(now.utc).utc
|
540
532
|
end
|
541
533
|
|
542
|
-
def
|
534
|
+
def formatted_enqueue_time now = Time.now.utc
|
543
535
|
last_time(now).getutc.to_f.to_s
|
544
536
|
end
|
545
537
|
|
546
|
-
def
|
538
|
+
def formatted_last_time now = Time.now.utc
|
547
539
|
last_time(now).getutc.iso8601
|
548
540
|
end
|
549
541
|
|
550
542
|
def self.exists? name
|
551
|
-
out =
|
552
|
-
|
553
|
-
out = conn.public_send(REDIS_EXISTS_METHOD, redis_key(name))
|
543
|
+
out = Sidekiq.redis do |conn|
|
544
|
+
conn.public_send(REDIS_EXISTS_METHOD, redis_key(name))
|
554
545
|
end
|
555
|
-
out
|
546
|
+
out == true || out == 1
|
556
547
|
end
|
557
548
|
|
558
549
|
def exists?
|
@@ -566,19 +557,7 @@ module Sidekiq
|
|
566
557
|
private
|
567
558
|
|
568
559
|
def parsed_cron
|
569
|
-
@parsed_cron ||=
|
570
|
-
c = Fugit.parse(@cron)
|
571
|
-
|
572
|
-
# Since `Fugit.parse` might yield a Fugit::Duration or an EtOrbi::EoTime
|
573
|
-
# https://github.com/floraison/fugit#fugitparses
|
574
|
-
if c.is_a?(Fugit::Cron)
|
575
|
-
c
|
576
|
-
else
|
577
|
-
errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}"
|
578
|
-
end
|
579
|
-
rescue => e
|
580
|
-
errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}"
|
581
|
-
end
|
560
|
+
@parsed_cron ||= Fugit.parse_cronish(@cron)
|
582
561
|
end
|
583
562
|
|
584
563
|
def not_enqueued_after?(time)
|
@@ -672,7 +651,7 @@ module Sidekiq
|
|
672
651
|
|
673
652
|
# Give Hash returns array for using it for redis.hmset
|
674
653
|
def hash_to_redis hash
|
675
|
-
hash.
|
654
|
+
hash.flat_map{ |key, value| [key, value || ""] }
|
676
655
|
end
|
677
656
|
end
|
678
657
|
end
|
@@ -14,11 +14,11 @@ module Sidekiq
|
|
14
14
|
attr_reader :cron_poller
|
15
15
|
|
16
16
|
# Add cron poller and execute normal initialize of Sidekiq launcher.
|
17
|
-
def initialize(
|
18
|
-
|
17
|
+
def initialize(config)
|
18
|
+
config[:cron_poll_interval] = DEFAULT_POLL_INTERVAL if config[:cron_poll_interval].nil?
|
19
19
|
|
20
|
-
@cron_poller = Sidekiq::Cron::Poller.new(
|
21
|
-
super
|
20
|
+
@cron_poller = Sidekiq::Cron::Poller.new(config) if config[:cron_poll_interval] > 0
|
21
|
+
super
|
22
22
|
end
|
23
23
|
|
24
24
|
# Execute normal run of launcher and run cron poller.
|
data/lib/sidekiq/cron/poller.rb
CHANGED
@@ -7,12 +7,12 @@ module Sidekiq
|
|
7
7
|
module Cron
|
8
8
|
# The Poller checks Redis every N seconds for sheduled cron jobs.
|
9
9
|
class Poller < Sidekiq::Scheduled::Poller
|
10
|
-
def initialize(
|
10
|
+
def initialize(config = nil)
|
11
11
|
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
|
12
12
|
super
|
13
13
|
else
|
14
14
|
# Old version of Sidekiq does not accept a config argument.
|
15
|
-
@config =
|
15
|
+
@config = config
|
16
16
|
super()
|
17
17
|
end
|
18
18
|
end
|
@@ -8,7 +8,7 @@ if Sidekiq.server?
|
|
8
8
|
|
9
9
|
if File.exist?(schedule_file)
|
10
10
|
config.on(:startup) do
|
11
|
-
schedule =
|
11
|
+
schedule = Sidekiq::Cron::Support.load_yaml(ERB.new(IO.read(schedule_file)).result)
|
12
12
|
if schedule.kind_of?(Hash)
|
13
13
|
Sidekiq::Cron::Job.load_from_hash schedule
|
14
14
|
elsif schedule.kind_of?(Array)
|
data/lib/sidekiq/cron/support.rb
CHANGED
data/lib/sidekiq/cron/version.rb
CHANGED
data/lib/sidekiq/options.rb
CHANGED
@@ -3,16 +3,23 @@ require 'sidekiq'
|
|
3
3
|
module Sidekiq
|
4
4
|
module Options
|
5
5
|
def self.[](key)
|
6
|
-
|
6
|
+
options_field ? Sidekiq.public_send(options_field)[key] : Sidekiq[key]
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.[]=(key, value)
|
10
|
-
|
10
|
+
options_field ? Sidekiq.public_send(options_field)[key] = value : Sidekiq[key] = value
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def self.options_field
|
14
|
+
return @options_field unless @options_field.nil?
|
15
|
+
sidekiq_version = Gem::Version.new(Sidekiq::VERSION)
|
16
|
+
@options_field = if sidekiq_version >= Gem::Version.new('7.0')
|
17
|
+
:default_configuration
|
18
|
+
elsif sidekiq_version >= Gem::Version.new('6.5')
|
19
|
+
false
|
20
|
+
else
|
21
|
+
:options
|
22
|
+
end
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
data/sidekiq-cron.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Sidekiq::Cron::VERSION
|
8
8
|
s.summary = "Scheduler/Cron for Sidekiq jobs"
|
9
9
|
s.description = "Enables to set jobs to be run in specified time (using CRON notation or natural language)"
|
10
|
-
s.homepage = "https://github.com/
|
10
|
+
s.homepage = "https://github.com/sidekiq-cron/sidekiq-cron"
|
11
11
|
s.authors = ["Ondrej Bartas"]
|
12
12
|
s.email = "ondrej@bartas.cz"
|
13
13
|
s.licenses = ["MIT"]
|
@@ -26,12 +26,11 @@ Gem::Specification.new do |s|
|
|
26
26
|
|
27
27
|
s.required_ruby_version = ">= 2.6"
|
28
28
|
|
29
|
-
s.add_dependency("fugit", "~> 1")
|
29
|
+
s.add_dependency("fugit", "~> 1.8")
|
30
30
|
s.add_dependency("sidekiq", ">= 4.2.1")
|
31
31
|
|
32
32
|
s.add_development_dependency("minitest", "~> 5.15")
|
33
33
|
s.add_development_dependency("mocha", "~> 1.14")
|
34
|
-
s.add_development_dependency("redis-namespace", "~> 1.8")
|
35
34
|
s.add_development_dependency("rack", "~> 2.2")
|
36
35
|
s.add_development_dependency("rack-test", "~> 1.1")
|
37
36
|
s.add_development_dependency("rake", "~> 13.0")
|
@@ -2,16 +2,13 @@ require './test/test_helper'
|
|
2
2
|
require 'benchmark'
|
3
3
|
|
4
4
|
describe 'Performance Poller' do
|
5
|
-
|
6
|
-
|
7
|
-
REDIS.with { |c| c.respond_to?(:redis) ? c.redis.flushdb : c.flushdb }
|
8
|
-
Sidekiq.redis = REDIS
|
5
|
+
JOBS_NUMBER = 10_000
|
6
|
+
MAX_SECONDS = 60
|
9
7
|
|
8
|
+
before do
|
10
9
|
# Clear all previous saved data from Redis.
|
11
10
|
Sidekiq.redis do |conn|
|
12
|
-
conn.
|
13
|
-
conn.del(key)
|
14
|
-
end
|
11
|
+
conn.flushdb
|
15
12
|
end
|
16
13
|
|
17
14
|
args = {
|
@@ -20,17 +17,17 @@ describe 'Performance Poller' do
|
|
20
17
|
klass: "CronTestClass"
|
21
18
|
}
|
22
19
|
|
23
|
-
|
20
|
+
JOBS_NUMBER.times do |i|
|
24
21
|
Sidekiq::Cron::Job.create(args.merge(name: "Test#{i}"))
|
25
22
|
end
|
26
23
|
|
27
|
-
@poller = Sidekiq::Cron::Poller.new
|
24
|
+
@poller = Sidekiq::Cron::Poller.new(Sidekiq.const_defined?(:Config) ? Sidekiq::Config.new : {})
|
28
25
|
now = Time.now.utc + 3600
|
29
26
|
enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 10, 5)
|
30
27
|
Time.stubs(:now).returns(enqueued_time)
|
31
28
|
end
|
32
29
|
|
33
|
-
it
|
30
|
+
it "should enqueue #{JOBS_NUMBER} jobs in less than #{MAX_SECONDS}s" do
|
34
31
|
Sidekiq.redis do |conn|
|
35
32
|
assert_equal 0, conn.llen("queue:default"), 'Queue should be empty'
|
36
33
|
end
|
@@ -40,10 +37,10 @@ describe 'Performance Poller' do
|
|
40
37
|
}
|
41
38
|
|
42
39
|
Sidekiq.redis do |conn|
|
43
|
-
assert_equal
|
40
|
+
assert_equal JOBS_NUMBER, conn.llen("queue:default"), 'Queue should be full'
|
44
41
|
end
|
45
42
|
|
46
43
|
puts "Performance test finished in #{bench.real}"
|
47
|
-
assert_operator bench.real, :<,
|
44
|
+
assert_operator bench.real, :<, MAX_SECONDS
|
48
45
|
end
|
49
46
|
end
|
data/test/test_helper.rb
CHANGED
@@ -3,31 +3,25 @@ ENV['RACK_ENV'] = 'test'
|
|
3
3
|
|
4
4
|
require 'simplecov'
|
5
5
|
SimpleCov.start do
|
6
|
-
add_filter "
|
7
|
-
add_group '
|
6
|
+
add_filter "test/"
|
7
|
+
add_group 'Sidekiq-Cron', 'lib/'
|
8
8
|
end
|
9
9
|
|
10
10
|
require "minitest/autorun"
|
11
11
|
require "rack/test"
|
12
12
|
require 'mocha/minitest'
|
13
13
|
require 'sidekiq'
|
14
|
-
require "sidekiq-pro" if ENV['SIDEKIQ_PRO_VERSION']
|
15
14
|
require 'sidekiq/web'
|
16
15
|
require "sidekiq/cli"
|
16
|
+
require 'sidekiq-cron'
|
17
|
+
require 'sidekiq/cron/web'
|
17
18
|
|
18
19
|
Sidekiq.logger.level = Logger::ERROR
|
19
|
-
|
20
|
-
redis_url = ENV['REDIS_URL'] || 'redis://0.0.0.0:6379'
|
21
|
-
REDIS = Sidekiq::RedisConnection.create(:url => redis_url, :namespace => 'testy')
|
22
|
-
|
23
20
|
Sidekiq.configure_client do |config|
|
24
|
-
config.redis = { :
|
21
|
+
config.redis = { url: ENV['REDIS_URL'] || 'redis://0.0.0.0:6379' }
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
require 'sidekiq/cron/web'
|
29
|
-
|
30
|
-
# For testing os symbilize args!
|
24
|
+
# For testing symbolize args
|
31
25
|
class Hash
|
32
26
|
def symbolize_keys
|
33
27
|
transform_keys { |key| key.to_sym rescue key }
|
data/test/unit/job_test.rb
CHANGED
@@ -178,11 +178,11 @@ describe "Cron Job" do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'returns formatted_last_time' do
|
181
|
-
assert_equal '2015-01-02T02:04:00Z', @job.
|
181
|
+
assert_equal '2015-01-02T02:04:00Z', @job.formatted_last_time(@time)
|
182
182
|
end
|
183
183
|
|
184
|
-
it 'returns
|
185
|
-
assert_equal '1420164240.0', @job.
|
184
|
+
it 'returns formatted_enqueue_time' do
|
185
|
+
assert_equal '1420164240.0', @job.formatted_enqueue_time(@time)
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -581,6 +581,36 @@ describe "Cron Job" do
|
|
581
581
|
@job.enque!
|
582
582
|
end
|
583
583
|
end
|
584
|
+
|
585
|
+
describe 'with active_job == true' do
|
586
|
+
before do
|
587
|
+
@args.merge!(active_job: true)
|
588
|
+
end
|
589
|
+
|
590
|
+
describe 'with active_job job class' do
|
591
|
+
before do
|
592
|
+
@job = Sidekiq::Cron::Job.new(@args.merge(klass: 'ActiveJobCronTestClass'))
|
593
|
+
end
|
594
|
+
|
595
|
+
it 'enques via active_job interface' do
|
596
|
+
@job.expects(:enqueue_active_job)
|
597
|
+
.returns(ActiveJobCronTestClass.new)
|
598
|
+
@job.enque!
|
599
|
+
end
|
600
|
+
end
|
601
|
+
|
602
|
+
describe 'with non sidekiq job class' do
|
603
|
+
before do
|
604
|
+
@job = Sidekiq::Cron::Job.new(@args.merge(klass: 'CronTestClass'))
|
605
|
+
end
|
606
|
+
|
607
|
+
it 'enques via active_job interface' do
|
608
|
+
@job.expects(:enqueue_active_job)
|
609
|
+
.returns(ActiveJobCronTestClass.new)
|
610
|
+
@job.enque!
|
611
|
+
end
|
612
|
+
end
|
613
|
+
end
|
584
614
|
end
|
585
615
|
|
586
616
|
describe 'active job with queue_name_prefix' do
|
data/test/unit/launcher_test.rb
CHANGED
@@ -3,7 +3,7 @@ require './test/test_helper'
|
|
3
3
|
describe 'Cron launcher' do
|
4
4
|
describe 'initialization' do
|
5
5
|
before do
|
6
|
-
Sidekiq[:cron_poll_interval] = nil
|
6
|
+
Sidekiq::Options[:cron_poll_interval] = nil
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'initializes poller with default poll interval when not configured' do
|
@@ -11,7 +11,7 @@ describe 'Cron launcher' do
|
|
11
11
|
assert_equal Sidekiq::Cron::Launcher::DEFAULT_POLL_INTERVAL, options[:cron_poll_interval]
|
12
12
|
end
|
13
13
|
|
14
|
-
Sidekiq::Launcher.new(Sidekiq)
|
14
|
+
Sidekiq::Launcher.new(Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'initializes poller with the configured poll interval' do
|
@@ -19,15 +19,15 @@ describe 'Cron launcher' do
|
|
19
19
|
assert_equal 99, options[:cron_poll_interval]
|
20
20
|
end
|
21
21
|
|
22
|
-
Sidekiq[:cron_poll_interval] = 99
|
23
|
-
Sidekiq::Launcher.new(Sidekiq)
|
22
|
+
Sidekiq::Options[:cron_poll_interval] = 99
|
23
|
+
Sidekiq::Launcher.new(Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'does not initialize the poller when interval is 0' do
|
27
27
|
Sidekiq::Cron::Poller.expects(:new).never
|
28
28
|
|
29
|
-
Sidekiq[:cron_poll_interval] = 0
|
30
|
-
Sidekiq::Launcher.new(Sidekiq)
|
29
|
+
Sidekiq::Options[:cron_poll_interval] = 0
|
30
|
+
Sidekiq::Launcher.new(Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/test/unit/poller_test.rb
CHANGED
@@ -2,17 +2,11 @@ require './test/test_helper'
|
|
2
2
|
|
3
3
|
describe 'Cron Poller' do
|
4
4
|
before do
|
5
|
-
REDIS.with { |c| c.respond_to?(:redis) ? c.redis.flushdb : c.flushdb }
|
6
|
-
Sidekiq.redis = REDIS
|
7
|
-
|
8
5
|
# Clear all previous saved data from Redis.
|
9
6
|
Sidekiq.redis do |conn|
|
10
|
-
conn.
|
11
|
-
conn.del(key)
|
12
|
-
end
|
7
|
+
conn.flushdb
|
13
8
|
end
|
14
9
|
|
15
|
-
|
16
10
|
@args = {
|
17
11
|
name: "Test",
|
18
12
|
cron: "*/2 * * * *",
|
@@ -20,7 +14,7 @@ describe 'Cron Poller' do
|
|
20
14
|
}
|
21
15
|
@args2 = @args.merge(name: 'with_queue', klass: 'CronTestClassWithQueue', cron: "*/10 * * * *")
|
22
16
|
|
23
|
-
@poller = Sidekiq::Cron::Poller.new
|
17
|
+
@poller = Sidekiq::Cron::Poller.new(Sidekiq.const_defined?(:Config) ? Sidekiq::Config.new : {})
|
24
18
|
end
|
25
19
|
|
26
20
|
it 'not enqueue any job - new jobs' do
|
@@ -2,7 +2,7 @@ require './test/test_helper'
|
|
2
2
|
|
3
3
|
describe 'ScheduleLoader' do
|
4
4
|
before do
|
5
|
-
Sidekiq
|
5
|
+
Sidekiq::Options[:lifecycle_events][:startup].clear
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'Schedule is defined in hash' do
|
@@ -13,7 +13,7 @@ describe 'ScheduleLoader' do
|
|
13
13
|
|
14
14
|
it 'calls Sidekiq::Cron::Job.load_from_hash' do
|
15
15
|
Sidekiq::Cron::Job.expects(:load_from_hash)
|
16
|
-
Sidekiq
|
16
|
+
Sidekiq::Options[:lifecycle_events][:startup].first.call
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -25,7 +25,7 @@ describe 'ScheduleLoader' do
|
|
25
25
|
|
26
26
|
it 'calls Sidekiq::Cron::Job.load_from_array' do
|
27
27
|
Sidekiq::Cron::Job.expects(:load_from_array)
|
28
|
-
Sidekiq
|
28
|
+
Sidekiq::Options[:lifecycle_events][:startup].first.call
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -37,9 +37,22 @@ describe 'ScheduleLoader' do
|
|
37
37
|
|
38
38
|
it 'raises an error' do
|
39
39
|
e = assert_raises StandardError do
|
40
|
-
Sidekiq
|
40
|
+
Sidekiq::Options[:lifecycle_events][:startup].first.call
|
41
41
|
end
|
42
42
|
assert_equal 'Not supported schedule format. Confirm your test/unit/fixtures/schedule_string.yml', e.message
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
describe 'Schedule is defined using ERB' do
|
47
|
+
it 'properly parses the schedule file' do
|
48
|
+
Sidekiq::Options[:cron_schedule_file] = 'test/unit/fixtures/schedule_erb.yml'
|
49
|
+
load 'sidekiq/cron/schedule_loader.rb'
|
50
|
+
|
51
|
+
Sidekiq::Options[:lifecycle_events][:startup].first.call
|
52
|
+
|
53
|
+
job = Sidekiq::Cron::Job.find("daily_job")
|
54
|
+
assert_equal job.klass, "DailyJob"
|
55
|
+
assert_equal job.cron, "every day at 5 pm"
|
56
|
+
end
|
57
|
+
end
|
45
58
|
end
|
@@ -12,8 +12,7 @@ describe 'Cron web' do
|
|
12
12
|
before do
|
13
13
|
env 'rack.session', { csrf: TOKEN }
|
14
14
|
env 'HTTP_X_CSRF_TOKEN', TOKEN
|
15
|
-
|
16
|
-
Sidekiq.redis = REDIS
|
15
|
+
Sidekiq.redis { |c| c.flushdb }
|
17
16
|
end
|
18
17
|
|
19
18
|
let(:job_name) { "TestNameOfCronJob" }
|
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.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondrej Bartas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fugit
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1'
|
19
|
+
version: '1.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1'
|
26
|
+
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sidekiq
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.14'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: redis-namespace
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.8'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.8'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rack
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +160,7 @@ files:
|
|
174
160
|
- test/integration/performance_test.rb
|
175
161
|
- test/test_helper.rb
|
176
162
|
- test/unit/fixtures/schedule_array.yml
|
163
|
+
- test/unit/fixtures/schedule_erb.yml
|
177
164
|
- test/unit/fixtures/schedule_hash.yml
|
178
165
|
- test/unit/fixtures/schedule_string.yml
|
179
166
|
- test/unit/job_test.rb
|
@@ -181,11 +168,11 @@ files:
|
|
181
168
|
- test/unit/poller_test.rb
|
182
169
|
- test/unit/schedule_loader_test.rb
|
183
170
|
- test/unit/web_extension_test.rb
|
184
|
-
homepage: https://github.com/
|
171
|
+
homepage: https://github.com/sidekiq-cron/sidekiq-cron
|
185
172
|
licenses:
|
186
173
|
- MIT
|
187
174
|
metadata: {}
|
188
|
-
post_install_message:
|
175
|
+
post_install_message:
|
189
176
|
rdoc_options: []
|
190
177
|
require_paths:
|
191
178
|
- lib
|
@@ -200,8 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
187
|
- !ruby/object:Gem::Version
|
201
188
|
version: '0'
|
202
189
|
requirements: []
|
203
|
-
rubygems_version: 3.
|
204
|
-
signing_key:
|
190
|
+
rubygems_version: 3.2.33
|
191
|
+
signing_key:
|
205
192
|
specification_version: 4
|
206
193
|
summary: Scheduler/Cron for Sidekiq jobs
|
207
194
|
test_files: []
|