dynamodb-sidekiq-scheduler 0.4 → 0.5

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: 44238e2d235ddfb9e7d9afd49f11ed04818fed695fe89f8c6a5582fdaf6fd7b8
4
- data.tar.gz: 15a508861db4aa29f69dfe8caf6dce4dd49d57f47999bb148cf0a1d2f88c1857
3
+ metadata.gz: edfdd3c98244e64bedb7799d4ef3c26f4b155cb9941b3506566364ff28ccd819
4
+ data.tar.gz: b8c5723d85a3ae4b53cc6e64768cf7c54ead6463734d9f0ea26b9bcb6e7af4a9
5
5
  SHA512:
6
- metadata.gz: 3e9a24d3c229f41eedd44ac00922c6ce8eaa75be5757f290c70b6d51fb205dee4552b328e4836a5b85d7c89b6d8eb033a8fa382e725e400259a592e20a2e951d
7
- data.tar.gz: c8750a1a82c076d84a54cfabcdf02b463b061e2d7eddc45c87d6f5d28200d55b2eaa0d1040c6de2f9d716c25e8a45cc1ae29da6eb91f178f71d202f55da6b200
6
+ metadata.gz: 2a86e0424c481068e135dd48fe6b51ece4d331c0f7649d6f1faf087a03d671598675525bc16c909e456adda54cd164d51b5f6569ab52ee474b7a840709d19e7a
7
+ data.tar.gz: 3d7df3c11fce1677a47260272da36f02ca89518818bc54e8cbfe19ea473b1a753b2d857f9a5d50ac9c435f59b4a6a688771b110b680803e650fef04ccc2fd39f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
1
+ # 5.0.6
2
+ - [**FIX**] Fix typo in `config#to_hash` method [#479](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/479)
3
+ - [**FIX**] Correctly clear scheduled jobs with Scheduler#clear_schedule! [#485](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/485)
4
+ - [**FIX**] Fix scheduling of aperiodic cron jobs [#487](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/487) (see [#484](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/484) for more details as well)
5
+
6
+ # 5.0.5
7
+ - [**FIX**] Use correct folder structure for assets [#476](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/476)
8
+
9
+ # 5.0.4
10
+ - [**FIX**] Ensure rufus-scheduler has a default rufus_scheduler_options value [#434](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/426)
11
+ - [**ENHANCEMENT**] Remove code related to sidekiq < 6 [#443](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/443)
12
+ - [**ENHANCEMENT**] Change cache-control to `private` [#446](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/446)
13
+ - [**ENHANCEMENT**] Increase compatibility range with tilt dependency [#458](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/458)
14
+ - [**ENHANCEMENT**] Ensure we support Ruby 3.3 [#461](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/461)
15
+ - [**ENHANCEMENT**] Use Redis MULTI command (https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/464)
16
+ - [**ENHANCEMENT**] Don't attempt to set jon next_time when job is nil [#466](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/466)
17
+ - [**ENHANCEMENT**] Improvements to prevent jobs been enqueued multiple times due to a delay in job execution [#463](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/463)
18
+ - [**FIX**] Prevent stack level too deep error by implementing `to_hash` method [#470](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/470)
19
+ - [**ENHANCEMENT**] Support new Sidekiq model for registering UI plugins [#472](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/472)
20
+ - [**ENHANCEMENT**] Stop testing against Ruby 2.7 and 3.0 [#472](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/472#discussion_r1663197863)
21
+ - [**ENHANCEMENT**] Display `at` and `in` in the dashboard [#291](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/291)
22
+ - [**ENHANCEMENT**] Docs enhancements [#442](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/442), [#449](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/449), [#457](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/457), [#465](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/465), [58e1835](https://github.com/sidekiq-scheduler/sidekiq-scheduler/commit/58e18351054fc3c264b2b5a684173316f674c386)
23
+
24
+
25
+ # 5.0.3
26
+
27
+ - [**FIX**] Fix "uppercase character in header name: Cache-Control" [#432](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/432)
28
+ - [**ENHANCEMENT**] Add gd translation [#433](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/433)
29
+ - [**ENHANCEMENT**] Add French translation [#435](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/435)
30
+ - [**FIX**] Remove usage of deprecated Redis command `zrangebyscore` [#437](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/437)
31
+ - [**ENHANCEMENT**] Add the ability to force a job args hash to be deconstructed to keyword arguments [#440](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/440)
32
+
1
33
  # 5.0.2
2
34
 
3
35
  - [**FIX**] Fix YARD docblocks. [#427](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/427)
@@ -11,7 +43,7 @@
11
43
 
12
44
  # 5.0.0
13
45
 
14
- - [**FIX**] Ensure generated scheduled time has a precision of 3 miliseconds. [#418](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/418)
46
+ - [**FIX**] Ensure generated scheduled time has a precision of 3 milliseconds. [#418](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/418)
15
47
 
16
48
  *Note 1:* Check [# 5.0.0.beta1](#500beta1) & [# 5.0.0.beta2](#500beta2) releases for breaking changes.
17
49
 
@@ -64,6 +96,6 @@
64
96
  - [**ENHANCEMENT**] Highlight disabled jobs [#369](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/369)
65
97
  - [**BREAKING CHANGE**] Require redis 4.2.0 [#370](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/370)
66
98
  - [**FIX**] Fixes redis deprecation warning regarding `exists` [#370](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/370)
67
- - [**BREAKING CHANGE**] Remove dependecy on thwait and e2mmap [#371](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/371)
99
+ - [**BREAKING CHANGE**] Remove dependency on thwait and e2mmap [#371](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/371)
68
100
  - Support Ruby 3.1 [#373](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/373)
69
101
  - [**BREAKING CHANGE**] Set rufus_scheduler_options via sidekiq.yml file as configuration option [#375](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/375)
data/README.md CHANGED
@@ -37,7 +37,7 @@ gem install sidekiq-scheduler
37
37
  require 'sidekiq-scheduler'
38
38
 
39
39
  class HelloWorld
40
- include Sidekiq::Worker
40
+ include Sidekiq::Job
41
41
 
42
42
  def perform
43
43
  puts 'Hello world'
@@ -45,6 +45,8 @@ class HelloWorld
45
45
  end
46
46
  ```
47
47
 
48
+ __Note:__ In Sidekiq v6.3 `Sidekiq::Job` was introduced as an alias for `Sidekiq::Worker`. `Sidekiq::Worker` has been officially deprecated in Sidekiq v7 although it still exists for backwards compatibility. It is therefore recommended to use `include Sidekiq::Job` in the above example unless an older version of Sidekiq is required.
49
+
48
50
  ``` yaml
49
51
  # config/sidekiq.yml
50
52
 
@@ -55,6 +57,9 @@ end
55
57
  class: HelloWorld
56
58
  ```
57
59
 
60
+ > [!NOTE]
61
+ > sidekiq-scheduler uses [fugit](https://github.com/floraison/fugit) under the hood, which supports up to six arguments as the cron string, [see](https://github.com/floraison/fugit?tab=readme-ov-file#the-second-extension).
62
+
58
63
  Run sidekiq:
59
64
 
60
65
  ``` sh
@@ -119,6 +124,25 @@ The schedule is configured through the `:scheduler:` -> `:schedule` config entry
119
124
 
120
125
  # Enable / disable a job. All jobs are enabled by default.
121
126
  enabled: true
127
+
128
+ # Deconstructs a hash defined as the `args` to keyword arguments.
129
+ #
130
+ # `false` by default.
131
+ #
132
+ # Example
133
+ #
134
+ # my_job:
135
+ # cron: '0 0 * * * *'
136
+ # class: MyJob
137
+ # args: { foo: 'bar', hello: 'world' }
138
+ # keyword_argument: true
139
+ #
140
+ # class MyJob < ActiveJob::Base
141
+ # def perform(foo:, hello:)
142
+ # # ...
143
+ # end
144
+ # end
145
+ keyword_argument: true
122
146
  ```
123
147
 
124
148
  ### Schedule metadata
@@ -189,7 +213,7 @@ At, and in types push jobs only once. `at` schedules in a point in time:
189
213
  at: '3001/01/01'
190
214
  ```
191
215
 
192
- You can specify any string that `DateTime.parse` and `Chronic` understand. To enable Chronic
216
+ You can specify any string that `DateTime.parse` and `Chronic` understand. To enable [Chronic](https://github.com/mojombo/chronic)
193
217
  strings, you must add it as a dependency.
194
218
 
195
219
  `in` triggers after a time duration has elapsed:
@@ -313,7 +337,7 @@ You can also override the thread pool size in Rufus Scheduler by setting the fol
313
337
  ## Notes about running on Multiple Hosts
314
338
 
315
339
  Under normal conditions, `cron` and `at` jobs are pushed once regardless of the number of `sidekiq-scheduler` running instances,
316
- assumming that time deltas between hosts is less than 24 hours.
340
+ assuming that time deltas between hosts is less than 24 hours.
317
341
 
318
342
  Non-normal conditions that could push a specific job multiple times are:
319
343
  - high cpu load + a high number of jobs scheduled at the same time, like 100 jobs
@@ -340,7 +364,7 @@ MyRegularJob:
340
364
  Then we can conditionally load it via an initializer:
341
365
 
342
366
  ```ruby
343
- # config/initializer/sidekiq.rb
367
+ # config/initializers/sidekiq.rb
344
368
  if ENV.fetch("IS_SCHEDULER", false)
345
369
  Sidekiq.configure_server do |config|
346
370
  config.on(:startup) do
@@ -470,7 +494,7 @@ end
470
494
 
471
495
  ## The Spring preloader and Testing your initializer via Rails console
472
496
 
473
- If you're pulling in your schedule from a YML file via an initializer as shown, be aware that the Spring application preloader included with Rails will interefere with testing via the Rails console.
497
+ If you're pulling in your schedule from a YML file via an initializer as shown, be aware that the Spring application preloader included with Rails will interfere with testing via the Rails console.
474
498
 
475
499
  **Spring will not reload initializers** unless the initializer is changed. Therefore, if you're making a change to your YML schedule file and reloading Rails console to see the change, Spring will make it seem like your modified schedule is not being reloaded.
476
500
 
@@ -515,7 +539,7 @@ MIT License
515
539
 
516
540
  ## Copyright
517
541
 
518
- - Copyright 2021 - 2022 Marcelo Lauxen.
542
+ - Copyright 2021 - 2024 Marcelo Lauxen.
519
543
  - Copyright 2013 - 2022 Moove-IT.
520
544
  - Copyright 2012 Morton Jonuschat.
521
545
  - Some parts copyright 2010 Ben VandenBos.
@@ -59,6 +59,17 @@ module SidekiqScheduler
59
59
  SidekiqScheduler::SidekiqAdapter.sidekiq_queues(sidekiq_config)
60
60
  end
61
61
 
62
+ def to_hash
63
+ {
64
+ enabled: enabled?,
65
+ dynamic: dynamic?,
66
+ dynamic_every: dynamic_every?,
67
+ schedule: schedule,
68
+ listened_queues_only: listened_queues_only?,
69
+ rufus_scheduler_options: rufus_scheduler_options
70
+ }
71
+ end
72
+
62
73
  private
63
74
 
64
75
  attr_reader :scheduler_config
@@ -1,14 +1,27 @@
1
1
  require 'sidekiq/web' unless defined?(Sidekiq::Web)
2
2
 
3
- ASSETS_PATH = File.expand_path('../../../web/assets', __dir__)
3
+ if SidekiqScheduler::SidekiqAdapter::SIDEKIQ_GTE_7_3_0
4
4
 
5
- Sidekiq::Web.register(SidekiqScheduler::Web)
6
- Sidekiq::Web.tabs['recurring_jobs'] = 'recurring-jobs'
7
- Sidekiq::Web.locales << File.expand_path("#{File.dirname(__FILE__)}/../../../web/locales")
5
+ # Locale and asset cache is configured in `.register`
6
+ Sidekiq::Web.register(SidekiqScheduler::Web,
7
+ name: "recurring_jobs",
8
+ tab: ["Recurring Jobs"],
9
+ index: ["recurring-jobs"],
10
+ root_dir: File.expand_path("../../../web", File.dirname(__FILE__)),
11
+ asset_paths: ["stylesheets-scheduler"]) do |app|
12
+ # add middleware or additional settings here
13
+ end
8
14
 
9
- if Sidekiq::VERSION >= '6.0.0'
10
- Sidekiq::Web.use Rack::Static, urls: ['/stylesheets-scheduler'],
15
+ else
16
+
17
+ ASSETS_PATH = File.expand_path('../../../web/assets', __dir__)
18
+
19
+ Sidekiq::Web.register(SidekiqScheduler::Web)
20
+ Sidekiq::Web.tabs['recurring_jobs'] = 'recurring-jobs'
21
+ Sidekiq::Web.locales << File.expand_path("#{File.dirname(__FILE__)}/../../../web/locales")
22
+
23
+ Sidekiq::Web.use Rack::Static, urls: ['/recurring_jobs/stylesheets-scheduler'],
11
24
  root: ASSETS_PATH,
12
25
  cascade: true,
13
- header_rules: [[:all, { 'Cache-Control' => 'public, max-age=86400' }]]
26
+ header_rules: [[:all, { 'cache-control' => 'private, max-age=86400' }]]
14
27
  end
@@ -38,7 +38,7 @@ module SidekiqScheduler
38
38
  #
39
39
  # @return [String] with the job's interval
40
40
  def interval
41
- @attributes['cron'] || @attributes['interval'] || @attributes['every']
41
+ @attributes['cron'] || @attributes['interval'] || @attributes['every'] || @attributes['at'] || @attributes['in']
42
42
  end
43
43
 
44
44
  # Returns the queue of the job
@@ -24,6 +24,15 @@ module SidekiqScheduler
24
24
  @scheduler_instance.load_schedule!
25
25
  end
26
26
 
27
+ # This method is needed to avoid exposing unnecessary information.
28
+ # Because ActiveSupport's `as_json` traverses instance values to convert the object to a hash
29
+ # unless it responds to `to_hash`.
30
+ def to_hash
31
+ {
32
+ scheduler: @scheduler_instance.to_hash
33
+ }
34
+ end
35
+
27
36
  private
28
37
 
29
38
  def set_current_scheduler_options(config)
@@ -106,7 +106,7 @@ module SidekiqScheduler
106
106
  #
107
107
  # @return [Array] array with all the changed job names
108
108
  def self.get_schedule_changes(from, to)
109
- Sidekiq.redis { |r| r.zrangebyscore(schedules_changed_key, from, "(#{to}") }
109
+ SidekiqScheduler::SidekiqAdapter.redis_zrangebyscore(schedules_changed_key, from, "(#{to}")
110
110
  end
111
111
 
112
112
  # Register a schedule change for a given job
@@ -121,7 +121,7 @@ module SidekiqScheduler
121
121
  Sidekiq.redis { |r| r.del(schedules_changed_key) unless r.type(schedules_changed_key) == 'zset' }
122
122
  end
123
123
 
124
- # Removes a queued job instance
124
+ # Registers a queued job instance
125
125
  #
126
126
  # @param [String] job_name The name of the job
127
127
  # @param [Time] time The time at which the job was cleared by the scheduler
@@ -130,9 +130,9 @@ module SidekiqScheduler
130
130
  def self.register_job_instance(job_name, time)
131
131
  job_key = pushed_job_key(job_name)
132
132
  registered, _ = Sidekiq.redis do |r|
133
- r.pipelined do |pipeline|
134
- pipeline.zadd(job_key, time.to_i, time.to_i)
135
- pipeline.expire(job_key, REGISTERED_JOBS_THRESHOLD_IN_SECONDS)
133
+ r.multi do |m|
134
+ m.zadd(job_key, time.to_i, time.to_i)
135
+ m.expire(job_key, REGISTERED_JOBS_THRESHOLD_IN_SECONDS)
136
136
  end
137
137
  end
138
138
 
@@ -65,7 +65,7 @@ module SidekiqScheduler
65
65
  end
66
66
  alias_method :schedule!, :reload_schedule!
67
67
 
68
- # Retrive the schedule configuration for the given name
68
+ # Retrieve the schedule configuration for the given name
69
69
  # if the name is nil it returns a hash with all the
70
70
  # names end their schedules.
71
71
  def get_schedule(name = nil)
@@ -17,7 +17,7 @@ module SidekiqScheduler
17
17
  # saying we will have to do it somehow still)
18
18
  #
19
19
  # NOTE: ^ Keeping this TODO here for now, in a future version of this project
20
- # we will remove those attr acessors and use only our config object. For now,
20
+ # we will remove those attr accessors and use only our config object. For now,
21
21
  # let's keep as it is.
22
22
 
23
23
  # Set to enable or disable the scheduler.
@@ -58,7 +58,7 @@ module SidekiqScheduler
58
58
  self.dynamic = config.dynamic?
59
59
  self.dynamic_every = config.dynamic_every?
60
60
  self.listened_queues_only = config.listened_queues_only?
61
- self.rufus_scheduler_options = config.rufus_scheduler_options
61
+ self.rufus_scheduler_options = config.rufus_scheduler_options || {}
62
62
  end
63
63
 
64
64
  # the Rufus::Scheduler jobs that are scheduled
@@ -128,6 +128,8 @@ module SidekiqScheduler
128
128
  schedule, options = SidekiqScheduler::RufusUtils.normalize_schedule_options(config_interval_type)
129
129
 
130
130
  rufus_job = new_job(name, interval_type, config, schedule, options)
131
+ return unless rufus_job
132
+
131
133
  @scheduled_jobs[name] = rufus_job
132
134
  SidekiqScheduler::Utils.update_job_next_time(name, rufus_job.next_time)
133
135
 
@@ -194,7 +196,7 @@ module SidekiqScheduler
194
196
  @rufus_scheduler = nil
195
197
  end
196
198
 
197
- @@scheduled_jobs = {}
199
+ @scheduled_jobs = {}
198
200
 
199
201
  rufus_scheduler
200
202
  end
@@ -248,6 +250,12 @@ module SidekiqScheduler
248
250
  end
249
251
  end
250
252
 
253
+ def to_hash
254
+ {
255
+ scheduler_config: @scheduler_config.to_hash
256
+ }
257
+ end
258
+
251
259
  private
252
260
 
253
261
  attr_reader :scheduler_config
@@ -256,7 +264,15 @@ module SidekiqScheduler
256
264
  options = options.merge({ :job => true, :tags => [name] })
257
265
 
258
266
  rufus_scheduler.send(interval_type, schedule, options) do |job, time|
259
- idempotent_job_enqueue(name, time, SidekiqScheduler::Utils.sanitize_job_config(config)) if job_enabled?(name)
267
+ if job_enabled?(name)
268
+ conf = SidekiqScheduler::Utils.sanitize_job_config(config)
269
+
270
+ if job.is_a?(Rufus::Scheduler::CronJob)
271
+ idempotent_job_enqueue(name, SidekiqScheduler::Utils.calc_cron_run_time(job.cron_line, time.to_t), conf)
272
+ else
273
+ idempotent_job_enqueue(name, time.to_t, conf)
274
+ end
275
+ end
260
276
  end
261
277
  end
262
278
 
@@ -287,12 +303,12 @@ module SidekiqScheduler
287
303
  end
288
304
 
289
305
  # Adds a Hash with schedule metadata as the last argument to call the worker.
290
- # It currently returns the schedule time as a Float number representing the milisencods
306
+ # It currently returns the schedule time as a Float number representing the milliseconds
291
307
  # since epoch.
292
308
  #
293
309
  # @example with hash argument
294
310
  # arguments_with_metadata({value: 1}, scheduled_at: Time.now.round(3))
295
- # #=> [{value: 1}, {scheduled_at: <miliseconds since epoch>}]
311
+ # #=> [{value: 1}, {scheduled_at: <milliseconds since epoch>}]
296
312
  #
297
313
  # @param args [Array|Hash]
298
314
  # @param metadata [Hash]
@@ -4,6 +4,7 @@ module SidekiqScheduler
4
4
  class SidekiqAdapter
5
5
  SIDEKIQ_GTE_6_5_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
6
6
  SIDEKIQ_GTE_7_0_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.0.0')
7
+ SIDEKIQ_GTE_7_3_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.3.0')
7
8
 
8
9
  def self.fetch_scheduler_config_from_sidekiq(sidekiq_config)
9
10
  return {} if sidekiq_config.nil?
@@ -76,5 +77,15 @@ module SidekiqScheduler
76
77
  end
77
78
  end
78
79
  end
80
+
81
+ def self.redis_zrangebyscore(key, from, to)
82
+ Sidekiq.redis do |r|
83
+ if SIDEKIQ_GTE_7_0_0
84
+ r.zrange(key, from, to, "BYSCORE")
85
+ else
86
+ r.zrangebyscore(key, from, to)
87
+ end
88
+ end
89
+ end
79
90
  end
80
91
  end
@@ -60,9 +60,11 @@ module SidekiqScheduler
60
60
  # @param [Array, Hash] args The parameters passed to the klass initializer
61
61
  #
62
62
  # @return [Object] instance of the class klass
63
- def self.initialize_active_job(klass, args)
63
+ def self.initialize_active_job(klass, args, keyword_argument = false)
64
64
  if args.is_a?(Array)
65
65
  klass.new(*args)
66
+ elsif args.is_a?(Hash) && keyword_argument
67
+ klass.new(**symbolize_keys(args))
66
68
  else
67
69
  klass.new(args)
68
70
  end
@@ -71,7 +73,7 @@ module SidekiqScheduler
71
73
  # Returns true if the enqueuing needs to be done for an ActiveJob
72
74
  # class false otherwise.
73
75
  #
74
- # @param [Class] klass the class to check is decendant from ActiveJob
76
+ # @param [Class] klass the class to check is descendant from ActiveJob
75
77
  #
76
78
  # @return [Boolean]
77
79
  def self.active_job_enqueue?(klass)
@@ -94,7 +96,7 @@ module SidekiqScheduler
94
96
  queue: config['queue']
95
97
  }.keep_if { |_, v| !v.nil? }
96
98
 
97
- initialize_active_job(config['class'], config['args']).enqueue(options)
99
+ initialize_active_job(config['class'], config['args'], config['keyword_argument']).enqueue(options)
98
100
  end
99
101
 
100
102
  # Removes the hash values associated to the rufus metadata keys.
@@ -139,5 +141,41 @@ module SidekiqScheduler
139
141
  def self.update_job_last_time(name, last_time)
140
142
  SidekiqScheduler::RedisManager.set_job_last_time(name, last_time) if last_time
141
143
  end
144
+
145
+ # Try to figure out when the cron job was supposed to run.
146
+ #
147
+ # Rufus calls the scheduler block with the current time and not the time the block was scheduled to run.
148
+ # This means under certain conditions you could have a job get scheduled multiple times because `time.to_i` is used
149
+ # to key the job in redis. If one server is under load and Rufus tries to run the jobs 1 seconds after the other
150
+ # server then the job will be queued twice.
151
+ # This method essentially makes a best guess at when this job was supposed to run and return that.
152
+ #
153
+ # @param [Fugit::Cron] cron
154
+ # @param [Time] time
155
+ #
156
+ # @return [Time]
157
+ def self.calc_cron_run_time(cron, time)
158
+ time = time.floor # remove sub seconds to prevent rounding errors.
159
+ return time if cron.match?(time) # If the time is a perfect match then return it.
160
+
161
+ next_t = cron.next_time(time).to_t
162
+ previous_t = cron.previous_time(time).to_t
163
+ # The `time` var is some point between `previous_t` and `next_t`.
164
+ # Figure out how far off we are from each side in seconds.
165
+ next_diff = next_t - time
166
+ previous_diff = time - previous_t
167
+
168
+ if next_diff == previous_diff
169
+ # In the event `time` is exactly between `previous_t` and `next_t` the diff will not be equal to
170
+ # `cron.rough_frequency`. In that case we round down.
171
+ cron.rough_frequency == next_diff ? time : previous_t
172
+ elsif next_diff > previous_diff
173
+ # We are closer to the previous run time so return that.
174
+ previous_t
175
+ else
176
+ # We are closer to the next run time so return that.
177
+ next_t
178
+ end
179
+ end
142
180
  end
143
181
  end
@@ -1,3 +1,3 @@
1
1
  module SidekiqScheduler
2
- VERSION = '0.4'
2
+ VERSION = "0.5"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'sidekiq'
2
- require 'tilt/erb'
3
2
 
4
3
  require_relative 'sidekiq/scheduler'
5
4
  require_relative 'sidekiq-scheduler/version'
@@ -24,6 +24,9 @@
24
24
  color: white;
25
25
  border: 1px solid #555;
26
26
  }
27
+ .list-group-item-disabled {
28
+ color: #585454;
29
+ }
27
30
  }
28
31
 
29
32
  .toggle-all-buttons {
data/web/locales/cs.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  cs:
2
+ "Recurring Jobs": Pravidelně opakované
2
3
  recurring_jobs: Pravidelně opakované
3
4
  name: Jméno
4
5
  description: Popis
data/web/locales/de.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  de:
2
+ "Recurring Jobs": Wiederkehrende Jobs
2
3
  recurring_jobs: Wiederkehrende Jobs
3
4
  name: Name
4
5
  description: Beschreibung
data/web/locales/en.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  en:
2
+ "Recurring Jobs": Recurring Jobs
2
3
  recurring_jobs: Recurring Jobs
3
4
  name: Name
4
5
  description: Description
data/web/locales/es.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  es:
2
+ "Recurring Jobs": Tareas Recurrentes
2
3
  recurring_jobs: Tareas Recurrentes
3
4
  name: Nombre
4
5
  description: Descripción
data/web/locales/fr.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  fr:
2
+ "Recurring Jobs": Tâches récurrentes
2
3
  recurring_jobs: Tâches récurrentes
3
4
  name: Nom
4
5
  description: Description
@@ -7,7 +8,10 @@ fr:
7
8
  queue: Queue
8
9
  arguments: Arguments
9
10
  enqueue_now: Ajouter à la queue
10
- next_time: Quand
11
+ last_time: Dernière fois
12
+ next_time: Prochaine fois
11
13
  no_next_time: Pas d'exécution prévue pour cette tâche
12
14
  disable: Désactiver
13
15
  enable: Activer
16
+ disable_all: Tout désactiver
17
+ enable_all: Tout activer
@@ -0,0 +1,17 @@
1
+ gd:
2
+ "Recurring Jobs": Obraichean ath-chùrsach
3
+ recurring_jobs: Obraichean ath-chùrsach
4
+ name: Ainm
5
+ description: Tuairisgeul
6
+ interval: Eadaramh
7
+ class: Clas
8
+ queue: Ciudha
9
+ arguments: Argamaidean
10
+ enqueue_now: Cuir sa chiudha an-dràsta
11
+ last_time: An t-àm mu dheireadh
12
+ next_time: An t-ath-àm
13
+ no_next_time: chan eil ath-ghnìomhachadh aig an obair seo
14
+ disable: Cuir à comas
15
+ enable: Cuir an comas
16
+ disable_all: Cuir na h-uile à comas
17
+ enable_all: Cuir na h-uile an comas
data/web/locales/it.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  it:
2
+ "Recurring Jobs": Job ricorrenti
2
3
  recurring_jobs: Job ricorrenti
3
4
  name: Nome
4
5
  description: Descrizione
data/web/locales/ja.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ja:
2
+ "Recurring Jobs": 定期ジョブ
2
3
  recurring_jobs: 定期ジョブ
3
4
  name: 名前
4
5
  description: 説明
data/web/locales/nl.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  nl:
2
+ "Recurring Jobs": Herhalende taken
2
3
  recurring_jobs: Herhalende taken
3
4
  name: Naam
4
5
  description: Beschrijving
data/web/locales/pl.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  pl:
2
+ "Recurring Jobs": Okresowe
2
3
  recurring_jobs: Okresowe
3
4
  name: Nazwa
4
5
  description: Opis
@@ -1,4 +1,5 @@
1
1
  pt-BR:
2
+ "Recurring Jobs": Jobs Recorrentes
2
3
  recurring_jobs: Jobs Recorrentes
3
4
  name: Nome
4
5
  description: Descrição
data/web/locales/ru.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ru:
2
+ "Recurring Jobs": Расписание задач
2
3
  recurring_jobs: Расписание задач
3
4
  name: Название
4
5
  description: Описание
data/web/locales/sv.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  sv:
2
+ "Recurring Jobs": Återkommande jobb
2
3
  recurring_jobs: Återkommande jobb
3
4
  name: Namn
4
5
  description: Beskrivning
@@ -1,4 +1,5 @@
1
1
  zh-cn:
2
+ "Recurring Jobs": 周期作业
2
3
  recurring_jobs: 周期作业
3
4
  name: 名称
4
5
  description: 描述
@@ -1,43 +1,7 @@
1
- <%# This view is a copy from the sidekiq web view, with just a few new actions (remove, edit, new) %>
2
- <% if Sidekiq::VERSION >= '6.0.0' %>
3
- <link href="<%= root_path %>stylesheets-scheduler/recurring_jobs.css" media="screen" rel="stylesheet" type="text/css" />
1
+ <% if SidekiqScheduler::SidekiqAdapter::SIDEKIQ_GTE_7_3_0 %>
2
+ <%= style_tag "recurring_jobs/stylesheets-scheduler/recurring_jobs.css" %>
4
3
  <% else %>
5
- <style>
6
- .recurring-jobs { border-top-left-radius: 4px; border-top-right-radius: 4px; }
7
- .recurring-jobs .title { margin-bottom: 5px; }
8
- .recurring-jobs .title .name { font-weight: bold;}
9
- .recurring-jobs .info,
10
- .recurring-jobs .description { margin-bottom: 5px; }
11
- .recurring-jobs .actions { margin-bottom: 5px; }
12
- .recurring-jobs .status,
13
- .recurring-jobs .description { font-size: 12px; }
14
- .recurring-jobs .enqueue { margin-bottom: 0.5rem }
15
-
16
- .list-group-item {
17
- background-color: #f3f3f3;
18
- color: #585454;
19
- border: 1px solid rgba(0, 0, 0, 0.1);
20
- }
21
-
22
- .list-group-item-disabled {
23
- background-color: #f3d3d3;
24
- }
25
-
26
- .toggle-all-buttons {
27
- margin-top: 20px;
28
- margin-bottom: 10px;
29
- line-height: 45px;
30
- text-align: right;
31
- }
32
-
33
- @media (max-width: 768px) {
34
- .toggle-all-buttons {
35
- margin-top: 0;
36
- text-align: left;
37
- line-height: inherit;
38
- }
39
- }
40
- </style>
4
+ <link href="<%= root_path %>recurring_jobs/stylesheets-scheduler/recurring_jobs.css" media="screen" rel="stylesheet" type="text/css" />
41
5
  <% end %>
42
6
 
43
7
  <div class="row">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb-sidekiq-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morton Jonuschat
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-05-25 00:00:00.000000000 Z
13
+ date: 2024-12-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sidekiq
@@ -46,20 +46,6 @@ dependencies:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '3.2'
49
- - !ruby/object:Gem::Dependency
50
- name: tilt
51
- requirement: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: 1.4.0
56
- type: :runtime
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.4.0
63
49
  - !ruby/object:Gem::Dependency
64
50
  name: rake
65
51
  requirement: !ruby/object:Gem::Requirement
@@ -214,12 +200,13 @@ files:
214
200
  - lib/sidekiq-scheduler/version.rb
215
201
  - lib/sidekiq-scheduler/web.rb
216
202
  - lib/sidekiq/scheduler.rb
217
- - web/assets/stylesheets-scheduler/recurring_jobs.css
203
+ - web/assets/recurring_jobs/stylesheets-scheduler/recurring_jobs.css
218
204
  - web/locales/cs.yml
219
205
  - web/locales/de.yml
220
206
  - web/locales/en.yml
221
207
  - web/locales/es.yml
222
208
  - web/locales/fr.yml
209
+ - web/locales/gd.yml
223
210
  - web/locales/it.yml
224
211
  - web/locales/ja.yml
225
212
  - web/locales/nl.yml
@@ -233,7 +220,8 @@ files:
233
220
  homepage: https://sidekiq-scheduler.github.io/sidekiq-scheduler/
234
221
  licenses:
235
222
  - MIT
236
- metadata: {}
223
+ metadata:
224
+ rubygems_mfa_required: 'true'
237
225
  post_install_message:
238
226
  rdoc_options: []
239
227
  require_paths:
@@ -249,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
237
  - !ruby/object:Gem::Version
250
238
  version: '0'
251
239
  requirements: []
252
- rubygems_version: 3.1.6
240
+ rubygems_version: 3.3.7
253
241
  signing_key:
254
242
  specification_version: 4
255
243
  summary: Light weight job scheduling extension for Sidekiq