switchman-inst-jobs 3.2.8 → 3.2.9

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: e4023807a9b569aff8d1751ded026466f0e135b8eae0c6ad9ff7bd80a1a7f818
4
- data.tar.gz: 8a61cde9444723e15b3ec0c6034791e1887972a572755fea1e72b87fe004ec7d
3
+ metadata.gz: 4f4d9ba9513be35bfcc25eb4273305aea1474ed42299bd7a45675cf6476e4eb1
4
+ data.tar.gz: 7d2222fa91a0a3ad4f5d19bb8705b118b909608608b29b2188e0d45bfad30f1e
5
5
  SHA512:
6
- metadata.gz: 0a947509044626f1ccebbd8c1ec34db74e0086dd3df8f8ef7a6b3dfbc6c616bb76a3832cf3a168191b954d1241586bacf8a7909bbeb3a7be1eec21eb3426865e
7
- data.tar.gz: fb103f3ec6eff9c2b356f592f133c8eaae99b08487623b3d0aee257f1cb1215620d66824eb221ec745abc96e9c19fdcb5c254bd5bffec78bfcd283d9cd2b9745
6
+ metadata.gz: b9fd01c47c6d4c9a4556a41a53bdcf54c43c8f1d1ce25109decafbf2ee3bf4b4fa155e3c284ecb4cbf3d5a52b99eff2fc08aa743bf73bb9c0eb93cb4e63c4f03
7
+ data.tar.gz: 919c31f442cd5eb1cbeb6fb1669b20f6abeec5f1c58d9fb0b3dedb978d3ae66a9fd2d9f1f7195f6fec79982c02f1510ae686a0c55397c32dac5666270e4bc27d
@@ -100,7 +100,7 @@ module SwitchmanInstJobs
100
100
  # those (= do nothing since it should already be false)
101
101
  # 4) no running job, jobs moved: set next_in_strand=true on the first of
102
102
  # those (= do nothing since it should already be true)
103
- handler = lambda { |scope, column, blocker_job_kwargs = {}|
103
+ handler = lambda { |scope, column, blocker_job_kwargs = {}, advisory_lock_cb = nil|
104
104
  shard_map = build_shard_map(scope, source_shard)
105
105
  shard_map.each do |(target_shard, source_shard_ids)|
106
106
  shard_scope = scope.where(shard_id: source_shard_ids)
@@ -111,6 +111,10 @@ module SwitchmanInstJobs
111
111
  target_shard.activate(:delayed_jobs) do
112
112
  values.each do |value|
113
113
  transaction_on([source_shard, target_shard]) do
114
+ source_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do
115
+ advisory_lock_cb&.call(value)
116
+ end
117
+
114
118
  value_scope = shard_scope.where(**{ column => value })
115
119
  # we want to copy all the jobs except the one that is still running.
116
120
  jobs_scope = value_scope.where(locked_by: nil)
@@ -151,9 +155,21 @@ module SwitchmanInstJobs
151
155
  singleton_scope = ::Delayed::Job.shard(source_shard).where('strand IS NULL AND singleton IS NOT NULL')
152
156
  all_scope = ::Delayed::Job.shard(source_shard).where('strand IS NOT NULL OR singleton IS NOT NULL')
153
157
 
154
- handler.call(strand_scope, :strand)
155
- handler.call(singleton_scope, :singleton,
156
- { locked_at: DateTime.now, locked_by: ::Delayed::Backend::Base::ON_HOLD_BLOCKER })
158
+ singleton_blocker_additional_kwargs = {
159
+ locked_at: DateTime.now,
160
+ locked_by: ::Delayed::Backend::Base::ON_HOLD_BLOCKER
161
+ }
162
+
163
+ strand_advisory_lock_fn = lambda do |value|
164
+ ::Delayed::Job.connection.execute("SELECT pg_advisory_xact_lock(half_md5_as_bigint('#{value}'))")
165
+ end
166
+
167
+ singleton_advisory_lock_fn = lambda do |value|
168
+ ::Delayed::Job.connection.execute("SELECT pg_advisory_xact_lock(half_md5_as_bigint('singleton:#{value}'))")
169
+ end
170
+
171
+ handler.call(strand_scope, :strand, {}, strand_advisory_lock_fn)
172
+ handler.call(singleton_scope, :singleton, singleton_blocker_additional_kwargs, singleton_advisory_lock_fn)
157
173
 
158
174
  shard_map = build_shard_map(all_scope, source_shard)
159
175
  shard_map.each do |(target_shard, source_shard_ids)|
@@ -1,3 +1,3 @@
1
1
  module SwitchmanInstJobs
2
- VERSION = '3.2.8'.freeze
2
+ VERSION = '3.2.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman-inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.8
4
+ version: 3.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Petty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inst-jobs