que-scheduler 4.3.0 → 4.4.0

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: aac67112308ae6e0840d46479cf890eb123f94c51ac9ac9a9a1b51900064cc96
4
+ data.tar.gz: 1e268c0c918988a05e4bb5912ff47aee45b680ade2c3b422ea9dbf5c1bd0fd18
5
5
  SHA512:
6
- metadata.gz: c6c0bdefa899496a741b4c4b059cdc7663299a4a349b41560c44d77d2c788bc3ee4fb53f7c8fa51767d86332f1bd5475ea3bca3516ddd1a81de1bfea91e2e653
7
- data.tar.gz: 447ff26a1c104803e27da593730b77aaf59300e13ead005c7dece366c1fbc0f252d65524dcba6b6a64be2a656681a97e1ae78adb45117b374b533525e2612b6a
6
+ metadata.gz: 7ba7be6ea94dfa50387a329e39753ce1b17df38aa13e8c106c49c4eabaa3a249be8528d8fc6985201736a87a74ef318083f4f9661d6153191f484f06136f3ede
7
+ data.tar.gz: eba73e89578334e55d4d39a253edf1d2822647eee62d733d52235184c8eaa9b36f64a7027fde5ed3c2a6ea2c73666a9ea6b82ed4ca62edbd5df1ed0bdeee6432
data/README.md CHANGED
@@ -308,12 +308,10 @@ A full changelog can be found here: [CHANGELOG.md](https://github.com/hlascelles
308
308
 
309
309
  ## System requirements
310
310
 
311
- Your [postgres](https://www.postgresql.org/) database must be at least version 9.5.0.
311
+ Your [postgres](https://www.postgresql.org/) database must be at least version 9.6.0.
312
312
 
313
- The latest version of que-scheduler supports Ruby 2.7, though this is largely to allow
314
- the gem to work with que 2.x. Recent que-scheduler versions (up to 4.2.2) work with Ruby 2.5.
315
-
316
- Ruby 3.x support (and thus que 2.x support) is currently in beta.
313
+ The latest version of que-scheduler supports Ruby 2.7 and above.
314
+ que-scheduler versions below 4.2.3 work with Ruby 2.5 and Ruby 2.6.
317
315
 
318
316
  Using que 0.x with Rails 6 needs a patch to support it.
319
317
  See the patch and how to use it here: https://github.com/que-rb/que/issues/247#issuecomment-595258236
@@ -334,3 +332,4 @@ This gem was inspired by the makers of the excellent [Que](https://github.com/ch
334
332
  * @papodaca
335
333
  * @ajoneil
336
334
  * @ippachi
335
+ * @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.4.0".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.4.0
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-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -71,9 +71,9 @@ dependencies:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0.14'
74
- - - "<="
74
+ - - "<"
75
75
  - !ruby/object:Gem::Version
76
- version: 2.0.0
76
+ version: 3.0.0
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
@@ -81,9 +81,9 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0.14'
84
- - - "<="
84
+ - - "<"
85
85
  - !ruby/object:Gem::Version
86
- version: 2.0.0
86
+ version: 3.0.0
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: activerecord
89
89
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +93,7 @@ dependencies:
93
93
  version: '5.0'
94
94
  - - "<"
95
95
  - !ruby/object:Gem::Version
96
- version: '7.0'
96
+ version: '8.0'
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
@@ -103,7 +103,7 @@ dependencies:
103
103
  version: '5.0'
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
- version: '7.0'
106
+ version: '8.0'
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: appraisal
109
109
  requirement: !ruby/object:Gem::Requirement
@@ -192,16 +192,16 @@ dependencies:
192
192
  name: pg
193
193
  requirement: !ruby/object:Gem::Requirement
194
194
  requirements:
195
- - - "~>"
195
+ - - ">="
196
196
  - !ruby/object:Gem::Version
197
- version: '0.21'
197
+ version: '0'
198
198
  type: :development
199
199
  prerelease: false
200
200
  version_requirements: !ruby/object:Gem::Requirement
201
201
  requirements:
202
- - - "~>"
202
+ - - ">="
203
203
  - !ruby/object:Gem::Version
204
- version: '0.21'
204
+ version: '0'
205
205
  - !ruby/object:Gem::Dependency
206
206
  name: pry-byebug
207
207
  requirement: !ruby/object:Gem::Requirement