sidekiq-cron 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcff473f7500a6ff2d006bb8af760d697b93aec6090b18e891f63a7b491396e2
4
- data.tar.gz: 03a0e5508ee4f31e9c437c253bef8411a25de83deeb6e8c5eb18ccf84e836b50
3
+ metadata.gz: e256288ae9e2ffd550dfd47aa2d2776cb75edff89c2c7605bbd11685afba79b2
4
+ data.tar.gz: 84eded49d6d3e3da996a73902daf9f27010394b334c769fdebad789acdc006c9
5
5
  SHA512:
6
- metadata.gz: 10d1500431656322f8f33feeec633bda703f601b98f1bc3e7f35e4ccfc93fef4fa4608d750a488282c0d02d274d9b2775969c1c072ebdd74292b00a6687593b8
7
- data.tar.gz: 99aa76218a9acf896e10b801398ba5a6b4935ed33b24bf8fa5be25b0a30bf2c3c5afe2dd7cc30b7ad4b665ed827c1adc9fb48e5bb3987de60513ce334895fbda
6
+ metadata.gz: a329899c823ee69c96a8849eddb5abcfac3d99d5ac0003e2066f7e919c3bc25fa071518d0fe98c308d75d9076925ca22ec77c1fbc66acd1d740f14086c4c6a97
7
+ data.tar.gz: 917fd615b9855cfa55a90624be4769febc0de1d7e0012f928471f1ba5fa1aa543a39a212b8cd725f6be8eeb7d7494df5a3fb74b532abb8a5d970563ceb3b8da6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 2.3.0
6
+
7
+ - **WARNING** The default value for `available_namespaces` has changed from `nil` to `[default_namespace]`. Please refer to the [migration guide](https://github.com/sidekiq-cron/sidekiq-cron/blob/master/README.md#migrating-to-23) for further details (https://github.com/sidekiq-cron/sidekiq-cron/pull/552)
8
+ - Fix deprecation warning for using raw params in WEB extension (https://github.com/sidekiq-cron/sidekiq-cron/pull/547)
9
+ - Allow for sidekiq embedded configuration (https://github.com/sidekiq-cron/sidekiq-cron/pull/549)
10
+ - Load schedule file within sidekiq callback (https://github.com/sidekiq-cron/sidekiq-cron/pull/550)
11
+ - Fix missing default namespace if namespaces are explicitly provided (https://github.com/sidekiq-cron/sidekiq-cron/pull/551)
12
+
5
13
  ## 2.2.0
6
14
 
7
15
  - Add support for Sidekiq v8 (https://github.com/sidekiq-cron/sidekiq-cron/pull/531, https://github.com/sidekiq-cron/sidekiq-cron/pull/538)
data/README.md CHANGED
@@ -56,7 +56,7 @@ gem "sidekiq-cron"
56
56
  'active_job' => true, # enqueue job through Active Job interface
57
57
  'queue_name_prefix' => 'prefix', # Active Job queue with prefix
58
58
  'queue_name_delimiter' => '.', # Active Job queue with custom delimiter (default: '_')
59
- 'description' => 'A sentence describing what work this job performs'
59
+ 'description' => 'A sentence describing what work this job performs',
60
60
  'status' => 'disabled' # default: enabled
61
61
  }
62
62
  ```
@@ -73,7 +73,7 @@ Sidekiq::Cron.configure do |config|
73
73
  config.cron_schedule_file = 'config/my_schedule.yml' # Default is 'config/schedule.yml'
74
74
  config.cron_history_size = 20 # Default is 10
75
75
  config.default_namespace = 'statistics' # Default is 'default'
76
- config.available_namespaces = %w[statistics maintenance billing] # Default is `nil`
76
+ config.available_namespaces = %w[statistics maintenance billing] # Default is `[config.default_namespace]`
77
77
  config.natural_cron_parsing_mode = :strict # Default is :single
78
78
  config.reschedule_grace_period = 300 # Default is 60
79
79
  end
@@ -163,7 +163,7 @@ In the case you'd like to change this value, you can change it via the following
163
163
 
164
164
  ```ruby
165
165
  Sidekiq::Cron.configure do |config|
166
- config.default_namespace = 'statics'
166
+ config.default_namespace = 'statistics'
167
167
  end
168
168
  ```
169
169
 
@@ -179,11 +179,21 @@ Sidekiq::Cron::Job.all('YOUR_OLD_NAMESPACE_NAME').each { |job| job.destroy }
179
179
 
180
180
  #### Available namespaces
181
181
 
182
- By default, Sidekiq Cron retrieves all existing jobs from Redis to determine the namespaces your application uses. However, this approach may not be suitable for large Redis installations. To address this, you can explicitly specify the list of available namespaces using the `available_namespaces` configuration option.
182
+ By default, Sidekiq Cron uses the available_namespaces configuration option to determine which namespaces your application utilizes. The default namespace (`"default"`, by default) is always included in the list of available namespaces.
183
183
 
184
- If `available_namespaces` is set and a job is created with an unexpected namespace, a warning will be printed, and the job will be assigned to the default namespace.
184
+ If you want Sidekiq Cron to automatically detect existing namespaces from the Redis database, you can set `available_namespaces` to the special option `:auto`.
185
185
 
186
- For more details and discussion, see [this issue](https://github.com/sidekiq-cron/sidekiq-cron/issues/516).
186
+ If available_namespaces is explicitly set and a job is created with an unexpected namespace, a warning will be printed, and the job will be assigned to the default namespace.
187
+
188
+ #### Migrating to 2.3
189
+
190
+ As discussed in [this issue](https://github.com/sidekiq-cron/sidekiq-cron/issues/516), the approach introduced in Sidekiq Cron 2.0 for determining available namespaces using the `KEYS` command is not acceptable. Therefore, starting from version 2.3, namespacing has been reworked:
191
+
192
+ - If you were not using the namespacing feature, no action is required. You can even remove `available_namespaces = %w[default]`, as it is now the default.
193
+
194
+ - If you were using the namespacing feature and explicitly specified available namespaces as a list, no changes are needed.
195
+
196
+ - If you were using the namespacing feature and relied on automatic namespace inference, you should either specify all used namespaces explicitly or set `available_namespaces` to `:auto` to maintain automatic detection. However, note that this approach does not scale well (see the referenced issue for details).
187
197
 
188
198
  #### Usage
189
199
 
@@ -530,18 +540,18 @@ RSpec.describe "Cron Schedule" do
530
540
 
531
541
  # Confirms that no jobs in the schedule have an invalid cron string.
532
542
  it "does not return any errors" do
533
- expect(schedule_loader.load).to be_empty
543
+ expect(schedule_loader.load_schedule).to be_empty
534
544
  end
535
545
 
536
546
  # May be subject to churn, but adds confidence.
537
547
  it "adds the expected number of jobs" do
538
- schedule_loader.load
548
+ schedule_loader.load_schedule
539
549
  expect(all_jobs.size).to eq 5
540
550
  end
541
551
 
542
552
  # Confirms that all job classes exist.
543
553
  it "has a valid class for each added job" do
544
- schedule_loader.load
554
+ schedule_loader.load_schedule
545
555
  # Shows that all classes exist (as we can constantize the names without raising).
546
556
  job_classes = all_jobs.map { |job| job.klass.constantize }
547
557
  # Naive check that classes are sidekiq jobs (as they all have `.perfrom_async`).
@@ -32,7 +32,7 @@ module Sidekiq
32
32
 
33
33
  default_namespace = Sidekiq::Cron.configuration.default_namespace
34
34
  @namespace = args["namespace"] || default_namespace
35
- if Sidekiq::Cron::Namespace.available_namespaces_provided? && !Sidekiq::Cron::Namespace.all.include?(@namespace) && @namespace != default_namespace
35
+ if Sidekiq::Cron::Namespace.available_namespaces_provided? && !Sidekiq::Cron::Namespace.all.include?(@namespace)
36
36
  Sidekiq.logger.warn { "Cron Jobs - unexpected namespace #{@namespace} encountered. Assigning to default namespace." }
37
37
  @namespace = default_namespace
38
38
  end
@@ -693,7 +693,7 @@ module Sidekiq
693
693
  def self.job_keys_from_namespace(namespace = Sidekiq::Cron.configuration.default_namespace)
694
694
  Sidekiq.redis do |conn|
695
695
  if namespace == '*'
696
- namespaces = Sidekiq::Cron.configuration.available_namespaces&.map { jobs_key(_1) } || conn.keys(jobs_key(namespace))
696
+ namespaces = Sidekiq::Cron::Namespace.all.map { jobs_key(_1) }
697
697
  namespaces.flat_map { |name| conn.smembers(name) }
698
698
  else
699
699
  conn.smembers(jobs_key(namespace))
@@ -2,25 +2,20 @@ module Sidekiq
2
2
  module Cron
3
3
  class Namespace
4
4
  def self.all
5
- namespaces = Sidekiq::Cron.configuration.available_namespaces
6
- return namespaces if namespaces
7
-
8
- Sidekiq.redis do |conn|
9
- namespaces = conn.keys('cron_jobs:*').collect do |key|
10
- key.split(':').last
5
+ namespaces = case (available_namespaces = Sidekiq::Cron.configuration.available_namespaces)
6
+ when NilClass then []
7
+ when Array then available_namespaces
8
+ when :auto
9
+ Sidekiq.redis do |conn|
10
+ conn.keys('cron_jobs:*').collect do |key|
11
+ key.split(':').last
12
+ end
13
+ end
14
+ else
15
+ raise ArgumentError, "Unexpected value provided for `available_namespaces`: #{available_namespaces.inspect}"
11
16
  end
12
- end
13
-
14
- # Adds the default namespace if not present
15
- has_default = namespaces.detect do |name|
16
- name == Sidekiq::Cron.configuration.default_namespace
17
- end
18
-
19
- unless has_default
20
- namespaces << Sidekiq::Cron.configuration.default_namespace
21
- end
22
17
 
23
- namespaces
18
+ namespaces | [Sidekiq::Cron.configuration.default_namespace]
24
19
  end
25
20
 
26
21
  def self.all_with_count
@@ -33,15 +28,15 @@ module Sidekiq
33
28
  end
34
29
 
35
30
  def self.count(name = Sidekiq::Cron.configuration.default_namespace)
36
- out = 0
37
31
  Sidekiq.redis do |conn|
38
- out = conn.scard("cron_jobs:#{name}")
32
+ conn.scard("cron_jobs:#{name}")
39
33
  end
40
- out
41
34
  end
42
35
 
43
36
  def self.available_namespaces_provided?
44
- !!Sidekiq::Cron.configuration.available_namespaces
37
+ available_namespaces = Sidekiq::Cron.configuration.available_namespaces
38
+
39
+ available_namespaces != nil && available_namespaces != :auto
45
40
  end
46
41
  end
47
42
  end
@@ -49,8 +49,9 @@ module Sidekiq
49
49
  end
50
50
 
51
51
  Sidekiq.configure_server do |config|
52
- schedule_loader = Sidekiq::Cron::ScheduleLoader.new
53
- break unless schedule_loader.has_schedule_file?
54
-
55
- config.on(:startup) { schedule_loader.load_schedule }
52
+ config.on(:startup) do
53
+ schedule_loader = Sidekiq::Cron::ScheduleLoader.new
54
+ next unless schedule_loader.has_schedule_file?
55
+ schedule_loader.load_schedule
56
+ end
56
57
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Cron
5
- VERSION = "2.2.0"
5
+ VERSION = "2.3.0"
6
6
  end
7
7
  end
@@ -16,7 +16,11 @@ module Sidekiq
16
16
  end
17
17
 
18
18
  def redirect_to_previous_or_default
19
- redirect params['redirect'] || namespace_redirect_path
19
+ if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0")
20
+ redirect url_params('redirect') || namespace_redirect_path
21
+ else
22
+ redirect params["redirect"] || namespace_redirect_path
23
+ end
20
24
  end
21
25
 
22
26
  def render_erb(view)
data/lib/sidekiq/cron.rb CHANGED
@@ -58,7 +58,7 @@ module Sidekiq
58
58
  @cron_schedule_file = 'config/schedule.yml'
59
59
  @cron_history_size = 10
60
60
  @default_namespace = 'default'
61
- @available_namespaces = nil
61
+ @available_namespaces = [@default_namespace]
62
62
  @natural_cron_parsing_mode = :single
63
63
  @reschedule_grace_period = 60
64
64
  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: 2.2.0
4
+ version: 2.3.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: 2025-03-20 00:00:00.000000000 Z
11
+ date: 2025-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cronex