inst-jobs 3.5.0 → 3.6.0
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 +4 -4
- data/lib/delayed/backend/active_record.rb +76 -0
- data/lib/delayed/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5f938b9b6cacf60e67a5063bd1e1af4c80eafcfbc9872d747214b623f105352d
|
|
4
|
+
data.tar.gz: f2fc44b5a7c8a7918b0930ae68b44edd64b0acb2361bd741704f128ca9ac34af
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39efda83073f3165101918d4233c9cef7cd272189d7aac7ae21fb2310a7e0e14f69005773206b708edb368d4c92e1c2cedd352323c90b9df552612809920ec89
|
|
7
|
+
data.tar.gz: c70e2049abc42ab22a6f8b699435d7743d25550cd73e24248c489d112800472a47719d2371e952b29f9fd31a08162c1ee1458b825d69b7789165006a18dc5336
|
|
@@ -350,6 +350,82 @@ module Delayed
|
|
|
350
350
|
[job_count, new_strand]
|
|
351
351
|
end
|
|
352
352
|
|
|
353
|
+
# change priority, max_concurrent and hold state of every job with the tag
|
|
354
|
+
# that is not running, held ones included. Running jobs keep their settings.
|
|
355
|
+
# max_concurrent applies only to stranded jobs, and a strand ramps up to it
|
|
356
|
+
# gradually as its jobs finish. hold: true holds, hold: false releases.
|
|
357
|
+
# returns the number of jobs that at least one of the changes applies to
|
|
358
|
+
# (this is designed for use in a Rails console or a Jobs UI)
|
|
359
|
+
def self.manage_tag(tag, priority: nil, max_concurrent: nil, hold: nil, batch_size: 1_000)
|
|
360
|
+
raise ArgumentError, "missing tag" if tag.blank?
|
|
361
|
+
if priority.nil? && max_concurrent.nil? && hold.nil?
|
|
362
|
+
raise ArgumentError, "missing priority, max_concurrent or hold"
|
|
363
|
+
end
|
|
364
|
+
unless priority.nil? || (priority.is_a?(Integer) && priority.between?(Delayed::MIN_PRIORITY, Delayed::MAX_PRIORITY))
|
|
365
|
+
raise ArgumentError, "invalid priority"
|
|
366
|
+
end
|
|
367
|
+
unless max_concurrent.nil? || (max_concurrent.is_a?(Integer) && max_concurrent >= 1)
|
|
368
|
+
raise ArgumentError, "invalid max_concurrent"
|
|
369
|
+
end
|
|
370
|
+
raise ArgumentError, "invalid hold" unless [nil, true, false].include?(hold)
|
|
371
|
+
|
|
372
|
+
apply_tag_changes(manageable_tag_jobs(tag), priority:, max_concurrent:, hold:, batch_size:)
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
# returns { matched_jobs:, matched_strands:, held_jobs: } for the jobs manage_tag changes
|
|
376
|
+
def self.manage_tag_counts(tag)
|
|
377
|
+
scope = manageable_tag_jobs(tag)
|
|
378
|
+
{
|
|
379
|
+
matched_jobs: scope.count,
|
|
380
|
+
matched_strands: scope.where.not(strand: nil).distinct.count(:strand),
|
|
381
|
+
held_jobs: scope.where(locked_by: ON_HOLD_LOCKED_BY).count
|
|
382
|
+
}
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
# Updates the jobs in scope, in batches. Each CASE reads the row as it was
|
|
386
|
+
# before the update, so the order of the assignments, locked_by last
|
|
387
|
+
# included, doesn't matter.
|
|
388
|
+
def self.apply_tag_changes(scope, priority:, max_concurrent:, hold:, batch_size:)
|
|
389
|
+
now = db_time_now
|
|
390
|
+
assignments = []
|
|
391
|
+
affected = []
|
|
392
|
+
sql = ->(*fragment) { sanitize_sql_array(fragment) }
|
|
393
|
+
|
|
394
|
+
assignments << sql.call("priority = ?", priority) if priority
|
|
395
|
+
if max_concurrent
|
|
396
|
+
assignments << sql.call("max_concurrent = CASE WHEN strand IS NULL THEN max_concurrent ELSE ? END",
|
|
397
|
+
max_concurrent)
|
|
398
|
+
affected << scope.where.not(strand: nil)
|
|
399
|
+
end
|
|
400
|
+
if hold == true
|
|
401
|
+
assignments << sql.call("locked_at = CASE WHEN locked_by IS NULL THEN ? ELSE locked_at END", now)
|
|
402
|
+
assignments << sql.call("attempts = CASE WHEN locked_by IS NULL THEN ? ELSE attempts END", ON_HOLD_COUNT)
|
|
403
|
+
assignments << sql.call("locked_by = CASE WHEN locked_by IS NULL THEN ? ELSE locked_by END",
|
|
404
|
+
ON_HOLD_LOCKED_BY)
|
|
405
|
+
affected << scope.where(locked_by: nil)
|
|
406
|
+
elsif hold == false
|
|
407
|
+
held = sql.call("locked_by = ?", ON_HOLD_LOCKED_BY)
|
|
408
|
+
assignments << "locked_at = CASE WHEN #{held} THEN NULL ELSE locked_at END"
|
|
409
|
+
assignments << "attempts = CASE WHEN #{held} THEN 0 ELSE attempts END"
|
|
410
|
+
assignments << sql.call("run_at = CASE WHEN #{held} AND run_at < ? THEN ? ELSE run_at END", now, now)
|
|
411
|
+
assignments << "failed_at = CASE WHEN #{held} THEN NULL ELSE failed_at END"
|
|
412
|
+
assignments << "locked_by = CASE WHEN #{held} THEN NULL ELSE locked_by END"
|
|
413
|
+
affected << scope.where(locked_by: ON_HOLD_LOCKED_BY)
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
# a priority change applies to every job in scope, otherwise only to the ones another change applies to
|
|
417
|
+
scope = affected.reduce(:or) unless priority
|
|
418
|
+
scope.in_batches(of: batch_size).update_all(assignments.join(", "))
|
|
419
|
+
end
|
|
420
|
+
private_class_method :apply_tag_changes
|
|
421
|
+
|
|
422
|
+
def self.manageable_tag_jobs(tag)
|
|
423
|
+
raise ArgumentError, "missing tag" if tag.blank?
|
|
424
|
+
|
|
425
|
+
where(tag:).where(locked_by: [nil, ON_HOLD_LOCKED_BY])
|
|
426
|
+
end
|
|
427
|
+
private_class_method :manageable_tag_jobs
|
|
428
|
+
|
|
353
429
|
def self.maybe_silence_periodic_log(&)
|
|
354
430
|
if Settings.silence_periodic_log
|
|
355
431
|
::ActiveRecord::Base.logger.silence(&)
|
data/lib/delayed/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: inst-jobs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cody Cutrer
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: exe
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2026-
|
|
13
|
+
date: 2026-12-01 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activerecord
|
|
@@ -74,6 +74,20 @@ dependencies:
|
|
|
74
74
|
- - "<"
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
76
|
version: '3'
|
|
77
|
+
- !ruby/object:Gem::Dependency
|
|
78
|
+
name: benchmark
|
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
type: :runtime
|
|
85
|
+
prerelease: false
|
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
77
91
|
- !ruby/object:Gem::Dependency
|
|
78
92
|
name: debug_inspector
|
|
79
93
|
requirement: !ruby/object:Gem::Requirement
|