sidekiq-cron 1.7.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -27
- data/README.md +14 -17
- data/lib/sidekiq/cron/job.rb +20 -21
- data/lib/sidekiq/cron/launcher.rb +10 -6
- data/lib/sidekiq/cron/locales/it.yml +23 -0
- data/lib/sidekiq/cron/poller.rb +9 -10
- data/lib/sidekiq/cron/schedule_loader.rb +1 -1
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/cron/views/cron.erb +1 -1
- data/lib/sidekiq/options.rb +12 -5
- data/sidekiq-cron.gemspec +1 -2
- data/test/integration/performance_test.rb +9 -12
- data/test/test_helper.rb +6 -12
- data/test/unit/fixtures/schedule_erb.yml +4 -0
- data/test/unit/job_test.rb +4 -4
- data/test/unit/launcher_test.rb +33 -0
- 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 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b26393b7aa972d9a769d851269600f51c61feff8c3d2b5cbe611eed0e21b704d
|
4
|
+
data.tar.gz: 1822ffdf4ebe54db931394f38acf3eca8552953396d8fc1848aa3ec89d1164d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fe8be5571ecb428191894a7d433fd6b2f8098607ad4de23f7cfe030b71895eed66cc8a218bf53684b235a5422b4895a676963f7bc02ab1deb06fae4982a34db
|
7
|
+
data.tar.gz: b75e0b6928d263590ba7a97beca37205bd50123d0118ee49312a106573bf1a7b640f75c8ef1f76198a3da94fe19a6c9c9fa4bd3d357898590f251732d9a34d43
|
data/CHANGELOG.md
CHANGED
@@ -2,35 +2,48 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## 1.9.0
|
6
|
+
|
7
|
+
- Sidekiq v7 support (https://github.com/sidekiq-cron/sidekiq-cron/pull/369)
|
8
|
+
- Add support for ERB templates in the auto schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/373)
|
9
|
+
|
10
|
+
## 1.8.0
|
11
|
+
|
12
|
+
- Fix deprecation warnings with redis-rb v4.8.0 (https://github.com/sidekiq-cron/sidekiq-cron/pull/356)
|
13
|
+
- Fix poller affecting Sidekiq scheduled set poller (https://github.com/sidekiq-cron/sidekiq-cron/pull/359)
|
14
|
+
- Fix default polling interval (https://github.com/sidekiq-cron/sidekiq-cron/pull/362)
|
15
|
+
- Add italian locale (https://github.com/sidekiq-cron/sidekiq-cron/pull/367)
|
16
|
+
- Allow disabling of cron polling (https://github.com/sidekiq-cron/sidekiq-cron/pull/368)
|
17
|
+
|
5
18
|
## 1.7.0
|
6
19
|
|
7
|
-
- Enable to use cron notation in natural language (ie `every 30 minutes`) (https://github.com/
|
8
|
-
- Fix `date_as_argument` feature to add timestamp argument at every cron job execution (https://github.com/
|
9
|
-
- Introduce `Sidekiq::Options` to centralize reading/writing options from different Sidekiq versions (https://github.com/
|
10
|
-
- Make auto schedule loading compatible with Array format (https://github.com/
|
20
|
+
- Enable to use cron notation in natural language (ie `every 30 minutes`) (https://github.com/sidekiq-cron/sidekiq-cron/pull/312)
|
21
|
+
- Fix `date_as_argument` feature to add timestamp argument at every cron job execution (https://github.com/sidekiq-cron/sidekiq-cron/pull/329)
|
22
|
+
- Introduce `Sidekiq::Options` to centralize reading/writing options from different Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/341)
|
23
|
+
- Make auto schedule loading compatible with Array format (https://github.com/sidekiq-cron/sidekiq-cron/pull/345)
|
11
24
|
|
12
25
|
## 1.6.0
|
13
26
|
|
14
|
-
- Adds support for auto-loading the `config/schedule.yml` file (https://github.com/
|
15
|
-
- Fix `Sidekiq.options` deprecation warning (https://github.com/
|
27
|
+
- Adds support for auto-loading the `config/schedule.yml` file (https://github.com/sidekiq-cron/sidekiq-cron/pull/337)
|
28
|
+
- Fix `Sidekiq.options` deprecation warning (https://github.com/sidekiq-cron/sidekiq-cron/pull/338)
|
16
29
|
|
17
30
|
## 1.5.1
|
18
31
|
|
19
|
-
- Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/
|
32
|
+
- Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
|
20
33
|
|
21
34
|
## 1.5.0
|
22
35
|
|
23
|
-
- Integrate Sidekiq v6.5 breaking changes (https://github.com/
|
24
|
-
- Add portuguese translations (https://github.com/
|
36
|
+
- Integrate Sidekiq v6.5 breaking changes (https://github.com/sidekiq-cron/sidekiq-cron/pull/331)
|
37
|
+
- Add portuguese translations (https://github.com/sidekiq-cron/sidekiq-cron/pull/332)
|
25
38
|
|
26
39
|
## 1.4.0
|
27
40
|
|
28
|
-
- Fix buttons order in job show view (https://github.com/
|
29
|
-
- Dark Mode support in UI (https://github.com/
|
30
|
-
- Remove invocation of deprecated Redis functionality (https://github.com/
|
31
|
-
- Internal code cleanup (https://github.com/
|
32
|
-
- Optimize gem size (https://github.com/
|
33
|
-
- Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/
|
41
|
+
- Fix buttons order in job show view (https://github.com/sidekiq-cron/sidekiq-cron/pull/302)
|
42
|
+
- Dark Mode support in UI (https://github.com/sidekiq-cron/sidekiq-cron/pull/317/282)
|
43
|
+
- Remove invocation of deprecated Redis functionality (https://github.com/sidekiq-cron/sidekiq-cron/pull/318)
|
44
|
+
- Internal code cleanup (https://github.com/sidekiq-cron/sidekiq-cron/pull/317)
|
45
|
+
- Optimize gem size (https://github.com/sidekiq-cron/sidekiq-cron/pull/322)
|
46
|
+
- Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/sidekiq-cron/sidekiq-cron/pull/321)
|
34
47
|
- Documentation updates
|
35
48
|
|
36
49
|
## 1.3.0
|
@@ -40,12 +53,12 @@ All notable changes to this project will be documented in this file.
|
|
40
53
|
- Fix deprecation warning for Redis 4.6.x
|
41
54
|
- Fix different response from Redis#exists in different Redis versions
|
42
55
|
- All PRs:
|
43
|
-
- https://github.com/
|
44
|
-
- https://github.com/
|
45
|
-
- https://github.com/
|
46
|
-
- https://github.com/
|
47
|
-
- https://github.com/
|
48
|
-
- https://github.com/
|
56
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/275
|
57
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/287
|
58
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/309
|
59
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/299
|
60
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/314
|
61
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/288
|
49
62
|
|
50
63
|
## 1.2.0
|
51
64
|
|
@@ -114,9 +127,3 @@ All notable changes to this project will be documented in this file.
|
|
114
127
|
- Suport for Active Job
|
115
128
|
- Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
|
116
129
|
- Add load_from_hash! and load_from_array! which cleanup jobs before adding new ones
|
117
|
-
|
118
|
-
## 0.1.1
|
119
|
-
|
120
|
-
- Add Web front-end with enabled/disable job, enqueue now, delete job
|
121
|
-
- Add cron poller - enqueue cron jobs
|
122
|
-
- 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[:
|
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,14 +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[:
|
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
|
|
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.
|
336
|
+
|
340
337
|
## Contributing
|
341
338
|
|
342
|
-
**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!**
|
343
340
|
|
344
341
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
345
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,
|
@@ -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
|
|
@@ -465,14 +464,15 @@ module Sidekiq
|
|
465
464
|
Sidekiq.redis do |conn|
|
466
465
|
|
467
466
|
# Add to set of all jobs
|
468
|
-
conn.sadd self.class.jobs_key, redis_key
|
467
|
+
conn.sadd self.class.jobs_key, [redis_key]
|
469
468
|
|
470
469
|
# Add informations for this job!
|
471
470
|
conn.hmset redis_key, *hash_to_redis(to_hash)
|
472
471
|
|
473
472
|
# Add information about last time! - don't enque right after scheduler poller starts!
|
474
473
|
time = Time.now.utc
|
475
|
-
|
474
|
+
exists = conn.public_send(REDIS_EXISTS_METHOD, job_enqueued_key)
|
475
|
+
conn.zadd(job_enqueued_key, time.to_f.to_s, formatted_last_time(time).to_s) unless exists == true || exists == 1
|
476
476
|
end
|
477
477
|
Sidekiq.logger.info { "Cron Jobs - added job with name: #{@name}" }
|
478
478
|
end
|
@@ -502,7 +502,7 @@ module Sidekiq
|
|
502
502
|
def destroy
|
503
503
|
Sidekiq.redis do |conn|
|
504
504
|
# Delete from set.
|
505
|
-
conn.srem self.class.jobs_key, redis_key
|
505
|
+
conn.srem self.class.jobs_key, [redis_key]
|
506
506
|
|
507
507
|
# Delete runned timestamps.
|
508
508
|
conn.del job_enqueued_key
|
@@ -539,20 +539,19 @@ module Sidekiq
|
|
539
539
|
parsed_cron.previous_time(now.utc).utc
|
540
540
|
end
|
541
541
|
|
542
|
-
def
|
542
|
+
def formatted_enqueue_time now = Time.now.utc
|
543
543
|
last_time(now).getutc.to_f.to_s
|
544
544
|
end
|
545
545
|
|
546
|
-
def
|
546
|
+
def formatted_last_time now = Time.now.utc
|
547
547
|
last_time(now).getutc.iso8601
|
548
548
|
end
|
549
549
|
|
550
550
|
def self.exists? name
|
551
|
-
out =
|
552
|
-
|
553
|
-
out = conn.public_send(REDIS_EXISTS_METHOD, redis_key(name))
|
551
|
+
out = Sidekiq.redis do |conn|
|
552
|
+
conn.public_send(REDIS_EXISTS_METHOD, redis_key(name))
|
554
553
|
end
|
555
|
-
out
|
554
|
+
out == true || out == 1
|
556
555
|
end
|
557
556
|
|
558
557
|
def exists?
|
@@ -672,7 +671,7 @@ module Sidekiq
|
|
672
671
|
|
673
672
|
# Give Hash returns array for using it for redis.hmset
|
674
673
|
def hash_to_redis hash
|
675
|
-
hash.
|
674
|
+
hash.flat_map{ |key, value| [key, value || ""] }
|
676
675
|
end
|
677
676
|
end
|
678
677
|
end
|
@@ -8,30 +8,34 @@ require 'sidekiq/cron/poller'
|
|
8
8
|
module Sidekiq
|
9
9
|
module Cron
|
10
10
|
module Launcher
|
11
|
+
DEFAULT_POLL_INTERVAL = 30
|
12
|
+
|
11
13
|
# Add cron poller to launcher.
|
12
14
|
attr_reader :cron_poller
|
13
15
|
|
14
16
|
# Add cron poller and execute normal initialize of Sidekiq launcher.
|
15
|
-
def initialize(
|
16
|
-
|
17
|
-
|
17
|
+
def initialize(config)
|
18
|
+
config[:cron_poll_interval] = DEFAULT_POLL_INTERVAL if config[:cron_poll_interval].nil?
|
19
|
+
|
20
|
+
@cron_poller = Sidekiq::Cron::Poller.new(config) if config[:cron_poll_interval] > 0
|
21
|
+
super
|
18
22
|
end
|
19
23
|
|
20
24
|
# Execute normal run of launcher and run cron poller.
|
21
25
|
def run
|
22
26
|
super
|
23
|
-
cron_poller.start
|
27
|
+
cron_poller.start if @cron_poller
|
24
28
|
end
|
25
29
|
|
26
30
|
# Execute normal quiet of launcher and quiet cron poller.
|
27
31
|
def quiet
|
28
|
-
cron_poller.terminate
|
32
|
+
cron_poller.terminate if @cron_poller
|
29
33
|
super
|
30
34
|
end
|
31
35
|
|
32
36
|
# Execute normal stop of launcher and stop cron poller.
|
33
37
|
def stop
|
34
|
-
cron_poller.terminate
|
38
|
+
cron_poller.terminate if @cron_poller
|
35
39
|
super
|
36
40
|
end
|
37
41
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
it:
|
2
|
+
Job: Job
|
3
|
+
Cron: Cron
|
4
|
+
CronJobs: Cron job
|
5
|
+
EnqueueNow: Accoda
|
6
|
+
EnableAll: Attiva tutto
|
7
|
+
DisableAll: Disattiva tutto
|
8
|
+
EnqueueAll: Accoda tutto
|
9
|
+
DeleteAll: Cancella tutto
|
10
|
+
"Cron string": Cron
|
11
|
+
AreYouSureEnqueueCronJobs: Vuoi accodare TUTTI i cron job?
|
12
|
+
AreYouSureEnqueueCronJob: "Vuoi accodare il cron job '%{job}'?"
|
13
|
+
AreYouSureDeleteCronJobs: Vuoi cancellare TUTTI i cron job?
|
14
|
+
AreYouSureDeleteCronJob: "Vuoi cancellare il cron job '%{job}'?"
|
15
|
+
NoCronJobsWereFound: Nessun cron job trovato
|
16
|
+
Enable: Attiva
|
17
|
+
Disable: Disattiva
|
18
|
+
"Last enqueued": Ultimo accodamento
|
19
|
+
disabled: disattivato
|
20
|
+
enabled: attivato
|
21
|
+
NoHistoryWereFound: Nessun evento in cronologia
|
22
|
+
Description: Descrizione
|
23
|
+
Message: Payload
|
data/lib/sidekiq/cron/poller.rb
CHANGED
@@ -5,20 +5,15 @@ require 'sidekiq/options'
|
|
5
5
|
|
6
6
|
module Sidekiq
|
7
7
|
module Cron
|
8
|
-
POLL_INTERVAL = Sidekiq::Options[:average_scheduled_poll_interval] || 30
|
9
|
-
|
10
8
|
# The Poller checks Redis every N seconds for sheduled cron jobs.
|
11
9
|
class Poller < Sidekiq::Scheduled::Poller
|
12
|
-
def initialize
|
13
|
-
Sidekiq.configure_server do
|
14
|
-
Sidekiq::Options[:poll_interval_average] = POLL_INTERVAL
|
15
|
-
end
|
16
|
-
|
10
|
+
def initialize(config = nil)
|
17
11
|
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
|
18
|
-
# Sidekiq Poller init requires a config argument.
|
19
|
-
super(Sidekiq)
|
20
|
-
else
|
21
12
|
super
|
13
|
+
else
|
14
|
+
# Old version of Sidekiq does not accept a config argument.
|
15
|
+
@config = config
|
16
|
+
super()
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
@@ -45,6 +40,10 @@ module Sidekiq
|
|
45
40
|
Sidekiq.logger.error "CRON JOB: #{ex.backtrace.first}"
|
46
41
|
handle_exception(ex) if respond_to?(:handle_exception)
|
47
42
|
end
|
43
|
+
|
44
|
+
def poll_interval_average(process_count = 1)
|
45
|
+
@config[:cron_poll_interval]
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|
50
49
|
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 = YAML.
|
11
|
+
schedule = YAML.load(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/version.rb
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
<td style="<%= style %>"><%= t job.status %></td>
|
43
43
|
<td style="<%= style %>">
|
44
44
|
<a href="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>">
|
45
|
-
<b><%= job.name %></b>
|
45
|
+
<b style="<%= style %>"><%= job.name %></b>
|
46
46
|
</a>
|
47
47
|
<hr style="margin:3px;border:0;">
|
48
48
|
<small>
|
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"]
|
@@ -31,7 +31,6 @@ Gem::Specification.new do |s|
|
|
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
|
|
@@ -929,7 +929,7 @@ describe "Cron Job" do
|
|
929
929
|
Sidekiq::Cron::Job.create(@args.merge(name: "Test3"))
|
930
930
|
|
931
931
|
Sidekiq.redis do |conn|
|
932
|
-
conn.sadd Sidekiq::Cron::Job.jobs_key, "some_other_key"
|
932
|
+
conn.sadd Sidekiq::Cron::Job.jobs_key, ["some_other_key"]
|
933
933
|
end
|
934
934
|
|
935
935
|
assert_equal Sidekiq::Cron::Job.all.size, 3, "All have to return only valid 3 jobs"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
|
3
|
+
describe 'Cron launcher' do
|
4
|
+
describe 'initialization' do
|
5
|
+
before do
|
6
|
+
Sidekiq::Options[:cron_poll_interval] = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'initializes poller with default poll interval when not configured' do
|
10
|
+
Sidekiq::Cron::Poller.expects(:new).with do |options|
|
11
|
+
assert_equal Sidekiq::Cron::Launcher::DEFAULT_POLL_INTERVAL, options[:cron_poll_interval]
|
12
|
+
end
|
13
|
+
|
14
|
+
Sidekiq::Launcher.new(Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'initializes poller with the configured poll interval' do
|
18
|
+
Sidekiq::Cron::Poller.expects(:new).with do |options|
|
19
|
+
assert_equal 99, options[:cron_poll_interval]
|
20
|
+
end
|
21
|
+
|
22
|
+
Sidekiq::Options[:cron_poll_interval] = 99
|
23
|
+
Sidekiq::Launcher.new(Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not initialize the poller when interval is 0' do
|
27
|
+
Sidekiq::Cron::Poller.expects(:new).never
|
28
|
+
|
29
|
+
Sidekiq::Options[:cron_poll_interval] = 0
|
30
|
+
Sidekiq::Launcher.new(Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq)
|
31
|
+
end
|
32
|
+
end
|
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.0
|
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-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fugit
|
@@ -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
|
@@ -156,6 +142,7 @@ files:
|
|
156
142
|
- lib/sidekiq/cron/launcher.rb
|
157
143
|
- lib/sidekiq/cron/locales/de.yml
|
158
144
|
- lib/sidekiq/cron/locales/en.yml
|
145
|
+
- lib/sidekiq/cron/locales/it.yml
|
159
146
|
- lib/sidekiq/cron/locales/ja.yml
|
160
147
|
- lib/sidekiq/cron/locales/pt.yml
|
161
148
|
- lib/sidekiq/cron/locales/ru.yml
|
@@ -173,17 +160,19 @@ files:
|
|
173
160
|
- test/integration/performance_test.rb
|
174
161
|
- test/test_helper.rb
|
175
162
|
- test/unit/fixtures/schedule_array.yml
|
163
|
+
- test/unit/fixtures/schedule_erb.yml
|
176
164
|
- test/unit/fixtures/schedule_hash.yml
|
177
165
|
- test/unit/fixtures/schedule_string.yml
|
178
166
|
- test/unit/job_test.rb
|
167
|
+
- test/unit/launcher_test.rb
|
179
168
|
- test/unit/poller_test.rb
|
180
169
|
- test/unit/schedule_loader_test.rb
|
181
170
|
- test/unit/web_extension_test.rb
|
182
|
-
homepage: https://github.com/
|
171
|
+
homepage: https://github.com/sidekiq-cron/sidekiq-cron
|
183
172
|
licenses:
|
184
173
|
- MIT
|
185
174
|
metadata: {}
|
186
|
-
post_install_message:
|
175
|
+
post_install_message:
|
187
176
|
rdoc_options: []
|
188
177
|
require_paths:
|
189
178
|
- lib
|
@@ -198,8 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
187
|
- !ruby/object:Gem::Version
|
199
188
|
version: '0'
|
200
189
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
202
|
-
signing_key:
|
190
|
+
rubygems_version: 3.2.33
|
191
|
+
signing_key:
|
203
192
|
specification_version: 4
|
204
193
|
summary: Scheduler/Cron for Sidekiq jobs
|
205
194
|
test_files: []
|