que-scheduler 4.4.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -15
- data/lib/que/scheduler/audit.rb +2 -2
- data/lib/que/scheduler/defined_job.rb +5 -7
- data/lib/que/scheduler/migrations/8/down.sql +1 -0
- data/lib/que/scheduler/migrations/8/up.sql +1 -0
- data/lib/que/scheduler/migrations.rb +4 -6
- data/lib/que/scheduler/scheduler_job.rb +5 -6
- data/lib/que/scheduler/state_checks.rb +2 -4
- data/lib/que/scheduler/to_enqueue.rb +3 -5
- data/lib/que/scheduler/version.rb +1 -1
- data/lib/que/scheduler/version_support.rb +5 -7
- metadata +41 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97c2b6fc33ff2ee357b0270dae679c66b50064eb8548f0e3be24c07ea504d939
|
4
|
+
data.tar.gz: c1ea678b7540e3f02ac5c7eee3416d20238819eb4050bb2f3d6e7183f342022a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdb0c8db5b2b9ab99e6a1e8b04a9710a8c19913ebdcc528ed71e0b27f3dad7231887fc8415d85a5aea3bd91304f7682402530a9612ee77037ecf04b2ea050d80
|
7
|
+
data.tar.gz: 4aed1036ef3f2d9937b8928ec0ccb6e6fc14651d8803cbaaddf52b3d0c3da3a7b744a4aa5db5a898440cef9edd45f77325009552fe3b7c5c9bbe9448b701e34f
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
que-scheduler
|
2
2
|
================
|
3
3
|
|
4
|
-
[![Gem Version](https://
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/que-scheduler?color=green)](https://img.shields.io/gem/v/que-scheduler?color=green)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/github/hlascelles/que-scheduler/badge.svg?branch=master)](https://coveralls.io/github/hlascelles/que-scheduler?branch=master)
|
6
6
|
[![Code Climate Maintainability](https://api.codeclimate.com/v1/badges/710d2fc5202f95d76e8a/maintainability)](https://codeclimate.com/github/hlascelles/que-scheduler/maintainability)
|
7
7
|
|
@@ -25,9 +25,9 @@ resque-scheduler files, but with additional features.
|
|
25
25
|
will fail if Que is set to execute jobs synchronously, i.e. `Que::Job.run_synchronously = true`.
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
class CreateQueSchedulerSchema < ActiveRecord::Migration
|
28
|
+
class CreateQueSchedulerSchema < ActiveRecord::Migration[6.0]
|
29
29
|
def change
|
30
|
-
Que::Scheduler::Migrations.migrate!(version:
|
30
|
+
Que::Scheduler::Migrations.migrate!(version: 8)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
```
|
@@ -40,7 +40,8 @@ wish to generate the configuration dynamically, you can set it directly using an
|
|
40
40
|
|
41
41
|
The file is a list of que job classes with arguments and a schedule frequency (in crontab
|
42
42
|
syntax). The format is similar to the resque-scheduler format, though priorities must be supplied as
|
43
|
-
integers, and job classes must be migrated from Resque to Que.
|
43
|
+
integers, and job classes must be migrated from Resque to Que.
|
44
|
+
ActiveJob classes configured to use `:que` adapter are also supported. Cron syntax can be anything
|
44
45
|
understood by [fugit](https://github.com/floraison/fugit#fugitcron).
|
45
46
|
|
46
47
|
It has one additional feature, `schedule_type: every_event`. This is set on a job that must be run for every
|
@@ -209,23 +210,25 @@ ie, This will perform all migrations necessary up to the latest version, skippin
|
|
209
210
|
performed.
|
210
211
|
|
211
212
|
```ruby
|
212
|
-
class CreateQueSchedulerSchema < ActiveRecord::Migration
|
213
|
+
class CreateQueSchedulerSchema < ActiveRecord::Migration[6.0]
|
213
214
|
def change
|
214
|
-
Que::Scheduler::Migrations.migrate!(version:
|
215
|
+
Que::Scheduler::Migrations.migrate!(version: 8)
|
215
216
|
end
|
216
217
|
end
|
217
218
|
```
|
218
219
|
|
219
220
|
The changes in past migrations were:
|
220
221
|
|
221
|
-
| Version | Changes
|
222
|
-
|
223
|
-
| 1 | Enqueued the main Que::Scheduler. This is the job that performs the scheduling.
|
224
|
-
| 2 | Added the audit table `que_scheduler_audit`.
|
225
|
-
| 3 | Added the audit table `que_scheduler_audit_enqueued`.
|
226
|
-
| 4 | Updated the the audit tables to use bigints
|
227
|
-
| 5 | Dropped an unnecessary index
|
228
|
-
| 6 | Enforced single scheduler job at the trigger level
|
222
|
+
| Version | Changes |
|
223
|
+
|:-------:|-------------------------------------------------------------------------------------|
|
224
|
+
| 1 | Enqueued the main Que::Scheduler. This is the job that performs the scheduling. |
|
225
|
+
| 2 | Added the audit table `que_scheduler_audit`. |
|
226
|
+
| 3 | Added the audit table `que_scheduler_audit_enqueued`. |
|
227
|
+
| 4 | Updated the the audit tables to use bigints |
|
228
|
+
| 5 | Dropped an unnecessary index |
|
229
|
+
| 6 | Enforced single scheduler job at the trigger level |
|
230
|
+
| 7 | Prevent accidental deletion of scheduler job |
|
231
|
+
| 8 | Add primary key to audit. Note, this can be a slow migration if you have many rows! |
|
229
232
|
|
230
233
|
The changes to the DB ([DDL](https://en.wikipedia.org/wiki/Data_definition_language)) are all
|
231
234
|
captured in the structure.sql so will be re-run in correctly if squashed - except for the actual
|
@@ -310,7 +313,8 @@ A full changelog can be found here: [CHANGELOG.md](https://github.com/hlascelles
|
|
310
313
|
|
311
314
|
Your [postgres](https://www.postgresql.org/) database must be at least version 9.6.0.
|
312
315
|
|
313
|
-
The latest version of que-scheduler supports Ruby
|
316
|
+
The latest version of que-scheduler supports Ruby 3.0 and above.
|
317
|
+
que-scheduler versions below 4.4.0 work with Ruby 2.7.
|
314
318
|
que-scheduler versions below 4.2.3 work with Ruby 2.5 and Ruby 2.6.
|
315
319
|
|
316
320
|
Using que 0.x with Rails 6 needs a patch to support it.
|
data/lib/que/scheduler/audit.rb
CHANGED
@@ -11,7 +11,7 @@ module Que
|
|
11
11
|
INSERT INTO #{TABLE_NAME} (scheduler_job_id, executed_at)
|
12
12
|
VALUES ($1::bigint, $2::timestamptz)
|
13
13
|
RETURNING *
|
14
|
-
}
|
14
|
+
}.freeze
|
15
15
|
INSERT_AUDIT_ENQUEUED = %{
|
16
16
|
INSERT INTO #{ENQUEUED_TABLE_NAME}
|
17
17
|
(scheduler_job_id, job_class, queue, priority, args, job_id, run_at)
|
@@ -20,7 +20,7 @@ module Que
|
|
20
20
|
$4::integer, $5::jsonb, $6::bigint, $7::timestamptz
|
21
21
|
)
|
22
22
|
RETURNING *
|
23
|
-
}
|
23
|
+
}.freeze
|
24
24
|
|
25
25
|
class << self
|
26
26
|
def append(scheduler_job_id, executed_at, enqueued_jobs)
|
@@ -54,10 +54,8 @@ module Que
|
|
54
54
|
validate_job_class_related(options)
|
55
55
|
end
|
56
56
|
|
57
|
-
private
|
58
|
-
|
59
57
|
# rubocop:disable Style/GuardClause This reads better as a conditional
|
60
|
-
def validate_fields_types(options)
|
58
|
+
private def validate_fields_types(options)
|
61
59
|
unless queue.nil? || queue.is_a?(String)
|
62
60
|
err_field(:queue, options, "queue must be a string")
|
63
61
|
end
|
@@ -70,14 +68,14 @@ module Que
|
|
70
68
|
end
|
71
69
|
# rubocop:enable Style/GuardClause
|
72
70
|
|
73
|
-
def validate_fields_presence(options)
|
71
|
+
private def validate_fields_presence(options)
|
74
72
|
err_field(:name, options, "name must be present") if name.nil?
|
75
73
|
err_field(:job_class, options, "job_class must be present") if job_class.nil?
|
76
74
|
# An invalid cron is nil
|
77
75
|
err_field(:cron, options, "cron must be present") if cron.nil?
|
78
76
|
end
|
79
77
|
|
80
|
-
def validate_job_class_related(options)
|
78
|
+
private def validate_job_class_related(options)
|
81
79
|
# Only support known job engines
|
82
80
|
unless Que::Scheduler::ToEnqueue.valid_job_class?(job_class)
|
83
81
|
err_field(:job_class, options, "Job #{job_class} was not a supported job type")
|
@@ -104,14 +102,14 @@ module Que
|
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
107
|
-
def err_field(field, options, reason = "")
|
105
|
+
private def err_field(field, options, reason = "")
|
108
106
|
schedule = Que::Scheduler.configuration.schedule_location
|
109
107
|
value = options[field]
|
110
108
|
raise "Invalid #{field} '#{value}' for '#{name}' in que-scheduler schedule #{schedule}.\n" \
|
111
109
|
"#{reason}"
|
112
110
|
end
|
113
111
|
|
114
|
-
def generate_to_enqueue_list(missed_times)
|
112
|
+
private def generate_to_enqueue_list(missed_times)
|
115
113
|
return [] if missed_times.empty?
|
116
114
|
|
117
115
|
options = to_h.slice(:args, :queue, :priority, :job_class).compact
|
@@ -0,0 +1 @@
|
|
1
|
+
ALTER TABLE que_scheduler_audit_enqueued DROP COLUMN "id";
|
@@ -0,0 +1 @@
|
|
1
|
+
ALTER TABLE que_scheduler_audit_enqueued ADD COLUMN id BIGSERIAL PRIMARY KEY;
|
@@ -8,7 +8,7 @@ module Que
|
|
8
8
|
SELECT description FROM pg_class
|
9
9
|
LEFT JOIN pg_description ON pg_description.objoid = pg_class.oid
|
10
10
|
WHERE relname = '#{AUDIT_TABLE_NAME}'
|
11
|
-
)
|
11
|
+
).freeze
|
12
12
|
MAX_VERSION = Dir.glob("#{__dir__}/migrations/*").map { |d| File.basename(d) }.map(&:to_i).max
|
13
13
|
|
14
14
|
class << self
|
@@ -48,21 +48,19 @@ module Que
|
|
48
48
|
Que::Scheduler::VersionSupport.enqueue_a_job(Que::Scheduler::SchedulerJob)
|
49
49
|
end
|
50
50
|
|
51
|
-
private
|
52
|
-
|
53
|
-
def migrate_up(current, version)
|
51
|
+
private def migrate_up(current, version)
|
54
52
|
if current.zero? # Version 1 does not use SQL
|
55
53
|
Que::Scheduler::VersionSupport.enqueue_a_job(Que::Scheduler::SchedulerJob)
|
56
54
|
end
|
57
55
|
execute_step((current += 1), :up) until current == version
|
58
56
|
end
|
59
57
|
|
60
|
-
def migrate_down(current, version)
|
58
|
+
private def migrate_down(current, version)
|
61
59
|
current += 1
|
62
60
|
execute_step((current -= 1), :down) until current == version + 1
|
63
61
|
end
|
64
62
|
|
65
|
-
def execute_step(number, direction)
|
63
|
+
private def execute_step(number, direction)
|
66
64
|
sql = File.read("#{__dir__}/migrations/#{number}/#{direction}.sql")
|
67
65
|
Que::Scheduler::VersionSupport.execute(sql)
|
68
66
|
return unless audit_table_exists?
|
@@ -38,16 +38,14 @@ module Que
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def enqueue_required_jobs(calculator_result, logs)
|
41
|
-
calculator_result.missed_jobs.
|
41
|
+
calculator_result.missed_jobs.filter_map do |to_enqueue|
|
42
42
|
to_enqueue.enqueue.tap do |enqueued_job|
|
43
43
|
check_enqueued_job(to_enqueue, enqueued_job, logs)
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
46
46
|
end
|
47
47
|
|
48
|
-
private
|
49
|
-
|
50
|
-
def check_enqueued_job(to_enqueue, enqueued_job, logs)
|
48
|
+
private def check_enqueued_job(to_enqueue, enqueued_job, logs)
|
51
49
|
logs << if enqueued_job.present?
|
52
50
|
"que-scheduler enqueueing #{enqueued_job.job_class} " \
|
53
51
|
"#{enqueued_job.job_id} with args: #{enqueued_job.args}"
|
@@ -58,7 +56,8 @@ module Que
|
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
|
-
def enqueue_self_again(scheduler_job_args, last_full_execution, job_dictionary,
|
59
|
+
private def enqueue_self_again(scheduler_job_args, last_full_execution, job_dictionary,
|
60
|
+
enqueued_jobs)
|
62
61
|
# Log last run...
|
63
62
|
job_id = VersionSupport.job_attributes(self).fetch(:job_id)
|
64
63
|
Audit.append(job_id, scheduler_job_args.as_time, enqueued_jobs)
|
@@ -10,9 +10,7 @@ module Que
|
|
10
10
|
assert_db_migrated
|
11
11
|
end
|
12
12
|
|
13
|
-
private
|
14
|
-
|
15
|
-
def assert_db_migrated
|
13
|
+
private def assert_db_migrated
|
16
14
|
db_version = Que::Scheduler::Migrations.db_version
|
17
15
|
return if db_version == Que::Scheduler::Migrations::MAX_VERSION
|
18
16
|
|
@@ -49,7 +47,7 @@ module Que
|
|
49
47
|
To bring the db version up to the current one required, add a migration like this. It
|
50
48
|
is cumulative, so one line is sufficient to perform all necessary steps.
|
51
49
|
|
52
|
-
class UpdateQueSchedulerSchema < ActiveRecord::Migration
|
50
|
+
class UpdateQueSchedulerSchema < ActiveRecord::Migration[6.0]
|
53
51
|
def change
|
54
52
|
Que::Scheduler::Migrations.migrate!(version: #{Que::Scheduler::Migrations::MAX_VERSION})
|
55
53
|
end
|
@@ -23,7 +23,7 @@ module Que
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def active_job_defined?
|
26
|
-
Object.const_defined?(
|
26
|
+
Object.const_defined?(:ActiveJob)
|
27
27
|
end
|
28
28
|
|
29
29
|
def active_job_version
|
@@ -39,16 +39,14 @@ module Que
|
|
39
39
|
Gem::Version.create("6.0.3")
|
40
40
|
end
|
41
41
|
|
42
|
-
private
|
43
|
-
|
44
|
-
def type_from_job_class(job_class)
|
42
|
+
private def type_from_job_class(job_class)
|
45
43
|
types.each do |type, implementation|
|
46
44
|
return implementation if job_class < type
|
47
45
|
end
|
48
46
|
nil
|
49
47
|
end
|
50
48
|
|
51
|
-
def types
|
49
|
+
private def types
|
52
50
|
@types ||=
|
53
51
|
begin
|
54
52
|
hash = {
|
@@ -15,7 +15,7 @@ module Que
|
|
15
15
|
# the top of all jobs it enqueues.
|
16
16
|
def set_priority(context, priority)
|
17
17
|
if zero_major?
|
18
|
-
context.instance_variable_set(
|
18
|
+
context.instance_variable_set(:@priority, priority)
|
19
19
|
else
|
20
20
|
context.priority = priority
|
21
21
|
end
|
@@ -24,7 +24,7 @@ module Que
|
|
24
24
|
# Ensure the job runs at least once an hour when it is backing off due to errors
|
25
25
|
def apply_retry_semantics(context)
|
26
26
|
if zero_major?
|
27
|
-
context.instance_variable_set(
|
27
|
+
context.instance_variable_set(:@retry_interval, RETRY_PROC)
|
28
28
|
else
|
29
29
|
context.maximum_retry_count = 1 << 128 # Heat death of universe
|
30
30
|
context.retry_interval = RETRY_PROC
|
@@ -92,17 +92,15 @@ module Que
|
|
92
92
|
@que_version ||= que_version_object.to_s
|
93
93
|
end
|
94
94
|
|
95
|
-
private
|
96
|
-
|
97
|
-
def supports_job_options_keyword?
|
95
|
+
private def supports_job_options_keyword?
|
98
96
|
@supports_job_options_keyword ||= que_version_object >= Gem::Version.new("1.2.0")
|
99
97
|
end
|
100
98
|
|
101
|
-
def que_version_object
|
99
|
+
private def que_version_object
|
102
100
|
@que_version_object ||= Gem.loaded_specs["que"].version
|
103
101
|
end
|
104
102
|
|
105
|
-
def normalise_array_of_hashes(array)
|
103
|
+
private def normalise_array_of_hashes(array)
|
106
104
|
array.map { |row| row.to_h.transform_keys(&:to_sym) }
|
107
105
|
end
|
108
106
|
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
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Lascelles
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fugit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,7 +175,7 @@ dependencies:
|
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
177
|
- !ruby/object:Gem::Dependency
|
178
|
-
name:
|
178
|
+
name: dememoize
|
179
179
|
requirement: !ruby/object:Gem::Requirement
|
180
180
|
requirements:
|
181
181
|
- - ">="
|
@@ -189,7 +189,7 @@ dependencies:
|
|
189
189
|
- !ruby/object:Gem::Version
|
190
190
|
version: '0'
|
191
191
|
- !ruby/object:Gem::Dependency
|
192
|
-
name:
|
192
|
+
name: fasterer
|
193
193
|
requirement: !ruby/object:Gem::Requirement
|
194
194
|
requirements:
|
195
195
|
- - ">="
|
@@ -202,6 +202,20 @@ dependencies:
|
|
202
202
|
- - ">="
|
203
203
|
- !ruby/object:Gem::Version
|
204
204
|
version: '0'
|
205
|
+
- !ruby/object:Gem::Dependency
|
206
|
+
name: pg
|
207
|
+
requirement: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '1.0'
|
212
|
+
type: :development
|
213
|
+
prerelease: false
|
214
|
+
version_requirements: !ruby/object:Gem::Requirement
|
215
|
+
requirements:
|
216
|
+
- - ">="
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: '1.0'
|
205
219
|
- !ruby/object:Gem::Dependency
|
206
220
|
name: pry-byebug
|
207
221
|
requirement: !ruby/object:Gem::Requirement
|
@@ -286,6 +300,20 @@ dependencies:
|
|
286
300
|
- - ">="
|
287
301
|
- !ruby/object:Gem::Version
|
288
302
|
version: '0'
|
303
|
+
- !ruby/object:Gem::Dependency
|
304
|
+
name: rubocop-performance
|
305
|
+
requirement: !ruby/object:Gem::Requirement
|
306
|
+
requirements:
|
307
|
+
- - ">="
|
308
|
+
- !ruby/object:Gem::Version
|
309
|
+
version: '0'
|
310
|
+
type: :development
|
311
|
+
prerelease: false
|
312
|
+
version_requirements: !ruby/object:Gem::Requirement
|
313
|
+
requirements:
|
314
|
+
- - ">="
|
315
|
+
- !ruby/object:Gem::Version
|
316
|
+
version: '0'
|
289
317
|
- !ruby/object:Gem::Dependency
|
290
318
|
name: rubocop-rspec
|
291
319
|
requirement: !ruby/object:Gem::Requirement
|
@@ -373,6 +401,8 @@ files:
|
|
373
401
|
- lib/que/scheduler/migrations/6/up.sql
|
374
402
|
- lib/que/scheduler/migrations/7/down.sql
|
375
403
|
- lib/que/scheduler/migrations/7/up.sql
|
404
|
+
- lib/que/scheduler/migrations/8/down.sql
|
405
|
+
- lib/que/scheduler/migrations/8/up.sql
|
376
406
|
- lib/que/scheduler/schedule.rb
|
377
407
|
- lib/que/scheduler/scheduler_job.rb
|
378
408
|
- lib/que/scheduler/scheduler_job_args.rb
|
@@ -391,7 +421,7 @@ metadata:
|
|
391
421
|
source_code_uri: https://github.com/hlascelles/que-scheduler/
|
392
422
|
bug_tracker_uri: https://github.com/hlascelles/que-scheduler/issues
|
393
423
|
rubygems_mfa_required: 'true'
|
394
|
-
post_install_message:
|
424
|
+
post_install_message:
|
395
425
|
rdoc_options: []
|
396
426
|
require_paths:
|
397
427
|
- lib
|
@@ -399,15 +429,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
399
429
|
requirements:
|
400
430
|
- - ">="
|
401
431
|
- !ruby/object:Gem::Version
|
402
|
-
version: '
|
432
|
+
version: '3.0'
|
403
433
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
404
434
|
requirements:
|
405
435
|
- - ">="
|
406
436
|
- !ruby/object:Gem::Version
|
407
437
|
version: '0'
|
408
438
|
requirements: []
|
409
|
-
rubygems_version: 3.
|
410
|
-
signing_key:
|
439
|
+
rubygems_version: 3.3.26
|
440
|
+
signing_key:
|
411
441
|
specification_version: 4
|
412
442
|
summary: A cron scheduler for Que
|
413
443
|
test_files: []
|