que-scheduler 4.2.1 → 4.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: 8d92cf3d8ebdf259e1710f12bd18a4c8659487db9a9aef74abc8adc5003d41e3
4
- data.tar.gz: 3f0444f62191a9e21d83d2aa3e8d31e2c360d8aa29855cac7c6e3a85a453354f
3
+ metadata.gz: 10ede03b787b5856626a071b1bc95482444e85426749dbd3e71cd0df4cce2471
4
+ data.tar.gz: acb2b596d1eb686618e508b25480402686e46c631cfe193ae8c974e49b91090a
5
5
  SHA512:
6
- metadata.gz: c92abb1259bec07700f14bc38f87513d664dab477a8c1c77112dc3850b807ce7ecc277dbe352bdcb1df1a5098758537a664ded7a59887b4c9e8b9f35c04019d8
7
- data.tar.gz: '080de57bec485640cff2f458c4462cd1ff13646851f2212273829195c4da3014df3675197c1d08e11e89bbcbdd68af1a951561837f0c89926a3baf1346b5cddb'
6
+ metadata.gz: 4a61f0242dde1547c4df76f2626ccab9e4fe2f2046db698ff54699f0b19fe3233a1ba4a586781500a3f9f8519033de3f2ef68cf39f73ba1e7d31fcfb270d0b7e
7
+ data.tar.gz: 5e8636614bb56e1b38acd50f7b2afdfc2edf9860cc55898b98552537d3aaab543dff7a40396e6aae623fd70f2fe1618f1214faf6589a5c4fb5c2000c8bff7f2e
data/README.md CHANGED
@@ -27,7 +27,7 @@ resque-scheduler files, but with additional features.
27
27
  ```ruby
28
28
  class CreateQueSchedulerSchema < ActiveRecord::Migration
29
29
  def change
30
- Que::Scheduler::Migrations.migrate!(version: 6)
30
+ Que::Scheduler::Migrations.migrate!(version: 7)
31
31
  end
32
32
  end
33
33
  ```
@@ -211,7 +211,7 @@ performed.
211
211
  ```ruby
212
212
  class CreateQueSchedulerSchema < ActiveRecord::Migration
213
213
  def change
214
- Que::Scheduler::Migrations.migrate!(version: 6)
214
+ Que::Scheduler::Migrations.migrate!(version: 7)
215
215
  end
216
216
  end
217
217
  ```
@@ -310,6 +310,15 @@ A full changelog can be found here: [CHANGELOG.md](https://github.com/hlascelles
310
310
 
311
311
  Your [postgres](https://www.postgresql.org/) database must be at least version 9.5.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.
317
+
318
+ Using que 0.x with Rails 6 needs a patch to support it.
319
+ See the patch and how to use it here: https://github.com/que-rb/que/issues/247#issuecomment-595258236
320
+ If that patch is included then que-scheduler will work. This setup is tested, but is not supported.
321
+
313
322
  ## Inspiration
314
323
 
315
324
  This gem was inspired by the makers of the excellent [Que](https://github.com/chanks/que) job scheduler gem.
@@ -324,3 +333,5 @@ This gem was inspired by the makers of the excellent [Que](https://github.com/ch
324
333
  * @krzyzak
325
334
  * @papodaca
326
335
  * @ajoneil
336
+ * @ippachi
337
+ * @milgner
@@ -86,7 +86,7 @@ module Que
86
86
  # queue name is only supported for a subrange of ActiveJob versions. Print this out as a
87
87
  # warning.
88
88
  if queue &&
89
- Que::Scheduler::ToEnqueue.active_job_loaded? &&
89
+ Que::Scheduler::ToEnqueue.active_job_defined? &&
90
90
  job_class < ::ActiveJob::Base &&
91
91
  Que::Scheduler::ToEnqueue.active_job_version < Gem::Version.create("6.0.3")
92
92
  puts <<~ERR
@@ -0,0 +1,13 @@
1
+ CREATE OR REPLACE FUNCTION que_scheduler_prevent_job_deletion() RETURNS TRIGGER AS
2
+ $BODY$
3
+ DECLARE
4
+ BEGIN
5
+ IF OLD.job_class = 'Que::Scheduler::SchedulerJob' THEN
6
+ IF NOT que_scheduler_check_job_exists() THEN
7
+ raise exception 'Deletion of que_scheduler job % prevented. Deleting the que_scheduler job is almost certainly a mistake.', OLD.job_id;
8
+ END IF;
9
+ END IF;
10
+ RETURN OLD;
11
+ END;
12
+ $BODY$
13
+ LANGUAGE 'plpgsql';
@@ -0,0 +1,13 @@
1
+ CREATE OR REPLACE FUNCTION que_scheduler_prevent_job_deletion() RETURNS TRIGGER AS
2
+ $BODY$
3
+ DECLARE
4
+ BEGIN
5
+ IF OLD.job_class = 'Que::Scheduler::SchedulerJob' THEN
6
+ IF NOT que_scheduler_check_job_exists() THEN
7
+ raise exception 'Deletion of que_scheduler job prevented. Deleting the que_scheduler job is almost certainly a mistake.';
8
+ END IF;
9
+ END IF;
10
+ RETURN OLD;
11
+ END;
12
+ $BODY$
13
+ LANGUAGE 'plpgsql';
@@ -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
 
@@ -36,10 +36,9 @@ module Que
36
36
  end
37
37
 
38
38
  def from_hash(config_hash)
39
- config_hash.to_h do |name, defined_job_hash|
40
- name_str = name.to_s
41
- [name_str, hash_item_to_defined_job(name_str, defined_job_hash)]
42
- end
39
+ config_hash
40
+ .map { |name, defined_job_hash| hash_item_to_defined_job(name.to_s, defined_job_hash) }
41
+ .index_by(&:name)
43
42
  end
44
43
 
45
44
  def hash_item_to_defined_job(name, defined_job_hash_in)
@@ -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
@@ -22,8 +22,8 @@ module Que
22
22
  type_from_job_class(job_class).present?
23
23
  end
24
24
 
25
- def active_job_loaded?
26
- !!active_job_version
25
+ def active_job_defined?
26
+ Object.const_defined?("ActiveJob")
27
27
  end
28
28
 
29
29
  def active_job_version
@@ -54,7 +54,7 @@ module Que
54
54
  hash = {
55
55
  ::Que::Job => QueJobType,
56
56
  }
57
- hash[::ActiveJob::Base] = ActiveJobType if ToEnqueue.active_job_loaded?
57
+ hash[::ActiveJob::Base] = ActiveJobType if ToEnqueue.active_job_defined?
58
58
  hash
59
59
  end
60
60
  end
@@ -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.2.1".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.2.1
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-02-03 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
@@ -70,7 +70,7 @@ dependencies:
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: '0.12'
73
+ version: '0.14'
74
74
  - - "<="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 2.0.0
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '0.12'
83
+ version: '0.14'
84
84
  - - "<="
85
85
  - !ruby/object:Gem::Version
86
86
  version: 2.0.0
@@ -371,6 +371,8 @@ files:
371
371
  - lib/que/scheduler/migrations/5/up.sql
372
372
  - lib/que/scheduler/migrations/6/down.sql
373
373
  - lib/que/scheduler/migrations/6/up.sql
374
+ - lib/que/scheduler/migrations/7/down.sql
375
+ - lib/que/scheduler/migrations/7/up.sql
374
376
  - lib/que/scheduler/schedule.rb
375
377
  - lib/que/scheduler/scheduler_job.rb
376
378
  - lib/que/scheduler/scheduler_job_args.rb
@@ -397,14 +399,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
397
399
  requirements:
398
400
  - - ">="
399
401
  - !ruby/object:Gem::Version
400
- version: '0'
402
+ version: '2.7'
401
403
  required_rubygems_version: !ruby/object:Gem::Requirement
402
404
  requirements:
403
405
  - - ">="
404
406
  - !ruby/object:Gem::Version
405
407
  version: '0'
406
408
  requirements: []
407
- rubygems_version: 3.2.7
409
+ rubygems_version: 3.1.6
408
410
  signing_key:
409
411
  specification_version: 4
410
412
  summary: A cron scheduler for Que