switchman-inst-jobs 4.3.0 → 4.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 469e2aadfc5975a5a52eff1f92550e0d811bd30962cc25346f287e829ec88e7c
4
- data.tar.gz: 10956f8da4d2662236a7ef61a092e6cd568e46886729428025625f8a17fc2ce9
3
+ metadata.gz: 3d126fdf9fae2bd957760dd1fdf1cac821e5103eb691fc2b293b3bda6170bb5c
4
+ data.tar.gz: 977e7915aea7e1e389ad95c190e5ae749a868f869f1d28542ee264342f57b89e
5
5
  SHA512:
6
- metadata.gz: aa941c70362bbe2c61b0cb155110fd6e9905af1720f8925fbe80eb990ffc242d1788873b19e273b914e0a1b56c4346984a3ae9e3486454f2304c826d13bb42b7
7
- data.tar.gz: 777f46f0ed99fa7f2a298ce6c839f5be066fb5a1a553833d80527d20c1925e7a119411ecea6e6b6c0fad205920d1e9bcea9b2850f1295938cf31b02f9b74d659
6
+ metadata.gz: 407591bf52c6068c6133b1654a68ffacb4aae0c0d941f7bdab9536a682c70a0a3ca04017c68e61ac6475fbd75a0b7cb93c35b1ce94e6e54b69fb638020802225
7
+ data.tar.gz: d5a69e5b56e07f4c90dcd5fea9f28f491c56f832acdd821b081ee5d3bb068af516b9ca114d464cda4f154edf4765b91c3d10c05f60b31c6612b5e72dca0c79ec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddPreviousJobsShard < ActiveRecord::Migration[7.1]
4
+ def change
5
+ add_reference :switchman_shards, :previous_delayed_jobs_shard, foreign_key: { to_table: :switchman_shards }, index: false, if_not_exists: true
6
+ end
7
+ end
@@ -35,12 +35,24 @@ module SwitchmanInstJobs
35
35
  end
36
36
 
37
37
  def migrate_shards(shard_map)
38
- source_shards = Set[]
38
+ effective_map = shard_map.dup
39
+ source_shards = Hash.new([].freeze)
39
40
  target_shards = Hash.new([].freeze)
40
- shard_map.each do |(shard, target_shard)|
41
+ # Also add any incomplete moves to the source shards to ensure we clean up appropriately
42
+ ::Switchman::Shard.where.not(previous_delayed_jobs_shard_id: nil).find_each do |shard|
43
+ effective_map[shard.id] ||= shard.delayed_jobs_shard.id
44
+ end
45
+ effective_map.each do |(shard, target_shard)|
41
46
  shard = ::Switchman::Shard.find(shard) unless shard.is_a?(::Switchman::Shard)
42
- source_shards << shard.delayed_jobs_shard.id
43
47
  target_shard = target_shard.try(:id) || target_shard
48
+ # if a move was interrupted, the new shard is already set as the delayed_jobs_shard
49
+ # but we still have the old shard stored in previous_delayed_jobs_shard and should
50
+ # act as if we are moving from there in the first place
51
+ if shard.previous_delayed_jobs_shard_id && shard.delayed_jobs_shard.id == target_shard
52
+ source_shards[shard.previous_delayed_jobs_shard_id] += [shard.id]
53
+ else
54
+ source_shards[shard.delayed_jobs_shard.id] += [shard.id]
55
+ end
44
56
  target_shards[target_shard] += [shard.id]
45
57
 
46
58
  @validation_callbacks&.each do |proc|
@@ -48,26 +60,33 @@ module SwitchmanInstJobs
48
60
  end
49
61
  end
50
62
 
51
- # Do the updates in batches and then just clear redis instead of clearing them one at a time
52
- target_shards.each do |target_shard, shards|
53
- updates = { delayed_jobs_shard_id: target_shard, block_stranded: true }
54
- updates[:updated_at] = Time.zone.now if ::Switchman::Shard.column_names.include?("updated_at")
55
- ::Switchman::Shard.where(id: shards).update_all(updates)
63
+ ::Switchman::Shard.transaction do
64
+ # Do the updates in batches and then just clear redis instead of clearing them one at a time
65
+ source_shards.each do |source_shard, shards|
66
+ updates = { previous_delayed_jobs_shard_id: source_shard }
67
+ ::Switchman::Shard.where(id: shards).update_all(updates)
68
+ end
69
+ target_shards.each do |target_shard, shards|
70
+ updates = { delayed_jobs_shard_id: target_shard, block_stranded: true }
71
+ updates[:updated_at] = Time.zone.now if ::Switchman::Shard.column_names.include?("updated_at")
72
+ ::Switchman::Shard.where(id: shards).update_all(updates)
73
+ end
56
74
  end
57
75
  clear_shard_cache(default: ::Switchman::Shard.exists?(id: target_shards.values.flatten, default: true))
58
76
 
59
77
  ::Switchman::Shard.clear_cache
60
78
  # rubocop:disable Style/CombinableLoops
61
79
  # We first migrate strands so that we can stop blocking strands before we migrate unstranded jobs
62
- source_shards.each do |s|
80
+ source_shards.each_key do |s|
63
81
  ::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_strands }
64
82
  end
65
83
 
66
- source_shards.each do |s|
84
+ source_shards.each_key do |s|
67
85
  ::Switchman::Shard.lookup(s).activate(::Delayed::Backend::ActiveRecord::AbstractJob) { migrate_everything }
68
86
  end
69
- ensure_unblock_stranded_for(shard_map.map(&:first))
87
+ ensure_unblock_stranded_for(effective_map.map(&:first))
70
88
  # rubocop:enable Style/CombinableLoops
89
+ ::Switchman::Shard.where(id: effective_map.map(&:first)).update_all(previous_delayed_jobs_shard_id: nil)
71
90
  end
72
91
 
73
92
  # if :migrate_strands ran on any shards that fell into scenario 1, then
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwitchmanInstJobs
4
- VERSION = "4.3.0"
4
+ VERSION = "4.3.1"
5
5
  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: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Petty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-26 00:00:00.000000000 Z
11
+ date: 2026-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inst-jobs
@@ -136,6 +136,7 @@ files:
136
136
  - db/migrate/20220203063200_remove_old_singleton_index.rb
137
137
  - db/migrate/20220328152900_add_failed_jobs_indicies.rb
138
138
  - db/migrate/20220519204546_add_requeued_job_id_to_failed_jobs.rb
139
+ - db/migrate/20260120092005_add_previous_jobs_shard.rb
139
140
  - lib/switchman-inst-jobs.rb
140
141
  - lib/switchman_inst_jobs.rb
141
142
  - lib/switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter.rb