delayed 2.0.1 → 2.0.3
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 +4 -4
- data/lib/delayed/helpers/migration.rb +13 -18
- data/lib/delayed/monitor.rb +30 -21
- data/lib/delayed/version.rb +1 -1
- data/spec/delayed/__snapshots__/monitor_spec.rb.snap +687 -309
- data/spec/delayed/helpers/migration_spec.rb +33 -18
- data/spec/helper.rb +2 -0
- metadata +2 -2
|
@@ -33,35 +33,50 @@ describe Delayed::Helpers::Migration do
|
|
|
33
33
|
migration.migration_start = Delayed::Job.db_time_now
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
describe '#
|
|
36
|
+
describe '#upsert_index retry behavior' do
|
|
37
37
|
it 'raises exception when wait_timeout is exceeded based on @migration_start' do
|
|
38
|
-
# Simulate migration that started 6 minutes ago
|
|
39
38
|
migration.migration_start = Delayed::Job.db_time_now - 6.minutes
|
|
40
39
|
|
|
40
|
+
allow(migration).to receive(:add_index).and_raise(ActiveRecord::LockWaitTimeout)
|
|
41
|
+
allow(migration.connection).to receive(:indexes).and_return([])
|
|
42
|
+
|
|
41
43
|
expect {
|
|
42
|
-
migration.
|
|
43
|
-
raise ActiveRecord::LockWaitTimeout
|
|
44
|
-
end
|
|
44
|
+
migration.upsert_index(:delayed_jobs, :name, wait_timeout: 5.minutes)
|
|
45
45
|
}.to raise_error(ActiveRecord::LockWaitTimeout)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
it '
|
|
49
|
-
|
|
48
|
+
it 're-checks for invalid index and drops it before retrying after timeout' do
|
|
49
|
+
add_index_calls = 0
|
|
50
|
+
remove_index_calls = 0
|
|
51
|
+
lookup_calls = 0
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
invalid_opts = ActiveRecord.version >= Gem::Version.new('7.1.0') ? { valid?: false } : { unique: true }
|
|
54
|
+
invalid_index = instance_double(
|
|
55
|
+
ActiveRecord::ConnectionAdapters::IndexDefinition,
|
|
56
|
+
name: 'test_idx',
|
|
57
|
+
columns: ['name'],
|
|
58
|
+
**invalid_opts,
|
|
55
59
|
)
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
allow(migration.connection).to receive(:indexes) do
|
|
62
|
+
lookup_calls += 1
|
|
63
|
+
lookup_calls == 2 ? [invalid_index] : []
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
allow(migration).to receive(:add_index) do |*_args|
|
|
67
|
+
add_index_calls += 1
|
|
68
|
+
raise ActiveRecord::StatementTimeout, 'timeout' if add_index_calls == 1
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
allow(migration).to receive(:remove_index) do |*_args|
|
|
72
|
+
remove_index_calls += 1
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
migration.upsert_index(:delayed_jobs, :name, name: 'test_idx', wait_timeout: 5.minutes)
|
|
63
76
|
|
|
64
|
-
expect(
|
|
77
|
+
expect(lookup_calls).to eq(3)
|
|
78
|
+
expect(remove_index_calls).to eq(1)
|
|
79
|
+
expect(add_index_calls).to eq(2)
|
|
65
80
|
end
|
|
66
81
|
end
|
|
67
82
|
end
|
data/spec/helper.rb
CHANGED
|
@@ -279,6 +279,8 @@ QueryUnderTest = Struct.new(:sql, :connection) do
|
|
|
279
279
|
.gsub(/ (AND|OR) /) { "\n #{Regexp.last_match(1).strip} " }
|
|
280
280
|
# normalize and truncate 'AS' names/aliases (changes across Rails versions)
|
|
281
281
|
.gsub(/AS ("|`)?(\w+)("|`)?/) { "AS #{Regexp.last_match(2)[0...63]}" }
|
|
282
|
+
# remove quotes around column names in aggregate functions
|
|
283
|
+
.gsub(/(MIN|MAX|COUNT|SUM)\(("|`)(\w+)("|`)\)/) { "#{Regexp.last_match(1)}(#{Regexp.last_match(3)})" }
|
|
282
284
|
end
|
|
283
285
|
|
|
284
286
|
def explain
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: delayed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Griffith
|
|
@@ -19,7 +19,7 @@ authors:
|
|
|
19
19
|
autorequire:
|
|
20
20
|
bindir: bin
|
|
21
21
|
cert_chain: []
|
|
22
|
-
date: 2026-
|
|
22
|
+
date: 2026-02-02 00:00:00.000000000 Z
|
|
23
23
|
dependencies:
|
|
24
24
|
- !ruby/object:Gem::Dependency
|
|
25
25
|
name: activerecord
|