que-scheduler 4.3.0 → 4.3.1

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: 3031c76424c60291dc8d004538ab6dc5d57fdf8bb7c48faa6dae2cd2ddba90f7
4
- data.tar.gz: 0c3d33ade4ebce0c2e24414347da1a5150d5ba680adafa240a15475a71ba646b
3
+ metadata.gz: 10ede03b787b5856626a071b1bc95482444e85426749dbd3e71cd0df4cce2471
4
+ data.tar.gz: acb2b596d1eb686618e508b25480402686e46c631cfe193ae8c974e49b91090a
5
5
  SHA512:
6
- metadata.gz: c6c0bdefa899496a741b4c4b059cdc7663299a4a349b41560c44d77d2c788bc3ee4fb53f7c8fa51767d86332f1bd5475ea3bca3516ddd1a81de1bfea91e2e653
7
- data.tar.gz: 447ff26a1c104803e27da593730b77aaf59300e13ead005c7dece366c1fbc0f252d65524dcba6b6a64be2a656681a97e1ae78adb45117b374b533525e2612b6a
6
+ metadata.gz: 4a61f0242dde1547c4df76f2626ccab9e4fe2f2046db698ff54699f0b19fe3233a1ba4a586781500a3f9f8519033de3f2ef68cf39f73ba1e7d31fcfb270d0b7e
7
+ data.tar.gz: 5e8636614bb56e1b38acd50f7b2afdfc2edf9860cc55898b98552537d3aaab543dff7a40396e6aae623fd70f2fe1618f1214faf6589a5c4fb5c2000c8bff7f2e
data/README.md CHANGED
@@ -334,3 +334,4 @@ This gem was inspired by the makers of the excellent [Que](https://github.com/ch
334
334
  * @papodaca
335
335
  * @ajoneil
336
336
  * @ippachi
337
+ * @milgner
@@ -43,13 +43,17 @@ module Que
43
43
 
44
44
  # This method is only intended for use in squashed migrations
45
45
  def reenqueue_scheduler_if_missing
46
- Que::Scheduler::SchedulerJob.enqueue if Que::Scheduler::Db.count_schedulers.zero?
46
+ return unless Que::Scheduler::Db.count_schedulers.zero?
47
+
48
+ Que::Scheduler::VersionSupport.enqueue_a_job(Que::Scheduler::SchedulerJob)
47
49
  end
48
50
 
49
51
  private
50
52
 
51
53
  def migrate_up(current, version)
52
- Que::Scheduler::SchedulerJob.enqueue if current.zero? # Version 1 does not use SQL
54
+ if current.zero? # Version 1 does not use SQL
55
+ Que::Scheduler::VersionSupport.enqueue_a_job(Que::Scheduler::SchedulerJob)
56
+ end
53
57
  execute_step((current += 1), :up) until current == version
54
58
  end
55
59
 
@@ -65,11 +65,16 @@ module Que
65
65
 
66
66
  # And rerun...
67
67
  next_run_at = scheduler_job_args.as_time.beginning_of_minute + SCHEDULER_FREQUENCY
68
- enqueued_job = SchedulerJob.enqueue(
69
- queue: Que::Scheduler.configuration.que_scheduler_queue,
70
- last_run_time: last_full_execution.iso8601,
71
- job_dictionary: job_dictionary,
72
- run_at: next_run_at
68
+ enqueued_job = Que::Scheduler::VersionSupport.enqueue_a_job(
69
+ SchedulerJob,
70
+ {
71
+ queue: Que::Scheduler.configuration.que_scheduler_queue,
72
+ run_at: next_run_at,
73
+ },
74
+ {
75
+ last_run_time: last_full_execution.iso8601,
76
+ job_dictionary: job_dictionary,
77
+ }
73
78
  )
74
79
 
75
80
  # rubocop:disable Style/GuardClause This reads better as a conditional
@@ -65,12 +65,11 @@ module Que
65
65
  class QueJobType < ToEnqueue
66
66
  def enqueue
67
67
  job_settings = to_h.slice(:queue, :priority, :run_at).compact
68
- job =
69
- if args.is_a?(Hash)
70
- job_class.enqueue(**args.merge(job_settings))
71
- else
72
- job_class.enqueue(*args, **job_settings)
73
- end
68
+ job = Que::Scheduler::VersionSupport.enqueue_a_job(
69
+ job_class,
70
+ job_settings,
71
+ args
72
+ )
74
73
 
75
74
  return nil if job.nil? || !job # nil in Rails < 6.1, false after.
76
75
 
@@ -1,5 +1,5 @@
1
1
  module Que
2
2
  module Scheduler
3
- VERSION = "4.3.0".freeze
3
+ VERSION = "4.3.1".freeze
4
4
  end
5
5
  end
@@ -47,6 +47,25 @@ module Que
47
47
  normalise_array_of_hashes(Que.execute(str, args))
48
48
  end
49
49
 
50
+ # rubocop:disable Style/IfInsideElse
51
+ def enqueue_a_job(clazz, job_options = {}, job_args = [])
52
+ if supports_job_options_keyword?
53
+ # More recent versions have separated the way job arguments and options are passed in
54
+ if job_args.is_a?(Hash)
55
+ clazz.enqueue(job_args, job_options: job_options)
56
+ else
57
+ clazz.enqueue(*job_args, job_options: job_options)
58
+ end
59
+ else
60
+ if job_args.is_a?(Hash)
61
+ clazz.enqueue(**job_args.merge(job_options))
62
+ else
63
+ clazz.enqueue(*job_args, **job_options)
64
+ end
65
+ end
66
+ end
67
+
68
+ # rubocop:enable Style/IfInsideElse
50
69
  def default_scheduler_queue
51
70
  zero_major? ? "" : Que::DEFAULT_QUEUE
52
71
  end
@@ -64,12 +83,25 @@ module Que
64
83
  @zero_major ||= que_version.split(".").first.to_i.zero?
65
84
  end
66
85
 
86
+ def one_major?
87
+ # This is the only way to handle beta releases too
88
+ @one_major ||= que_version.split(".").first.to_i == 1
89
+ end
90
+
67
91
  def que_version
68
- @que_version ||= Gem.loaded_specs["que"].version.to_s
92
+ @que_version ||= que_version_object.to_s
69
93
  end
70
94
 
71
95
  private
72
96
 
97
+ def supports_job_options_keyword?
98
+ @supports_job_options_keyword ||= que_version_object >= Gem::Version.new("1.2.0")
99
+ end
100
+
101
+ def que_version_object
102
+ @que_version_object ||= Gem.loaded_specs["que"].version
103
+ end
104
+
73
105
  def normalise_array_of_hashes(array)
74
106
  array.map { |row| row.to_h.transform_keys(&:to_sym) }
75
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: que-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Lascelles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-04 00:00:00.000000000 Z
11
+ date: 2022-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport