sidekiq-cron 1.9.0 → 1.10.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: b26393b7aa972d9a769d851269600f51c61feff8c3d2b5cbe611eed0e21b704d
4
- data.tar.gz: 1822ffdf4ebe54db931394f38acf3eca8552953396d8fc1848aa3ec89d1164d1
3
+ metadata.gz: f484cd18cea7b3b00d83b82c5ae6ca7e2c831b22ed4d00cd77a19cfc9491b49d
4
+ data.tar.gz: efe62165d5c2b02b4ee2ce7f1ac877cda1bd06d550f4554fbb340b491f8d1319
5
5
  SHA512:
6
- metadata.gz: 8fe8be5571ecb428191894a7d433fd6b2f8098607ad4de23f7cfe030b71895eed66cc8a218bf53684b235a5422b4895a676963f7bc02ab1deb06fae4982a34db
7
- data.tar.gz: b75e0b6928d263590ba7a97beca37205bd50123d0118ee49312a106573bf1a7b640f75c8ef1f76198a3da94fe19a6c9c9fa4bd3d357898590f251732d9a34d43
6
+ metadata.gz: a945824e3d39d8f54a33c68eec458f3dee68be2cd43ddf697b7fdd568afff291ff62ee1ec8cf2bbc05e26ddfa6e8230c78a953499b59b6844ca60b37f55ffc99
7
+ data.tar.gz: 2aa57d5d1e2b4ba98199bf79e13d49b7726478650ef46efa92871e0c13b51608829bc66159d8ed5a2cd58f4b6d5dcb3a6e87329795e604309fc60ba85b583758
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 1.10.0
6
+
7
+ - Remove EOL Ruby 2.6 support (https://github.com/sidekiq-cron/sidekiq-cron/pull/399)
8
+ - Add a logo for the project! (https://github.com/sidekiq-cron/sidekiq-cron/pull/402)
9
+ - Added support for ActiveRecord serialize/deserialize using GlobalID (https://github.com/sidekiq-cron/sidekiq-cron/pull/395)
10
+ - Allow for keyword args (`embedded: true`) in Poller (https://github.com/sidekiq-cron/sidekiq-cron/pull/398)
11
+ - Make last_enqueue_time be always an instance of Time (https://github.com/sidekiq-cron/sidekiq-cron/pull/354)
12
+ - Fix argument error problem update from 1.6.0 to newer (https://github.com/sidekiq-cron/sidekiq-cron/pull/392)
13
+ - Clear old jobs while loading the jobs from schedule via the schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/405)
14
+
15
+ ## 1.9.1
16
+
17
+ - Always enqueue via Active Job interface when defined in cron job config (https://github.com/sidekiq-cron/sidekiq-cron/pull/381)
18
+ - Fix schedule.yml YAML load errors on Ruby 3.1 (https://github.com/sidekiq-cron/sidekiq-cron/pull/386)
19
+ - Require Fugit v1.8 to refactor internals (https://github.com/sidekiq-cron/sidekiq-cron/pull/385)
20
+
5
21
  ## 1.9.0
6
22
 
7
23
  - Sidekiq v7 support (https://github.com/sidekiq-cron/sidekiq-cron/pull/369)
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ # To test different Sidekiq versions
6
+ gem "sidekiq", ENV.fetch("SIDEKIQ_VERSION", ">= 6")
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Sidekiq-Cron
1
+ ![Sidekiq-Cron](logos/cover.png)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/sidekiq-cron.svg)](https://badge.fury.io/rb/sidekiq-cron)
4
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
- [![Coverage Status](https://coveralls.io/repos/github/ondrejbartas/sidekiq-cron/badge.svg?branch=master)](https://coveralls.io/github/ondrejbartas/sidekiq-cron?branch=master)
5
+ [![codecov](https://codecov.io/gh/sidekiq-cron/sidekiq-cron/branch/master/graph/badge.svg?token=VK9IVLIaY8)](https://codecov.io/gh/sidekiq-cron/sidekiq-cron)
6
6
 
7
7
  > A scheduling add-on for [Sidekiq](https://sidekiq.org/)
8
8
 
@@ -26,12 +26,6 @@ Before upgrading to a new version, please read our [Changelog](CHANGELOG.md).
26
26
 
27
27
  ## Installation
28
28
 
29
- ### Requirements
30
-
31
- - Redis 2.8 or greater is required (Redis 3.0.3 or greater is recommended for large scale use)
32
- - Sidekiq 4.2 or greater is required (for Sidekiq < 4 use version sidekiq-cron 0.3.1)
33
- - Sidekiq 6.5 requires Sidekiq-Cron 1.5+
34
-
35
29
  Install the gem:
36
30
 
37
31
  ```
@@ -171,6 +165,26 @@ unless job.save
171
165
  end
172
166
  ```
173
167
 
168
+ Use ActiveRecord models as arguments
169
+
170
+ ```rb
171
+ class Person < ApplicationRecord
172
+ end
173
+
174
+ class HardWorker < ActiveJob::Base
175
+ queue_as :default
176
+
177
+ def perform(person)
178
+ puts "person: #{person}"
179
+ end
180
+ end
181
+
182
+
183
+ person = Person.create(id: 1)
184
+ Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker', args: person)
185
+ # => true
186
+ ```
187
+
174
188
  Load more jobs from hash:
175
189
 
176
190
  ```ruby
@@ -316,7 +330,7 @@ add `require 'sidekiq/cron/web'` after `require 'sidekiq/web'`.
316
330
 
317
331
  With this, you will get:
318
332
 
319
- ![Web UI](examples/web-cron-ui.jpeg)
333
+ ![Web UI](docs/images/web-cron-ui.jpeg)
320
334
 
321
335
  ## Under the hood
322
336
 
@@ -1,4 +1,5 @@
1
1
  require 'fugit'
2
+ require 'globalid'
2
3
  require 'sidekiq'
3
4
  require 'sidekiq/cron/support'
4
5
  require 'sidekiq/options'
@@ -15,6 +16,9 @@ module Sidekiq
15
16
  # Use the exists? method if we're on a newer version of Redis.
16
17
  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
18
 
19
+ # Use serialize/deserialize key of GlobalID.
20
+ GLOBALID_KEY = "_sc_globalid"
21
+
18
22
  # Crucial part of whole enqueuing job.
19
23
  def should_enque? time
20
24
  enqueue = Sidekiq.redis do |conn|
@@ -45,7 +49,7 @@ module Sidekiq
45
49
 
46
50
  # Enqueue cron job to queue.
47
51
  def enque! time = Time.now.utc
48
- @last_enqueue_time = time.strftime(LAST_ENQUEUE_TIME_FORMAT)
52
+ @last_enqueue_time = time
49
53
 
50
54
  klass_const =
51
55
  begin
@@ -56,7 +60,7 @@ module Sidekiq
56
60
 
57
61
  jid =
58
62
  if klass_const
59
- if defined?(ActiveJob::Base) && klass_const < ActiveJob::Base
63
+ if is_active_job?(klass_const)
60
64
  enqueue_active_job(klass_const).try :provider_job_id
61
65
  else
62
66
  enqueue_sidekiq_worker(klass_const)
@@ -74,8 +78,8 @@ module Sidekiq
74
78
  Sidekiq.logger.debug { "enqueued #{@name}: #{@message}" }
75
79
  end
76
80
 
77
- def is_active_job?
78
- @active_job || defined?(ActiveJob::Base) && Sidekiq::Cron::Support.constantize(@klass.to_s) < ActiveJob::Base
81
+ def is_active_job?(klass = nil)
82
+ @active_job || defined?(ActiveJob::Base) && (klass || Sidekiq::Cron::Support.constantize(@klass.to_s)) < ActiveJob::Base
79
83
  rescue NameError
80
84
  false
81
85
  end
@@ -85,7 +89,8 @@ module Sidekiq
85
89
  end
86
90
 
87
91
  def enqueue_args
88
- date_as_argument? ? @args + [Time.now.to_f] : @args
92
+ args = date_as_argument? ? @args + [Time.now.to_f] : @args
93
+ deserialize_argument(args)
89
94
  end
90
95
 
91
96
  def enqueue_active_job(klass_const)
@@ -398,21 +403,26 @@ module Sidekiq
398
403
 
399
404
  # Export job data to hash.
400
405
  def to_hash
401
- {
406
+ hash = {
402
407
  name: @name,
403
408
  klass: @klass.to_s,
404
409
  cron: @cron,
405
410
  description: @description,
406
411
  args: @args.is_a?(String) ? @args : Sidekiq.dump_json(@args || []),
407
- date_as_argument: date_as_argument? ? "1" : "0",
408
412
  message: @message.is_a?(String) ? @message : Sidekiq.dump_json(@message || {}),
409
413
  status: @status,
410
414
  active_job: @active_job ? "1" : "0",
411
415
  queue_name_prefix: @active_job_queue_name_prefix,
412
416
  queue_name_delimiter: @active_job_queue_name_delimiter,
413
- last_enqueue_time: @last_enqueue_time.to_s,
417
+ last_enqueue_time: serialized_last_enqueue_time,
414
418
  symbolize_args: symbolize_args? ? "1" : "0",
415
419
  }
420
+
421
+ if date_as_argument?
422
+ hash.merge!(date_as_argument: "1")
423
+ end
424
+
425
+ hash
416
426
  end
417
427
 
418
428
  def errors
@@ -428,15 +438,7 @@ module Sidekiq
428
438
  errors << "'cron' must be set"
429
439
  else
430
440
  begin
431
- c = Fugit.do_parse(@cron)
432
-
433
- # Since `Fugit.do_parse` might yield a Fugit::Duration or an EtOrbi::EoTime
434
- # https://github.com/floraison/fugit#fugitparses
435
- if c.is_a?(Fugit::Cron)
436
- @parsed_cron = c
437
- else
438
- errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}"
439
- end
441
+ @parsed_cron = Fugit.do_parse_cronish(@cron)
440
442
  rescue => e
441
443
  errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}"
442
444
  end
@@ -480,7 +482,7 @@ module Sidekiq
480
482
  def save_last_enqueue_time
481
483
  Sidekiq.redis do |conn|
482
484
  # Update last enqueue time.
483
- conn.hset redis_key, 'last_enqueue_time', @last_enqueue_time
485
+ conn.hset redis_key, 'last_enqueue_time', serialized_last_enqueue_time
484
486
  end
485
487
  end
486
488
 
@@ -565,19 +567,7 @@ module Sidekiq
565
567
  private
566
568
 
567
569
  def parsed_cron
568
- @parsed_cron ||= begin
569
- c = Fugit.parse(@cron)
570
-
571
- # Since `Fugit.parse` might yield a Fugit::Duration or an EtOrbi::EoTime
572
- # https://github.com/floraison/fugit#fugitparses
573
- if c.is_a?(Fugit::Cron)
574
- c
575
- else
576
- errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}"
577
- end
578
- rescue => e
579
- errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}"
580
- end
570
+ @parsed_cron ||= Fugit.parse_cronish(@cron)
581
571
  end
582
572
 
583
573
  def not_enqueued_after?(time)
@@ -589,6 +579,8 @@ module Sidekiq
589
579
  # try to load JSON, then failover to string array.
590
580
  def parse_args(args)
591
581
  case args
582
+ when GlobalID::Identification
583
+ [convert_to_global_id_hash(args)]
592
584
  when String
593
585
  begin
594
586
  parsed_args = Sidekiq.load_json(args)
@@ -597,8 +589,10 @@ module Sidekiq
597
589
  [*args]
598
590
  end
599
591
  when Hash
592
+ args = serialize_argument(args)
600
593
  symbolize_args? ? [symbolize_args(args)] : [args]
601
594
  when Array
595
+ args = serialize_argument(args)
602
596
  symbolize_args? ? symbolize_args(args) : args
603
597
  else
604
598
  [*args]
@@ -673,6 +667,57 @@ module Sidekiq
673
667
  def hash_to_redis hash
674
668
  hash.flat_map{ |key, value| [key, value || ""] }
675
669
  end
670
+
671
+ def serialized_last_enqueue_time
672
+ @last_enqueue_time&.strftime(LAST_ENQUEUE_TIME_FORMAT)
673
+ end
674
+
675
+ def convert_to_global_id_hash(argument)
676
+ { GLOBALID_KEY => argument.to_global_id.to_s }
677
+ rescue URI::GID::MissingModelIdError
678
+ raise "Unable to serialize #{argument.class} " \
679
+ "without an id. (Maybe you forgot to call save?)"
680
+ end
681
+
682
+ def deserialize_argument(argument)
683
+ case argument
684
+ when String
685
+ argument
686
+ when Array
687
+ argument.map { |arg| deserialize_argument(arg) }
688
+ when Hash
689
+ if serialized_global_id?(argument)
690
+ deserialize_global_id argument
691
+ else
692
+ argument.transform_values { |v| deserialize_argument(v) }
693
+ end
694
+ else
695
+ argument
696
+ end
697
+ end
698
+
699
+ def serialized_global_id?(hash)
700
+ hash.size == 1 && hash.include?(GLOBALID_KEY)
701
+ end
702
+
703
+ def deserialize_global_id(hash)
704
+ GlobalID::Locator.locate hash[GLOBALID_KEY]
705
+ end
706
+
707
+ def serialize_argument(argument)
708
+ case argument
709
+ when GlobalID::Identification
710
+ convert_to_global_id_hash(argument)
711
+ when Array
712
+ argument.map { |arg| serialize_argument(arg) }
713
+ when Hash
714
+ argument.each_with_object({}) do |(key, value), hash|
715
+ hash[key] = serialize_argument(value)
716
+ end
717
+ else
718
+ argument
719
+ end
720
+ end
676
721
  end
677
722
  end
678
723
  end
@@ -14,7 +14,7 @@ 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(config)
17
+ def initialize(config, **kwargs)
18
18
  config[:cron_poll_interval] = DEFAULT_POLL_INTERVAL if config[:cron_poll_interval].nil?
19
19
 
20
20
  @cron_poller = Sidekiq::Cron::Poller.new(config) if config[:cron_poll_interval] > 0
@@ -8,11 +8,11 @@ if Sidekiq.server?
8
8
 
9
9
  if File.exist?(schedule_file)
10
10
  config.on(:startup) do
11
- schedule = YAML.load(ERB.new(IO.read(schedule_file)).result)
11
+ schedule = Sidekiq::Cron::Support.load_yaml(ERB.new(IO.read(schedule_file)).result)
12
12
  if schedule.kind_of?(Hash)
13
- Sidekiq::Cron::Job.load_from_hash schedule
13
+ Sidekiq::Cron::Job.load_from_hash! schedule
14
14
  elsif schedule.kind_of?(Array)
15
- Sidekiq::Cron::Job.load_from_array schedule
15
+ Sidekiq::Cron::Job.load_from_array! schedule
16
16
  else
17
17
  raise "Not supported schedule format. Confirm your #{schedule_file}"
18
18
  end
@@ -32,6 +32,14 @@ module Sidekiq
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ def self.load_yaml(src)
37
+ if Psych::VERSION > "4.0"
38
+ YAML.safe_load(src, permitted_classes: [Symbol], aliases: true)
39
+ else
40
+ YAML.load(src)
41
+ end
42
+ end
35
43
  end
36
44
  end
37
45
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Cron
5
- VERSION = "1.9.0"
5
+ VERSION = "1.10.0"
6
6
  end
7
7
  end
data/sidekiq-cron.gemspec CHANGED
@@ -24,10 +24,11 @@ Gem::Specification.new do |s|
24
24
  "sidekiq-cron.gemspec",
25
25
  ]
26
26
 
27
- s.required_ruby_version = ">= 2.6"
27
+ s.required_ruby_version = ">= 2.7"
28
28
 
29
- s.add_dependency("fugit", "~> 1")
30
- s.add_dependency("sidekiq", ">= 4.2.1")
29
+ s.add_dependency("fugit", "~> 1.8")
30
+ s.add_dependency("sidekiq", ">= 6")
31
+ s.add_dependency("globalid", ">= 1.0.1")
31
32
 
32
33
  s.add_development_dependency("minitest", "~> 5.15")
33
34
  s.add_development_dependency("mocha", "~> 1.14")
@@ -35,4 +36,5 @@ Gem::Specification.new do |s|
35
36
  s.add_development_dependency("rack-test", "~> 1.1")
36
37
  s.add_development_dependency("rake", "~> 13.0")
37
38
  s.add_development_dependency("simplecov", "~> 0.21")
39
+ s.add_development_dependency("simplecov-cobertura", "~> 2.1")
38
40
  end
@@ -0,0 +1,21 @@
1
+ class Person
2
+ include GlobalID::Identification
3
+
4
+ attr_reader :id
5
+
6
+ def self.find(id)
7
+ new(id)
8
+ end
9
+
10
+ def initialize(id)
11
+ @id = id
12
+ end
13
+
14
+ def to_global_id(options = {})
15
+ super app: "app"
16
+ end
17
+
18
+ def ==(other_person)
19
+ other_person.is_a?(Person) && id.to_s == other_person.id.to_s
20
+ end
21
+ end
data/test/test_helper.rb CHANGED
@@ -2,6 +2,12 @@ $TESTING = true
2
2
  ENV['RACK_ENV'] = 'test'
3
3
 
4
4
  require 'simplecov'
5
+
6
+ if ENV['CI']
7
+ require 'simplecov-cobertura'
8
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
9
+ end
10
+
5
11
  SimpleCov.start do
6
12
  add_filter "test/"
7
13
  add_group 'Sidekiq-Cron', 'lib/'
@@ -1,4 +1,6 @@
1
1
  ---
2
- daily_job:
2
+ default: &default
3
3
  cron: <%= "every day at 5 pm" %>
4
4
  class: <%= "DailyJob" %>
5
+
6
+ daily_job: *default
@@ -1,4 +1,5 @@
1
1
  require './test/test_helper'
2
+ require "./test/models/person"
2
3
 
3
4
  describe "Cron Job" do
4
5
  before do
@@ -338,6 +339,45 @@ describe "Cron Job" do
338
339
  assert args[-1].between?(Time.now.to_f - 1, Time.now.to_f)
339
340
  end
340
341
  end
342
+
343
+ describe 'with GlobalID::Identification args' do
344
+ before do
345
+ @args.merge!(args: Person.new(1))
346
+ @job = Sidekiq::Cron::Job.new(@args)
347
+ end
348
+
349
+ let(:args) { @job.sidekiq_worker_message['args'] }
350
+
351
+ it 'should add timestamp to args' do
352
+ assert_equal args[0], Person.new(1)
353
+ end
354
+ end
355
+
356
+ describe 'with GlobalID::Identification args in Array' do
357
+ before do
358
+ @args.merge!(args: [Person.new(1)])
359
+ @job = Sidekiq::Cron::Job.new(@args)
360
+ end
361
+
362
+ let(:args) { @job.sidekiq_worker_message['args'] }
363
+
364
+ it 'should add timestamp to args' do
365
+ assert_equal args[0], Person.new(1)
366
+ end
367
+ end
368
+
369
+ describe 'with GlobalID::Identification args in Hash' do
370
+ before do
371
+ @args.merge!(args: {person: Person.new(1)})
372
+ @job = Sidekiq::Cron::Job.new(@args)
373
+ end
374
+
375
+ let(:args) { @job.sidekiq_worker_message['args'] }
376
+
377
+ it 'should add timestamp to args' do
378
+ assert_equal args[0], {person: Person.new(1)}
379
+ end
380
+ end
341
381
  end
342
382
 
343
383
  describe '#sidekiq_worker_message settings overwrite queue name' do
@@ -581,6 +621,36 @@ describe "Cron Job" do
581
621
  @job.enque!
582
622
  end
583
623
  end
624
+
625
+ describe 'with active_job == true' do
626
+ before do
627
+ @args.merge!(active_job: true)
628
+ end
629
+
630
+ describe 'with active_job job class' do
631
+ before do
632
+ @job = Sidekiq::Cron::Job.new(@args.merge(klass: 'ActiveJobCronTestClass'))
633
+ end
634
+
635
+ it 'enques via active_job interface' do
636
+ @job.expects(:enqueue_active_job)
637
+ .returns(ActiveJobCronTestClass.new)
638
+ @job.enque!
639
+ end
640
+ end
641
+
642
+ describe 'with non sidekiq job class' do
643
+ before do
644
+ @job = Sidekiq::Cron::Job.new(@args.merge(klass: 'CronTestClass'))
645
+ end
646
+
647
+ it 'enques via active_job interface' do
648
+ @job.expects(:enqueue_active_job)
649
+ .returns(ActiveJobCronTestClass.new)
650
+ @job.enque!
651
+ end
652
+ end
653
+ end
584
654
  end
585
655
 
586
656
  describe 'active job with queue_name_prefix' do
@@ -747,6 +817,58 @@ describe "Cron Job" do
747
817
  end
748
818
  end
749
819
 
820
+ # @note sidekiq-cron 1.6.0 cannot process options correctly if any date_as_argument evaluates to true.
821
+ # This has been tested to resolve issues in environments where multiple sidekiq-cron versions are running when updating from 1.6.0
822
+ # See https://github.com/sidekiq-cron/sidekiq-cron/issues/350#issuecomment-1409798837 for more information.
823
+ describe "compat with sidekiq cron 1.6.0" do
824
+ describe "#to_hash with date_as_argument false" do
825
+ before do
826
+ @args = {
827
+ name: "Test",
828
+ cron: "* * * * *",
829
+ klass: "CronTestClass",
830
+ date_as_argument: false,
831
+ }
832
+ @job = Sidekiq::Cron::Job.new(@args)
833
+ end
834
+
835
+ it "should not have date_as_argument property" do
836
+ assert !@job.to_hash.key?(:date_as_argument)
837
+ end
838
+ end
839
+
840
+ describe "#to_hash with no date_as_argument option" do
841
+ before do
842
+ @args = {
843
+ name: "Test",
844
+ cron: "* * * * *",
845
+ klass: "CronTestClass",
846
+ }
847
+ @job = Sidekiq::Cron::Job.new(@args)
848
+ end
849
+
850
+ it "should not have date_as_argument property" do
851
+ assert !@job.to_hash.key?(:date_as_argument)
852
+ end
853
+ end
854
+
855
+ describe "#to_hash with date_as_argument" do
856
+ before do
857
+ @args = {
858
+ name: "Test",
859
+ cron: "* * * * *",
860
+ klass: "CronTestClass",
861
+ date_as_argument: true,
862
+ }
863
+ @job = Sidekiq::Cron::Job.new(@args)
864
+ end
865
+
866
+ it "should have date_as_argument property with value '1'" do
867
+ assert_equal @job.to_hash[:date_as_argument], '1'
868
+ end
869
+ end
870
+ end
871
+
750
872
  describe "save" do
751
873
  before do
752
874
  @args = {
@@ -888,6 +1010,42 @@ describe "Cron Job" do
888
1010
  assert_equal job.name, "Test"
889
1011
  end
890
1012
  end
1013
+
1014
+ it "from GlobalID::Identification" do
1015
+ args = {
1016
+ name: "Test",
1017
+ cron: "* * * * *",
1018
+ klass: "CronTestClass",
1019
+ args: Person.new(1)
1020
+ }
1021
+ Sidekiq::Cron::Job.new(args).tap do |job|
1022
+ assert_equal job.args, [{"_sc_globalid"=>"gid://app/Person/1"}]
1023
+ end
1024
+ end
1025
+
1026
+ it "from GlobalID::Identification in Array" do
1027
+ args = {
1028
+ name: "Test",
1029
+ cron: "* * * * *",
1030
+ klass: "CronTestClass",
1031
+ args: [Person.new(1)]
1032
+ }
1033
+ Sidekiq::Cron::Job.new(args).tap do |job|
1034
+ assert_equal job.args, [{"_sc_globalid"=>"gid://app/Person/1"}]
1035
+ end
1036
+ end
1037
+
1038
+ it "from GlobalID::Identification in Hash" do
1039
+ args = {
1040
+ name: "Test",
1041
+ cron: "* * * * *",
1042
+ klass: "CronTestClass",
1043
+ args: {person: Person.new(1)}
1044
+ }
1045
+ Sidekiq::Cron::Job.new(args).tap do |job|
1046
+ assert_equal job.args, [{person: {"_sc_globalid"=>"gid://app/Person/1"}}]
1047
+ end
1048
+ end
891
1049
  end
892
1050
 
893
1051
  describe "create & find methods" do
@@ -1115,11 +1273,11 @@ describe "Cron Job" do
1115
1273
  end
1116
1274
 
1117
1275
  it "duplicate jobs are not loaded" do
1118
- out = Sidekiq::Cron::Job.load_from_hash @jobs_hash
1276
+ out = Sidekiq::Cron::Job.load_from_hash! @jobs_hash
1119
1277
  assert_equal out.size, 0, "should have no errors"
1120
1278
  assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after load"
1121
1279
 
1122
- out_2 = Sidekiq::Cron::Job.load_from_hash @jobs_hash
1280
+ out_2 = Sidekiq::Cron::Job.load_from_hash! @jobs_hash
1123
1281
  assert_equal out_2.size, 0, "should have no errors"
1124
1282
  assert_equal Sidekiq::Cron::Job.all.size, 2, "Should have 2 jobs after loading again"
1125
1283
  end
@@ -12,7 +12,7 @@ describe 'ScheduleLoader' do
12
12
  end
13
13
 
14
14
  it 'calls Sidekiq::Cron::Job.load_from_hash' do
15
- Sidekiq::Cron::Job.expects(:load_from_hash)
15
+ Sidekiq::Cron::Job.expects(:load_from_hash!)
16
16
  Sidekiq::Options[:lifecycle_events][:startup].first.call
17
17
  end
18
18
  end
@@ -24,7 +24,7 @@ describe 'ScheduleLoader' do
24
24
  end
25
25
 
26
26
  it 'calls Sidekiq::Cron::Job.load_from_array' do
27
- Sidekiq::Cron::Job.expects(:load_from_array)
27
+ Sidekiq::Cron::Job.expects(:load_from_array!)
28
28
  Sidekiq::Options[:lifecycle_events][:startup].first.call
29
29
  end
30
30
  end
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.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondrej Bartas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-01 00:00:00.000000000 Z
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fugit
@@ -16,28 +16,42 @@ 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
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 4.2.1
33
+ version: '6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 4.2.1
40
+ version: '6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: globalid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: minitest
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0.21'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov-cobertura
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.1'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.1'
125
153
  description: Enables to set jobs to be run in specified time (using CRON notation
126
154
  or natural language)
127
155
  email: ondrej@bartas.cz
@@ -158,6 +186,7 @@ files:
158
186
  - lib/sidekiq/options.rb
159
187
  - sidekiq-cron.gemspec
160
188
  - test/integration/performance_test.rb
189
+ - test/models/person.rb
161
190
  - test/test_helper.rb
162
191
  - test/unit/fixtures/schedule_array.yml
163
192
  - test/unit/fixtures/schedule_erb.yml
@@ -180,14 +209,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
209
  requirements:
181
210
  - - ">="
182
211
  - !ruby/object:Gem::Version
183
- version: '2.6'
212
+ version: '2.7'
184
213
  required_rubygems_version: !ruby/object:Gem::Requirement
185
214
  requirements:
186
215
  - - ">="
187
216
  - !ruby/object:Gem::Version
188
217
  version: '0'
189
218
  requirements: []
190
- rubygems_version: 3.2.33
219
+ rubygems_version: 3.4.6
191
220
  signing_key:
192
221
  specification_version: 4
193
222
  summary: Scheduler/Cron for Sidekiq jobs