switchman-inst-jobs 3.2.1 → 3.2.2
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/db/migrate/20210812210128_add_singleton_column.rb +0 -3
- data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +27 -0
- data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +56 -0
- data/lib/switchman_inst_jobs/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 98c61abb5cfc89f0f020fdaf985b7dd97620813192052fa6859504d06b9d8394
|
|
4
|
+
data.tar.gz: d57c6382a723425eb15abbcc7bcd62869b3a31defc15df1339e2d81ca656d8cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31f03b8c1ccb6d95e7824671728e78ddb362b326fb007509db9b543621b17f22179d097f383e43c2b233fe78a563eec09a4fddc6d4af872cc4554fa1f68a6e88
|
|
7
|
+
data.tar.gz: 5a84c259b4dfe96df5d8cad336b0ba4555fb0f89e110d172f59fdbfeca0f090fed9ad9e1028d361cbf281997c6415dd6ae2e828de47d23b519706e624f580f46
|
|
@@ -90,7 +90,6 @@ class AddSingletonColumn < ActiveRecord::Migration[5.2]
|
|
|
90
90
|
execute(<<~SQL)
|
|
91
91
|
CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
|
|
92
92
|
BEGIN
|
|
93
|
-
RAISE NOTICE 'inserting job';
|
|
94
93
|
IF NEW.strand IS NOT NULL THEN
|
|
95
94
|
PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
|
|
96
95
|
IF (SELECT COUNT(*) FROM (
|
|
@@ -100,10 +99,8 @@ class AddSingletonColumn < ActiveRecord::Migration[5.2]
|
|
|
100
99
|
END IF;
|
|
101
100
|
END IF;
|
|
102
101
|
IF NEW.singleton IS NOT NULL THEN
|
|
103
|
-
RAISE NOTICE 'inserting job that is a singleton';
|
|
104
102
|
PERFORM 1 FROM delayed_jobs WHERE singleton = NEW.singleton;
|
|
105
103
|
IF FOUND THEN
|
|
106
|
-
RAISE NOTICE 'and not first';
|
|
107
104
|
NEW.next_in_strand := false;
|
|
108
105
|
END IF;
|
|
109
106
|
END IF;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddDeleteConflictingSingletonsBeforeUnlockTrigger < ActiveRecord::Migration[5.2]
|
|
4
|
+
def up
|
|
5
|
+
execute(<<~SQL)
|
|
6
|
+
CREATE FUNCTION #{connection.quote_table_name('delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn')} () RETURNS trigger AS $$
|
|
7
|
+
BEGIN
|
|
8
|
+
IF EXISTS (SELECT 1 FROM delayed_jobs j2 WHERE j2.singleton=OLD.singleton) THEN
|
|
9
|
+
DELETE FROM delayed_jobs WHERE id<>OLD.id AND singleton=OLD.singleton;
|
|
10
|
+
END IF;
|
|
11
|
+
RETURN NEW;
|
|
12
|
+
END;
|
|
13
|
+
$$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
|
|
14
|
+
SQL
|
|
15
|
+
execute(<<~SQL)
|
|
16
|
+
CREATE TRIGGER delayed_jobs_before_unlock_delete_conflicting_singletons_row_tr BEFORE UPDATE ON #{::Delayed::Job.quoted_table_name} FOR EACH ROW WHEN (
|
|
17
|
+
OLD.singleton IS NOT NULL AND
|
|
18
|
+
OLD.singleton=NEW.singleton AND
|
|
19
|
+
OLD.locked_by IS NOT NULL AND
|
|
20
|
+
NEW.locked_by IS NULL) EXECUTE PROCEDURE #{connection.quote_table_name('delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn')}();
|
|
21
|
+
SQL
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def down
|
|
25
|
+
execute("DROP FUNCTION #{connection.quote_table_name('delayed_jobs_before_unlock_delete_conflicting_singletons_row_tr_fn')}() CASCADE")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class FixSingletonConditionInBeforeInsert < ActiveRecord::Migration[5.2]
|
|
4
|
+
def change
|
|
5
|
+
reversible do |direction|
|
|
6
|
+
direction.up do
|
|
7
|
+
execute(<<~SQL)
|
|
8
|
+
CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
|
|
9
|
+
BEGIN
|
|
10
|
+
IF NEW.strand IS NOT NULL THEN
|
|
11
|
+
PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
|
|
12
|
+
IF (SELECT COUNT(*) FROM (
|
|
13
|
+
SELECT 1 FROM delayed_jobs WHERE strand = NEW.strand AND next_in_strand=true LIMIT NEW.max_concurrent
|
|
14
|
+
) s) = NEW.max_concurrent THEN
|
|
15
|
+
NEW.next_in_strand := false;
|
|
16
|
+
END IF;
|
|
17
|
+
END IF;
|
|
18
|
+
IF NEW.singleton IS NOT NULL THEN
|
|
19
|
+
-- this condition seems silly, but it forces postgres to use the two partial indexes on singleton,
|
|
20
|
+
-- rather than doing a seq scan
|
|
21
|
+
PERFORM 1 FROM delayed_jobs WHERE singleton = NEW.singleton AND (locked_by IS NULL OR locked_by IS NOT NULL);
|
|
22
|
+
IF FOUND THEN
|
|
23
|
+
NEW.next_in_strand := false;
|
|
24
|
+
END IF;
|
|
25
|
+
END IF;
|
|
26
|
+
RETURN NEW;
|
|
27
|
+
END;
|
|
28
|
+
$$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
|
|
29
|
+
SQL
|
|
30
|
+
end
|
|
31
|
+
direction.down do
|
|
32
|
+
execute(<<~SQL)
|
|
33
|
+
CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
|
|
34
|
+
BEGIN
|
|
35
|
+
IF NEW.strand IS NOT NULL THEN
|
|
36
|
+
PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
|
|
37
|
+
IF (SELECT COUNT(*) FROM (
|
|
38
|
+
SELECT 1 FROM delayed_jobs WHERE strand = NEW.strand AND next_in_strand=true LIMIT NEW.max_concurrent
|
|
39
|
+
) s) = NEW.max_concurrent THEN
|
|
40
|
+
NEW.next_in_strand := false;
|
|
41
|
+
END IF;
|
|
42
|
+
END IF;
|
|
43
|
+
IF NEW.singleton IS NOT NULL THEN
|
|
44
|
+
PERFORM 1 FROM delayed_jobs WHERE singleton = NEW.singleton;
|
|
45
|
+
IF FOUND THEN
|
|
46
|
+
NEW.next_in_strand := false;
|
|
47
|
+
END IF;
|
|
48
|
+
END IF;
|
|
49
|
+
RETURN NEW;
|
|
50
|
+
END;
|
|
51
|
+
$$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
|
|
52
|
+
SQL
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
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.
|
|
4
|
+
version: 3.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bryan Petty
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-09-
|
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: inst-jobs
|
|
@@ -16,7 +16,7 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 2.4.
|
|
19
|
+
version: 2.4.9
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
22
|
version: '3.0'
|
|
@@ -26,7 +26,7 @@ dependencies:
|
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 2.4.
|
|
29
|
+
version: 2.4.9
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '3.0'
|
|
@@ -298,6 +298,8 @@ files:
|
|
|
298
298
|
- db/migrate/20200825011002_add_strand_order_override.rb
|
|
299
299
|
- db/migrate/20210809145804_add_n_strand_index.rb
|
|
300
300
|
- db/migrate/20210812210128_add_singleton_column.rb
|
|
301
|
+
- db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb
|
|
302
|
+
- db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb
|
|
301
303
|
- lib/switchman-inst-jobs.rb
|
|
302
304
|
- lib/switchman_inst_jobs.rb
|
|
303
305
|
- lib/switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter.rb
|