sidekiq-cron 1.8.0 → 1.9.0

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: 7df934577b0740b3e977ffd0e361f6333de6958921659d78bf4c4e4a0015aad9
4
- data.tar.gz: 6ae3317c56ff984bf0b651df9117121b4cf67cf36d715eee56a7521f47fe0770
3
+ metadata.gz: b26393b7aa972d9a769d851269600f51c61feff8c3d2b5cbe611eed0e21b704d
4
+ data.tar.gz: 1822ffdf4ebe54db931394f38acf3eca8552953396d8fc1848aa3ec89d1164d1
5
5
  SHA512:
6
- metadata.gz: 8948ce194538c052c1761b921a4df485bc99ab5ce9b2e4c12b576d90e10bb6bb1691d7fe111d8ecc6b54e3324d53b8c5c45c0be561d58c4adb4414f08db576b8
7
- data.tar.gz: 2fcccab9c996fe7a6c79c0090875dd81fca30ba6de130af3cf300d1d745e0212e056afe4ea05a8912191703cddf47800f5e3ea6092e1e751091ecf4a3baffc15
6
+ metadata.gz: 8fe8be5571ecb428191894a7d433fd6b2f8098607ad4de23f7cfe030b71895eed66cc8a218bf53684b235a5422b4895a676963f7bc02ab1deb06fae4982a34db
7
+ data.tar.gz: b75e0b6928d263590ba7a97beca37205bd50123d0118ee49312a106573bf1a7b640f75c8ef1f76198a3da94fe19a6c9c9fa4bd3d357898590f251732d9a34d43
data/CHANGELOG.md CHANGED
@@ -2,43 +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
+
5
10
  ## 1.8.0
6
11
 
7
- - Fix deprecation warnings with redis-rb v4.8.0 (https://github.com/ondrejbartas/sidekiq-cron/pull/356)
8
- - Fix poller affecting Sidekiq scheduled set poller (https://github.com/ondrejbartas/sidekiq-cron/pull/359)
9
- - Fix default polling interval (https://github.com/ondrejbartas/sidekiq-cron/pull/362)
10
- - Add italian locale (https://github.com/ondrejbartas/sidekiq-cron/pull/367)
11
- - Allow disabling of cron polling (https://github.com/ondrejbartas/sidekiq-cron/pull/368)
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)
12
17
 
13
18
  ## 1.7.0
14
19
 
15
- - Enable to use cron notation in natural language (ie `every 30 minutes`) (https://github.com/ondrejbartas/sidekiq-cron/pull/312)
16
- - Fix `date_as_argument` feature to add timestamp argument at every cron job execution (https://github.com/ondrejbartas/sidekiq-cron/pull/329)
17
- - Introduce `Sidekiq::Options` to centralize reading/writing options from different Sidekiq versions (https://github.com/ondrejbartas/sidekiq-cron/pull/341)
18
- - Make auto schedule loading compatible with Array format (https://github.com/ondrejbartas/sidekiq-cron/pull/345)
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)
19
24
 
20
25
  ## 1.6.0
21
26
 
22
- - Adds support for auto-loading the `config/schedule.yml` file (https://github.com/ondrejbartas/sidekiq-cron/pull/337)
23
- - Fix `Sidekiq.options` deprecation warning (https://github.com/ondrejbartas/sidekiq-cron/pull/338)
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)
24
29
 
25
30
  ## 1.5.1
26
31
 
27
- - Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/ondrejbartas/sidekiq-cron/pull/335)
32
+ - Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
28
33
 
29
34
  ## 1.5.0
30
35
 
31
- - Integrate Sidekiq v6.5 breaking changes (https://github.com/ondrejbartas/sidekiq-cron/pull/331)
32
- - Add portuguese translations (https://github.com/ondrejbartas/sidekiq-cron/pull/332)
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)
33
38
 
34
39
  ## 1.4.0
35
40
 
36
- - Fix buttons order in job show view (https://github.com/ondrejbartas/sidekiq-cron/pull/302)
37
- - Dark Mode support in UI (https://github.com/ondrejbartas/sidekiq-cron/pull/317/282)
38
- - Remove invocation of deprecated Redis functionality (https://github.com/ondrejbartas/sidekiq-cron/pull/318)
39
- - Internal code cleanup (https://github.com/ondrejbartas/sidekiq-cron/pull/317)
40
- - Optimize gem size (https://github.com/ondrejbartas/sidekiq-cron/pull/322)
41
- - Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/ondrejbartas/sidekiq-cron/pull/321)
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)
42
47
  - Documentation updates
43
48
 
44
49
  ## 1.3.0
@@ -48,12 +53,12 @@ All notable changes to this project will be documented in this file.
48
53
  - Fix deprecation warning for Redis 4.6.x
49
54
  - Fix different response from Redis#exists in different Redis versions
50
55
  - All PRs:
51
- - https://github.com/ondrejbartas/sidekiq-cron/pull/275
52
- - https://github.com/ondrejbartas/sidekiq-cron/pull/287
53
- - https://github.com/ondrejbartas/sidekiq-cron/pull/309
54
- - https://github.com/ondrejbartas/sidekiq-cron/pull/299
55
- - https://github.com/ondrejbartas/sidekiq-cron/pull/314
56
- - https://github.com/ondrejbartas/sidekiq-cron/pull/288
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
57
62
 
58
63
  ## 1.2.0
59
64
 
@@ -122,9 +127,3 @@ All notable changes to this project will be documented in this file.
122
127
  - Suport for Active Job
123
128
  - Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
124
129
  - 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/ondrejbartas/sidekiq-cron/workflows/CI/badge.svg?branch=master)](https://github.com/ondrejbartas/sidekiq-cron/actions)
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
- **Job properties:**
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, 15:01, ... (HH:MM)
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, ex: 12:05, 12:10, 12:15...etc
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
- i.e. `cron_schedule_file: "config/users_schedule.yml"`
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/ondrejbartas/sidekiq-cron/graphs/contributors), you’re awesome and this wouldn’t be possible without you!**
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.
@@ -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, formated_enqueue_time(time), formated_last_time(time))
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.inject([]) do |out,(key, job)|
161
+ array = hash.map do |key, job|
163
162
  job['name'] = key
164
- out << job
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: @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: @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
 
@@ -472,7 +471,8 @@ module Sidekiq
472
471
 
473
472
  # Add information about last time! - don't enque right after scheduler poller starts!
474
473
  time = Time.now.utc
475
- conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time).to_s) unless conn.public_send(REDIS_EXISTS_METHOD, job_enqueued_key)
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
@@ -539,20 +539,19 @@ module Sidekiq
539
539
  parsed_cron.previous_time(now.utc).utc
540
540
  end
541
541
 
542
- def formated_enqueue_time now = Time.now.utc
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 formated_last_time now = Time.now.utc
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 = false
552
- Sidekiq.redis do |conn|
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.inject([]){ |arr,kv| arr + [kv[0], kv[1]] }
674
+ hash.flat_map{ |key, value| [key, value || ""] }
676
675
  end
677
676
  end
678
677
  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(options)
18
- options[:cron_poll_interval] = DEFAULT_POLL_INTERVAL if options[:cron_poll_interval].nil?
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(options) if options[:cron_poll_interval] > 0
21
- super(options)
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.
@@ -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(options = {})
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 = options
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 = YAML.load_file(schedule_file)
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Cron
5
- VERSION = "1.8.0"
5
+ VERSION = "1.9.0"
6
6
  end
7
7
  end
@@ -3,16 +3,23 @@ require 'sidekiq'
3
3
  module Sidekiq
4
4
  module Options
5
5
  def self.[](key)
6
- new_version? ? Sidekiq[key] : Sidekiq.options[key]
6
+ options_field ? Sidekiq.public_send(options_field)[key] : Sidekiq[key]
7
7
  end
8
8
 
9
9
  def self.[]=(key, value)
10
- new_version? ? Sidekiq[key] = value : Sidekiq.options[key] = value
10
+ options_field ? Sidekiq.public_send(options_field)[key] = value : Sidekiq[key] = value
11
11
  end
12
12
 
13
- # sidekiq --version >= 6.5.0
14
- def self.new_version?
15
- @new_version ||= Sidekiq.respond_to?(:[])
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/ondrejbartas/sidekiq-cron"
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
- X = 10000
6
- before do
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.keys("cron_job*").each do |key|
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
- X.times do |i|
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 'should enqueue 10000 jobs in less than 50s' do
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 X, conn.llen("queue:default"), 'Queue should be full'
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, :<, 50
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 "/test/"
7
- add_group 'SidekiqCron', 'lib/'
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 = { :url => redis_url, :namespace => 'testy' }
21
+ config.redis = { url: ENV['REDIS_URL'] || 'redis://0.0.0.0:6379' }
25
22
  end
26
23
 
27
- require 'sidekiq-cron'
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 }
@@ -0,0 +1,4 @@
1
+ ---
2
+ daily_job:
3
+ cron: <%= "every day at 5 pm" %>
4
+ class: <%= "DailyJob" %>
@@ -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.formated_last_time(@time)
181
+ assert_equal '2015-01-02T02:04:00Z', @job.formatted_last_time(@time)
182
182
  end
183
183
 
184
- it 'returns formated_enqueue_time' do
185
- assert_equal '1420164240.0', @job.formated_enqueue_time(@time)
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
 
@@ -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
@@ -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.keys("cron_job*").each do |key|
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.options[:lifecycle_events][:startup].clear
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.options[:lifecycle_events][:startup].first.call
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.options[:lifecycle_events][:startup].first.call
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.options[:lifecycle_events][:startup].first.call
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
- REDIS.with { |c| c.respond_to?(:redis) ? c.redis.flushdb : c.flushdb }
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.8.0
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-10-03 00:00:00.000000000 Z
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
@@ -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/ondrejbartas/sidekiq-cron
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.1.6
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: []