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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fa880428987cbea8be8cb706b2b4d4fae3164a021107591e7e1f5724a88fc4b
|
4
|
+
data.tar.gz: f9feb618c4043c02ce428146d9bc1801884639d72867e23f21c5b39b546c6a7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
data/lib/delayed/backend/base.rb
CHANGED
@@ -148,13 +148,19 @@ module Delayed
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def unlock_orphaned_prefetched_jobs
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
162
|
+
unlock(orphaned_jobs)
|
163
|
+
end
|
158
164
|
end
|
159
165
|
|
160
166
|
def unlock_orphaned_jobs(pid = nil, name = nil)
|
data/lib/delayed/periodic.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/delayed/version.rb
CHANGED
@@ -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(
|
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
|
+
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-
|
12
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|