inst-jobs 2.4.5 → 2.4.6

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: 3fa880428987cbea8be8cb706b2b4d4fae3164a021107591e7e1f5724a88fc4b
4
- data.tar.gz: f9feb618c4043c02ce428146d9bc1801884639d72867e23f21c5b39b546c6a7f
3
+ metadata.gz: ba509dbe247e504537397a8482595ee6dbeac623c69141a24aa56f753343484f
4
+ data.tar.gz: 69502011608a6ac485012dd8ebc5ed9e616b8643ed92a297778100f9ddf51e15
5
5
  SHA512:
6
- metadata.gz: 9328098d390744e089edb857db0f27d379f3696f66c8c549655e6a9a5ea331e7083dda3eb3203200fb00ca1edf121a1264b7ffb228ea075f43889c8a20f7d02c
7
- data.tar.gz: f6dfe1ad5d03c525daf9e445764bb191cdd6075d0c36156d3ff1499c7fb149718b4d5bb689da16349e49e9b1c25bb1e468ceed7e7cfa30543ce831047a7bd954
6
+ metadata.gz: bba4b9a818f3ce3f0cae2f9d77a556c2d9770a47730328d7b3d6de5c8e5bc338ab24da4a4c5006d68375c9b8c24f24af04a0e711ee71d57b17526c0ca401e275
7
+ data.tar.gz: 8ccc1674c9d7f7b1caa27d759a34b9670bc298ece8d85472ba23b83e03cb672cff7372547a84d8c13363aa93447ff0249255f02e5353458d252ef77e1bc89b35
@@ -463,9 +463,19 @@ module Delayed
463
463
  where("locked_by LIKE ?", "#{name}:%").pluck(:locked_by).map { |locked_by| locked_by.split(":").last.to_i }
464
464
  end
465
465
 
466
+ def self.prefetch_jobs_lock_name
467
+ "Delayed::Job.unlock_orphaned_prefetched_jobs"
468
+ end
469
+
466
470
  def self.unlock_orphaned_prefetched_jobs
467
- horizon = db_time_now - (Settings.parent_process[:prefetched_jobs_timeout] * 4)
468
- where("locked_by LIKE 'prefetch:%' AND locked_at<?", horizon).update_all(locked_at: nil, locked_by: nil)
471
+ transaction do
472
+ # for db performance reasons, we only need one process doing this at a time
473
+ # so if we can't get an advisory lock, just abort. we'll try again soon
474
+ return unless attempt_advisory_lock(prefetch_jobs_lock_name)
475
+
476
+ horizon = db_time_now - (Settings.parent_process[:prefetched_jobs_timeout] * 4)
477
+ where("locked_by LIKE 'prefetch:%' AND locked_at<?", horizon).update_all(locked_at: nil, locked_by: nil)
478
+ end
469
479
  end
470
480
 
471
481
  def self.unlock(jobs)
@@ -148,19 +148,13 @@ module Delayed
148
148
  end
149
149
 
150
150
  def unlock_orphaned_prefetched_jobs
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?
161
-
162
- unlock(orphaned_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
163
154
  end
155
+ return 0 if orphaned_jobs.empty?
156
+
157
+ unlock(orphaned_jobs)
164
158
  end
165
159
 
166
160
  def unlock_orphaned_jobs(pid = nil, name = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "2.4.5"
4
+ VERSION = "2.4.6"
5
5
  end
@@ -195,11 +195,13 @@ module Delayed
195
195
  def unlock_timed_out_prefetched_jobs
196
196
  @prefetched_jobs.each do |(worker_config, jobs)|
197
197
  next if jobs.empty?
198
+ next unless jobs.first.locked_at < Time.now.utc - Settings.parent_process[:prefetched_jobs_timeout]
198
199
 
199
- if jobs.first.locked_at < Time.now.utc - Settings.parent_process[:prefetched_jobs_timeout]
200
+ Delayed::Job.transaction do
201
+ Delayed::Job.connection.execute("SELECT pg_advisory_xact_lock('#{Delayed::Job.prefetch_jobs_lock_name}')")
200
202
  Delayed::Job.unlock(jobs)
201
- @prefetched_jobs[worker_config] = []
202
203
  end
204
+ @prefetched_jobs[worker_config] = []
203
205
  end
204
206
  end
205
207
 
@@ -207,7 +209,10 @@ module Delayed
207
209
  @prefetched_jobs.each do |(_worker_config, jobs)|
208
210
  next if jobs.empty?
209
211
 
210
- Delayed::Job.unlock(jobs)
212
+ Delayed::Job.transaction do
213
+ Delayed::Job.connection.execute("SELECT pg_advisory_xact_lock('#{Delayed::Job.prefetch_jobs_lock_name}')")
214
+ Delayed::Job.unlock(jobs)
215
+ end
211
216
  end
212
217
  @prefetched_jobs = {}
213
218
  end
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.5
4
+ version: 2.4.6
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-20 00:00:00.000000000 Z
12
+ date: 2021-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord