sidekiq-cron 2.0.1 → 2.1.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 +5 -0
- data/README.md +20 -1
- data/lib/sidekiq/cron/job.rb +8 -2
- data/lib/sidekiq/cron/locales/es.yml +22 -0
- data/lib/sidekiq/cron/locales/ja.yml +2 -2
- data/lib/sidekiq/cron/namespace.rb +6 -1
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/cron.rb +12 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d5f570d2d2d72cdb4fc1a2458dc6cae7abfa5a0da1f27915310b5d5dc835e89
|
4
|
+
data.tar.gz: 514d74f88c65af3db1956190ca9092d4f1a95d6bce4b0a9191463e2bb0f9181a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61f4af041526789dcf51264baa88a5e1855fa124a0fe9f2c5ed04eec36bd4b617aae1152890ab281d5938914725ba9cce812f70bc258a6e4b8d82b642882212a
|
7
|
+
data.tar.gz: 9e82488bd6459b3ce373e52c94fc3607631b5fc67fa58e578d190368a09f4edc3b4502318646d5285e9fb9d139a080d90d560b28ad31a56e9d01d81d1dc0a2f8
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## 2.1.0
|
6
|
+
|
7
|
+
- Add `available_namespaces` configuration option (https://github.com/sidekiq-cron/sidekiq-cron/pull/524)
|
8
|
+
- I18n fixes and enhancements (https://github.com/sidekiq-cron/sidekiq-cron/pull/520, https://github.com/sidekiq-cron/sidekiq-cron/pull/522)
|
9
|
+
|
5
10
|
## 2.0.1
|
6
11
|
|
7
12
|
- Fix usage of ActiveJob::Base.queue_name (https://github.com/sidekiq-cron/sidekiq-cron/pull/517)
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
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
|
+
[![CI](https://github.com/sidekiq-cron/sidekiq-cron/actions/workflows/ci.yml/badge.svg)](https://github.com/sidekiq-cron/sidekiq-cron/actions/workflows/ci.yml)
|
5
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/)
|
@@ -75,6 +75,7 @@ Sidekiq::Cron.configure do |config|
|
|
75
75
|
config.default_namespace = 'statistics' # Default is 'default'
|
76
76
|
config.natural_cron_parsing_mode = :strict # Default is :single
|
77
77
|
config.reschedule_grace_period = 300 # Default is 60
|
78
|
+
config.available_namespaces = %w[maintenance billing] # Default is `nil`
|
78
79
|
end
|
79
80
|
```
|
80
81
|
|
@@ -166,6 +167,24 @@ Sidekiq::Cron.configure do |config|
|
|
166
167
|
end
|
167
168
|
```
|
168
169
|
|
170
|
+
#### Renaming namespace
|
171
|
+
|
172
|
+
If you rename the namespace of a job that is already running, the gem will not automatically delete the cron job associated with the old namespace. This means you could end up with two cron jobs running simultaneously.
|
173
|
+
|
174
|
+
To avoid this, it is recommended to delete all existing cron jobs associated with the old namespace before making the change. You can achieve this with the following code:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
Sidekiq::Cron::Job.all('YOUR_OLD_NAMESPACE_NAME').each { |job| job.destroy }
|
178
|
+
```
|
179
|
+
|
180
|
+
#### Available namespaces
|
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.
|
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.
|
185
|
+
|
186
|
+
For more details and discussion, see [this issue](https://github.com/sidekiq-cron/sidekiq-cron/issues/516).
|
187
|
+
|
169
188
|
#### Usage
|
170
189
|
|
171
190
|
When creating a new job, you can optionally give a `namespace` attribute, and then you can pass it too in the `find` or `destroy` methods.
|
data/lib/sidekiq/cron/job.rb
CHANGED
@@ -26,11 +26,17 @@ module Sidekiq
|
|
26
26
|
@fetch_missing_args = true if @fetch_missing_args.nil?
|
27
27
|
|
28
28
|
@name = args["name"]
|
29
|
-
@namespace = args["namespace"] || Sidekiq::Cron.configuration.default_namespace
|
30
29
|
@cron = args["cron"]
|
31
30
|
@description = args["description"] if args["description"]
|
32
31
|
@source = args["source"] == "schedule" ? "schedule" : "dynamic"
|
33
32
|
|
33
|
+
default_namespace = Sidekiq::Cron.configuration.default_namespace
|
34
|
+
@namespace = args["namespace"] || default_namespace
|
35
|
+
if Sidekiq::Cron::Namespace.available_namespaces_provided? && !Sidekiq::Cron::Namespace.all.include?(@namespace) && @namespace != default_namespace
|
36
|
+
Sidekiq.logger.warn { "Cron Jobs - unexpected namespace #{@namespace} encountered. Assigning to default namespace." }
|
37
|
+
@namespace = default_namespace
|
38
|
+
end
|
39
|
+
|
34
40
|
# Get class from klass or class.
|
35
41
|
@klass = args["klass"] || args["class"]
|
36
42
|
|
@@ -687,7 +693,7 @@ module Sidekiq
|
|
687
693
|
def self.job_keys_from_namespace(namespace = Sidekiq::Cron.configuration.default_namespace)
|
688
694
|
Sidekiq.redis do |conn|
|
689
695
|
if namespace == '*'
|
690
|
-
namespaces = conn.keys(jobs_key(namespace))
|
696
|
+
namespaces = Sidekiq::Cron.configuration.available_namespaces&.map { jobs_key(_1) } || conn.keys(jobs_key(namespace))
|
691
697
|
namespaces.flat_map { |name| conn.smembers(name) }
|
692
698
|
else
|
693
699
|
conn.smembers(jobs_key(namespace))
|
@@ -0,0 +1,22 @@
|
|
1
|
+
es:
|
2
|
+
AreYouSureDeleteCronJob: ¿Estás seguro de que quieres borrar el trabajo cron %{job}?
|
3
|
+
AreYouSureDeleteCronJobs: ¿Estás seguro de que quieres borrar TODOS los trabajos cron?
|
4
|
+
AreYouSureEnqueueCronJob: ¿Estás seguro de que quieres poner en cola el trabajo cron %{job}?
|
5
|
+
AreYouSureEnqueueCronJobs: ¿Estás seguro de que quieres poner en cola TODOS los trabajos cron?
|
6
|
+
Cron: Cron
|
7
|
+
CronJobs: Trabajos cron programados
|
8
|
+
CronString: Cron
|
9
|
+
DeleteAll: Borrar todo
|
10
|
+
Description: Descripción
|
11
|
+
Disable: Desactivar
|
12
|
+
DisableAll: Desactivar todos
|
13
|
+
Enable: Activar
|
14
|
+
EnableAll: Activar todos
|
15
|
+
EnqueueAll: Poner todos en cola
|
16
|
+
EnqueueNow: Poner en cola ahora
|
17
|
+
Job: Trabajo
|
18
|
+
LastEnqueued: Último trabajo en cola
|
19
|
+
NoCronJobsWereFound: No se encontraron trabajos
|
20
|
+
NoHistoryWereFound: No se encontró histórico de trabajos
|
21
|
+
disabled: activo
|
22
|
+
enabled: inactivo
|
@@ -1,8 +1,8 @@
|
|
1
1
|
ja:
|
2
2
|
AreYouSureDeleteCronJob: "本当に%{job}のcronジョブを削除しますか?"
|
3
3
|
AreYouSureDeleteCronJobs: "本当にすべてのcronジョブを削除しますか?"
|
4
|
-
AreYouSureEnqueueCronJob: "%{job} の
|
5
|
-
AreYouSureEnqueueCronJobs: "すべての
|
4
|
+
AreYouSureEnqueueCronJob: "%{job} の cronジョブをキューに入れてもよろしいですか?"
|
5
|
+
AreYouSureEnqueueCronJobs: "すべての cronジョブをキューに入れてもよろしいですか?"
|
6
6
|
Cron: Cron
|
7
7
|
CronJobs: Cronジョブ
|
8
8
|
CronString: Cron
|
@@ -2,7 +2,8 @@ module Sidekiq
|
|
2
2
|
module Cron
|
3
3
|
class Namespace
|
4
4
|
def self.all
|
5
|
-
namespaces =
|
5
|
+
namespaces = Sidekiq::Cron.configuration.available_namespaces
|
6
|
+
return namespaces if namespaces
|
6
7
|
|
7
8
|
Sidekiq.redis do |conn|
|
8
9
|
namespaces = conn.keys('cron_jobs:*').collect do |key|
|
@@ -38,6 +39,10 @@ module Sidekiq
|
|
38
39
|
end
|
39
40
|
out
|
40
41
|
end
|
42
|
+
|
43
|
+
def self.available_namespaces_provided?
|
44
|
+
!!Sidekiq::Cron.configuration.available_namespaces
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
data/lib/sidekiq/cron/version.rb
CHANGED
data/lib/sidekiq/cron.rb
CHANGED
@@ -42,6 +42,17 @@ module Sidekiq
|
|
42
42
|
# jobs that missed their schedules during the deployment. E.g., jobs that run once a day.
|
43
43
|
attr_accessor :reschedule_grace_period
|
44
44
|
|
45
|
+
# List of available namespaces
|
46
|
+
#
|
47
|
+
# If not set, Sidekiq Cron will dynamically fetch available namespaces
|
48
|
+
# by retrieving existing jobs from Redis.
|
49
|
+
#
|
50
|
+
# This dynamic fetching can negatively impact performance in certain cases.
|
51
|
+
# To mitigate this, you can provide the list of namespaces explicitly.
|
52
|
+
# If a job specifies a namespace that is not included in the provided list,
|
53
|
+
# a warning will be logged, and the job will be assigned to the default namespace.
|
54
|
+
attr_accessor :available_namespaces
|
55
|
+
|
45
56
|
def initialize
|
46
57
|
@cron_poll_interval = 30
|
47
58
|
@cron_schedule_file = 'config/schedule.yml'
|
@@ -49,6 +60,7 @@ module Sidekiq
|
|
49
60
|
@default_namespace = 'default'
|
50
61
|
@natural_cron_parsing_mode = :single
|
51
62
|
@reschedule_grace_period = 60
|
63
|
+
@available_namespaces = nil
|
52
64
|
end
|
53
65
|
|
54
66
|
def natural_cron_parsing_mode=(mode)
|
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.0
|
4
|
+
version: 2.1.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:
|
11
|
+
date: 2025-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cronex
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/sidekiq/cron/launcher.rb
|
191
191
|
- lib/sidekiq/cron/locales/de.yml
|
192
192
|
- lib/sidekiq/cron/locales/en.yml
|
193
|
+
- lib/sidekiq/cron/locales/es.yml
|
193
194
|
- lib/sidekiq/cron/locales/id.yml
|
194
195
|
- lib/sidekiq/cron/locales/it.yml
|
195
196
|
- lib/sidekiq/cron/locales/ja.yml
|
@@ -226,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
227
|
- !ruby/object:Gem::Version
|
227
228
|
version: '0'
|
228
229
|
requirements: []
|
229
|
-
rubygems_version: 3.
|
230
|
+
rubygems_version: 3.4.10
|
230
231
|
signing_key:
|
231
232
|
specification_version: 4
|
232
233
|
summary: Scheduler/Cron for Sidekiq jobs
|