inst-jobs 2.4.4 → 2.4.5

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: 90e78e46299d111959e7e48f25fe4e05a7939c6fb54fcd423deff4b960e79e6c
4
- data.tar.gz: 20963910cd2cb1856f73cabbdc1547131a0d5096e26f7cc444f0a6e7d26b0ded
3
+ metadata.gz: 3fa880428987cbea8be8cb706b2b4d4fae3164a021107591e7e1f5724a88fc4b
4
+ data.tar.gz: f9feb618c4043c02ce428146d9bc1801884639d72867e23f21c5b39b546c6a7f
5
5
  SHA512:
6
- metadata.gz: 22155dba3fd9f1201e67930be8a3cc488da21b02b2066b59fe9a0f28f5670393534ddbb87a937979df356ba602c23a27e97f7650463fa2eb7c53e76647df5f02
7
- data.tar.gz: 41a6bec7f263657aac33b62eeb8169db1898dfdcdbfadc32d91a985f54cb037a5691d75f02dff80b9c80ea57387a746fa70e6710545fe6b9c12724dde9f8f720
6
+ metadata.gz: 9328098d390744e089edb857db0f27d379f3696f66c8c549655e6a9a5ea331e7083dda3eb3203200fb00ca1edf121a1264b7ffb228ea075f43889c8a20f7d02c
7
+ data.tar.gz: f6dfe1ad5d03c525daf9e445764bb191cdd6075d0c36156d3ff1499c7fb149718b4d5bb689da16349e49e9b1c25bb1e468ceed7e7cfa30543ce831047a7bd954
@@ -38,6 +38,11 @@ module Delayed
38
38
  job = new(attributes, &block)
39
39
  job.single_step_create(on_conflict: on_conflict)
40
40
  end
41
+
42
+ def attempt_advisory_lock(lock_name)
43
+ fn_name = connection.quote_table_name("half_md5_as_bigint")
44
+ connection.select_value("SELECT pg_try_advisory_xact_lock(#{fn_name}('#{lock_name}'));")
45
+ end
41
46
  end
42
47
 
43
48
  def single_step_create(on_conflict: nil)
@@ -148,13 +148,19 @@ module Delayed
148
148
  end
149
149
 
150
150
  def unlock_orphaned_prefetched_jobs
151
- horizon = db_time_now - (Settings.parent_process[:prefetched_jobs_timeout] * 4)
152
- orphaned_jobs = running_jobs.select do |job|
153
- job.locked_by.start_with?("prefetch:") && job.locked_at < horizon
154
- end
155
- return 0 if orphaned_jobs.empty?
151
+ transaction do
152
+ # for db performance reasons, we only need one process doing this at a time
153
+ # so if we can't get an advisory lock, just abort. we'll try again soon
154
+ return unless attempt_advisory_lock("Delayed::Job.unlock_orphaned_prefetched_jobs")
155
+
156
+ horizon = db_time_now - (Settings.parent_process[:prefetched_jobs_timeout] * 4)
157
+ orphaned_jobs = running_jobs.select do |job|
158
+ job.locked_by.start_with?("prefetch:") && job.locked_at < horizon
159
+ end
160
+ return 0 if orphaned_jobs.empty?
156
161
 
157
- unlock(orphaned_jobs)
162
+ unlock(orphaned_jobs)
163
+ end
158
164
  end
159
165
 
160
166
  def unlock_orphaned_jobs(pid = nil, name = nil)
@@ -33,7 +33,13 @@ module Delayed
33
33
  # we used to queue up a job in a strand here, and perform the audit inside that job
34
34
  # however, now that we're using singletons for scheduling periodic jobs,
35
35
  # it's fine to just do the audit in-line here without risk of creating duplicates
36
- perform_audit!
36
+ Delayed::Job.transaction do
37
+ # for db performance reasons, we only need one process doing this at a time
38
+ # so if we can't get an advisory lock, just abort. we'll try again soon
39
+ return unless Delayed::Job.attempt_advisory_lock("Delayed::Periodic#audit_queue")
40
+
41
+ perform_audit!
42
+ end
37
43
  end
38
44
 
39
45
  # make sure all periodic jobs are scheduled for their next run in the job queue
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "2.4.4"
4
+ VERSION = "2.4.5"
5
5
  end
@@ -33,7 +33,7 @@ module Delayed
33
33
  # and we try to get an advisory lock when it runs. If we succeed,
34
34
  # no other worker is trying to do this right now (and if we abandon the
35
35
  # operation, the transaction will end, releasing the advisory lock).
36
- result = attempt_advisory_lock
36
+ result = Delayed::Job.attempt_advisory_lock("Delayed::Worker::HealthCheck#reschedule_abandoned_jobs")
37
37
  return unless result
38
38
 
39
39
  checker = Worker::HealthCheck.build(
@@ -65,13 +65,6 @@ module Delayed
65
65
  end
66
66
  end
67
67
  end
68
-
69
- def attempt_advisory_lock
70
- lock_name = "Delayed::Worker::HealthCheck#reschedule_abandoned_jobs"
71
- conn = ActiveRecord::Base.connection
72
- fn_name = conn.quote_table_name("half_md5_as_bigint")
73
- conn.select_value("SELECT pg_try_advisory_xact_lock(#{fn_name}('#{lock_name}'));")
74
- end
75
68
  end
76
69
 
77
70
  attr_accessor :config, :worker_name
@@ -111,7 +111,7 @@ RSpec.describe Delayed::Worker::HealthCheck do
111
111
  end
112
112
 
113
113
  it "bails immediately if advisory lock already taken" do
114
- allow(described_class).to receive(:attempt_advisory_lock).and_return(false)
114
+ allow(Delayed::Job).to receive(:attempt_advisory_lock).and_return(false)
115
115
  described_class.reschedule_abandoned_jobs
116
116
  @dead_job.reload
117
117
  expect(@dead_job.run_at.to_i).to eq(initial_run_at.to_i)
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: 2.4.4
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-09-18 00:00:00.000000000 Z
12
+ date: 2021-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord