sidekiq-cron 2.2.0 → 2.3.1

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: 8e088e2cce323ffd21798bdaf3818e6b49bb5dd7ae98e4005899df45603c9529
4
+ data.tar.gz: b3771467c144d7ac4de9f30f00f15fdff4fba7750ee3b0e74df09a3fd88215ba
5
5
  SHA512:
6
- metadata.gz: 10d1500431656322f8f33feeec633bda703f601b98f1bc3e7f35e4ccfc93fef4fa4608d750a488282c0d02d274d9b2775969c1c072ebdd74292b00a6687593b8
7
- data.tar.gz: 99aa76218a9acf896e10b801398ba5a6b4935ed33b24bf8fa5be25b0a30bf2c3c5afe2dd7cc30b7ad4b665ed827c1adc9fb48e5bb3987de60513ce334895fbda
6
+ metadata.gz: 25cf2dc9507fc3b8a8e65b9a0e14bbc52449be13c4e7083f059b3cd1d07b0bac8006a3db5c77d37a18372cce12241e99c46f8d370c39ed8bcfc3a9791429c013
7
+ data.tar.gz: 60126836a12d6d1df44f76f2fdf4c473b1ec4e5dc723582e092cb6ac5e47178cffa7bf048b2afa7bf2fcf7f1428dd9ea1f4a8eb5ffe1c9b868a733fed12d0d0a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 2.3.1
6
+
7
+ - Fix manually launch enqueue job not working from web UI (https://github.com/sidekiq-cron/sidekiq-cron/pull/564)
8
+
9
+ ## 2.3.0
10
+
11
+ - **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)
12
+ - Fix deprecation warning for using raw params in WEB extension (https://github.com/sidekiq-cron/sidekiq-cron/pull/547)
13
+ - Allow for sidekiq embedded configuration (https://github.com/sidekiq-cron/sidekiq-cron/pull/549)
14
+ - Load schedule file within sidekiq callback (https://github.com/sidekiq-cron/sidekiq-cron/pull/550)
15
+ - Fix missing default namespace if namespaces are explicitly provided (https://github.com/sidekiq-cron/sidekiq-cron/pull/551)
16
+
5
17
  ## 2.2.0
6
18
 
7
19
  - 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`).
@@ -17,8 +17,8 @@ module Sidekiq
17
17
  # Use serialize/deserialize key of GlobalID.
18
18
  GLOBALID_KEY = "_sc_globalid"
19
19
 
20
- attr_accessor :name, :namespace, :cron, :description, :klass, :args, :message
21
- attr_reader :cron_expression_string, :last_enqueue_time, :fetch_missing_args, :source
20
+ attr_accessor :name, :namespace, :cron, :description, :klass, :message
21
+ attr_reader :last_enqueue_time, :fetch_missing_args, :source, :args
22
22
 
23
23
  def initialize input_args = {}
24
24
  args = Hash[input_args.map{ |k, v| [k.to_s, v] }]
@@ -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
@@ -379,7 +379,7 @@ module Sidekiq
379
379
 
380
380
  def human_cron
381
381
  Cronex::ExpressionDescriptor.new(cron).description
382
- rescue => e
382
+ rescue
383
383
  cron
384
384
  end
385
385
 
@@ -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.1"
6
6
  end
7
7
  end
@@ -5,7 +5,7 @@
5
5
  <small>(<%= @current_namespace %>)</small>
6
6
  </h2>
7
7
  <% if @cron_jobs.size > 0 %>
8
- <form class="filter">
8
+ <div class="filter buttons-row">
9
9
  <form action="<%= root_path %>cron/namespaces/<%= @current_namespace %>/all/delete" method="post">
10
10
  <%= csrf_tag %>
11
11
  <input class="btn btn-danger" type="submit" name="delete" value="<%= t('DeleteAll') %>" data-confirm="<%= t('AreYouSureDeleteCronJobs') %>" />
@@ -22,7 +22,7 @@
22
22
  <%= csrf_tag %>
23
23
  <input class="btn btn-primary" type="submit" name="enqueue" value="<%= t('EnqueueAll') %>" data-confirm="<%= t('AreYouSureEnqueueCronJobs') %>" />
24
24
  </form>
25
- </form>
25
+ </div>
26
26
  <% end %>
27
27
  </header>
28
28
  <!-- Namespaces -->
@@ -6,8 +6,8 @@
6
6
  <small><%= @job.name %></small>
7
7
  </h2>
8
8
  </div>
9
- <form class="filter">
10
- <% cron_job_path = "#{root_path}cron/namespaces/#{@current_namespace}/jobs/#{CGI.escape(@job.name).gsub('+', '%20')}" %>
9
+ <% cron_job_path = "#{root_path}cron/namespaces/#{@current_namespace}/jobs/#{CGI.escape(@job.name).gsub('+', '%20')}" %>
10
+ <div class="filter buttons-row">
11
11
  <form action="<%= cron_job_path %>/enqueue?redirect=<%= cron_job_path %>" method="post">
12
12
  <%= csrf_tag %>
13
13
  <input class="btn btn-primary" name="enqueue" type="submit" value="<%= t('EnqueueNow') %>" data-confirm="<%= t('AreYouSureEnqueueCronJob', :job => @job.name) %>" />
@@ -27,7 +27,7 @@
27
27
  <input class="btn btn-danger" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => @job.name) %>" name="delete" type="submit" value="<%= t('Delete') %>" />
28
28
  </form>
29
29
  <% end %>
30
- </form>
30
+ </div>
31
31
  </header>
32
32
  <table class="table table-bordered table-striped">
33
33
  <tbody>
@@ -90,4 +90,4 @@
90
90
  <% else %>
91
91
  <div class='alert alert-success'><%= t 'NoHistoryWereFound' %></div>
92
92
  <% end %>
93
- </section>
93
+ </section>
@@ -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.1
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-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cronex
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements: []
232
- rubygems_version: 3.5.16
232
+ rubygems_version: 3.4.10
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: Scheduler/Cron for Sidekiq jobs