switchman-inst-jobs 4.0.13 → 4.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20101216224513_create_delayed_jobs.rb +5 -3
  3. data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +2 -0
  4. data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +2 -0
  5. data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +2 -0
  6. data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +9 -7
  7. data/db/migrate/20110610213249_optimize_delayed_jobs.rb +20 -18
  8. data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +28 -26
  9. data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +20 -18
  10. data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +4 -2
  11. data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +61 -59
  12. data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +3 -1
  13. data/db/migrate/20120608191051_add_jobs_run_at_index.rb +3 -1
  14. data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +2 -0
  15. data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +2 -0
  16. data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -0
  17. data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +2 -0
  18. data/db/migrate/20140512213941_add_source_to_jobs.rb +2 -0
  19. data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +51 -49
  20. data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +2 -0
  21. data/db/migrate/20151210162949_improve_max_concurrent.rb +37 -35
  22. data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +4 -2
  23. data/db/migrate/20170308045400_add_shard_id_to_delayed_jobs.rb +2 -0
  24. data/db/migrate/20170308045401_add_delayed_jobs_shard_id_to_switchman_shards.rb +2 -0
  25. data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +73 -71
  26. data/db/migrate/20190726154743_make_critical_columns_not_null.rb +2 -0
  27. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +14 -10
  28. data/db/migrate/20200818130101_add_on_hold_to_switchman_shards.rb +2 -0
  29. data/db/migrate/20200822014259_add_block_stranded_to_switchman_shards.rb +2 -0
  30. data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +6 -4
  31. data/db/migrate/20200825011002_add_strand_order_override.rb +10 -7
  32. data/db/migrate/20210809145804_add_n_strand_index.rb +4 -3
  33. data/db/migrate/20210812210128_add_singleton_column.rb +12 -12
  34. data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +3 -3
  35. data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +2 -2
  36. data/db/migrate/20210929204903_update_conflicting_singleton_function_to_use_index.rb +2 -2
  37. data/db/migrate/20211101190934_update_after_delete_trigger_for_singleton_index.rb +2 -2
  38. data/db/migrate/20211207094200_update_after_delete_trigger_for_singleton_transition_cases.rb +2 -2
  39. data/db/migrate/20211220112800_fix_singleton_race_condition_insert.rb +2 -2
  40. data/db/migrate/20211220113000_fix_singleton_race_condition_delete.rb +2 -2
  41. data/db/migrate/20220127091200_fix_singleton_unique_constraint.rb +6 -6
  42. data/db/migrate/20220128084800_update_insert_trigger_for_singleton_unique_constraint_change.rb +2 -2
  43. data/db/migrate/20220128084900_update_delete_trigger_for_singleton_unique_constraint_change.rb +2 -2
  44. data/db/migrate/20220203063200_remove_old_singleton_index.rb +8 -8
  45. data/db/migrate/20220328152900_add_failed_jobs_indicies.rb +2 -2
  46. data/lib/switchman-inst-jobs.rb +3 -1
  47. data/lib/switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter.rb +3 -1
  48. data/lib/switchman_inst_jobs/active_record/migration.rb +5 -3
  49. data/lib/switchman_inst_jobs/delayed/backend/active_record/abstract_job.rb +2 -0
  50. data/lib/switchman_inst_jobs/delayed/backend/base.rb +10 -2
  51. data/lib/switchman_inst_jobs/delayed/message_sending.rb +2 -0
  52. data/lib/switchman_inst_jobs/delayed/pool.rb +2 -0
  53. data/lib/switchman_inst_jobs/delayed/settings.rb +3 -1
  54. data/lib/switchman_inst_jobs/delayed/worker/health_check.rb +5 -3
  55. data/lib/switchman_inst_jobs/delayed/worker.rb +2 -0
  56. data/lib/switchman_inst_jobs/engine.rb +7 -5
  57. data/lib/switchman_inst_jobs/guard_rail.rb +2 -0
  58. data/lib/switchman_inst_jobs/jobs_migrator.rb +58 -55
  59. data/lib/switchman_inst_jobs/new_relic.rb +2 -0
  60. data/lib/switchman_inst_jobs/switchman/database_server.rb +3 -1
  61. data/lib/switchman_inst_jobs/switchman/default_shard.rb +2 -0
  62. data/lib/switchman_inst_jobs/switchman/shard.rb +27 -23
  63. data/lib/switchman_inst_jobs/timed_cache.rb +2 -0
  64. data/lib/switchman_inst_jobs/version.rb +3 -1
  65. data/lib/switchman_inst_jobs/yaml_extensions.rb +3 -1
  66. data/lib/switchman_inst_jobs.rb +22 -20
  67. metadata +5 -5
@@ -1,46 +1,48 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ImproveMaxConcurrent < ActiveRecord::Migration[4.2]
2
4
  def up
3
- if connection.adapter_name == 'PostgreSQL'
4
- execute(<<-CODE)
5
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
6
- DECLARE
7
- running_count integer;
8
- BEGIN
9
- IF OLD.strand IS NOT NULL THEN
10
- PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
11
- running_count := (SELECT COUNT(*) FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't');
12
- IF running_count < OLD.max_concurrent THEN
13
- UPDATE delayed_jobs SET next_in_strand = 't' WHERE id IN (
14
- SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
15
- j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT (OLD.max_concurrent - running_count) FOR UPDATE
16
- );
5
+ if connection.adapter_name == "PostgreSQL"
6
+ execute(<<~SQL)
7
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
8
+ DECLARE
9
+ running_count integer;
10
+ BEGIN
11
+ IF OLD.strand IS NOT NULL THEN
12
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
13
+ running_count := (SELECT COUNT(*) FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't');
14
+ IF running_count < OLD.max_concurrent THEN
15
+ UPDATE delayed_jobs SET next_in_strand = 't' WHERE id IN (
16
+ SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
17
+ j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT (OLD.max_concurrent - running_count) FOR UPDATE
18
+ );
19
+ END IF;
17
20
  END IF;
18
- END IF;
19
- RETURN OLD;
20
- END;
21
- $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
22
- CODE
21
+ RETURN OLD;
22
+ END;
23
+ $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
24
+ SQL
23
25
  end
24
26
  end
25
27
 
26
28
  def down
27
- if connection.adapter_name == 'PostgreSQL'
28
- execute(<<-CODE)
29
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
30
- BEGIN
31
- IF OLD.strand IS NOT NULL THEN
32
- PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
33
- IF (SELECT COUNT(*) FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't') < OLD.max_concurrent THEN
34
- UPDATE delayed_jobs SET next_in_strand = 't' WHERE id = (
35
- SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
36
- j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT 1 FOR UPDATE
37
- );
29
+ if connection.adapter_name == "PostgreSQL"
30
+ execute(<<~SQL)
31
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
32
+ BEGIN
33
+ IF OLD.strand IS NOT NULL THEN
34
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
35
+ IF (SELECT COUNT(*) FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't') < OLD.max_concurrent THEN
36
+ UPDATE delayed_jobs SET next_in_strand = 't' WHERE id = (
37
+ SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
38
+ j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT 1 FOR UPDATE
39
+ );
40
+ END IF;
38
41
  END IF;
39
- END IF;
40
- RETURN OLD;
41
- END;
42
- $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
43
- CODE
42
+ RETURN OLD;
43
+ END;
44
+ $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
45
+ SQL
44
46
  end
45
47
  end
46
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddBackDefaultStringLimitsJobs < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  drop_triggers
@@ -23,8 +25,8 @@ class AddBackDefaultStringLimitsJobs < ActiveRecord::Migration[4.2]
23
25
  end
24
26
 
25
27
  def readd_triggers
26
- execute("CREATE TRIGGER delayed_jobs_before_insert_row_tr BEFORE INSERT ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (NEW.strand IS NOT NULL) EXECUTE PROCEDURE #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')}()")
27
- execute("CREATE TRIGGER delayed_jobs_after_delete_row_tr AFTER DELETE ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (OLD.strand IS NOT NULL AND OLD.next_in_strand = 't') EXECUTE PROCEDURE #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')}()")
28
+ execute("CREATE TRIGGER delayed_jobs_before_insert_row_tr BEFORE INSERT ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (NEW.strand IS NOT NULL) EXECUTE PROCEDURE #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")}()")
29
+ execute("CREATE TRIGGER delayed_jobs_after_delete_row_tr AFTER DELETE ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (OLD.strand IS NOT NULL AND OLD.next_in_strand = 't') EXECUTE PROCEDURE #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")}()")
28
30
  end
29
31
 
30
32
  def add_string_limit_if_missing(table, column)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddShardIdToDelayedJobs < ActiveRecord::Migration[4.2]
2
4
  disable_ddl_transaction!
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddDelayedJobsShardIdToSwitchmanShards < ActiveRecord::Migration[5.2]
2
4
  def change
3
5
  add_reference :switchman_shards, :delayed_jobs_shard, foreign_key: { to_table: :switchman_shards }, index: false, if_not_exists: true
@@ -1,91 +1,93 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
2
4
  def up
3
- if connection.adapter_name == 'PostgreSQL'
5
+ if connection.adapter_name == "PostgreSQL"
4
6
  # tl;dr sacrifice some responsiveness to max_concurrent changes for faster performance
5
7
  # don't get the count every single time - it's usually safe to just set the next one in line
6
8
  # since the max_concurrent doesn't change all that often for a strand
7
- execute(<<-CODE)
8
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
9
- DECLARE
10
- running_count integer;
11
- BEGIN
12
- IF OLD.strand IS NOT NULL THEN
13
- PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
14
- IF OLD.id % 20 = 0 THEN
15
- running_count := (SELECT COUNT(*) FROM (
16
- SELECT 1 as one FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't' LIMIT OLD.max_concurrent
17
- ) subquery_for_count);
18
- IF running_count < OLD.max_concurrent THEN
19
- UPDATE delayed_jobs SET next_in_strand = 't' WHERE id IN (
20
- SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
21
- j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT (OLD.max_concurrent - running_count) FOR UPDATE
22
- );
9
+ execute(<<~SQL)
10
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
11
+ DECLARE
12
+ running_count integer;
13
+ BEGIN
14
+ IF OLD.strand IS NOT NULL THEN
15
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
16
+ IF OLD.id % 20 = 0 THEN
17
+ running_count := (SELECT COUNT(*) FROM (
18
+ SELECT 1 as one FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't' LIMIT OLD.max_concurrent
19
+ ) subquery_for_count);
20
+ IF running_count < OLD.max_concurrent THEN
21
+ UPDATE delayed_jobs SET next_in_strand = 't' WHERE id IN (
22
+ SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
23
+ j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT (OLD.max_concurrent - running_count) FOR UPDATE
24
+ );
25
+ END IF;
26
+ ELSE
27
+ UPDATE delayed_jobs SET next_in_strand = 't' WHERE id =
28
+ (SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
29
+ j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT 1 FOR UPDATE);
23
30
  END IF;
24
- ELSE
25
- UPDATE delayed_jobs SET next_in_strand = 't' WHERE id =
26
- (SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
27
- j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT 1 FOR UPDATE);
28
31
  END IF;
29
- END IF;
30
- RETURN OLD;
31
- END;
32
- $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
33
- CODE
32
+ RETURN OLD;
33
+ END;
34
+ $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
35
+ SQL
34
36
 
35
37
  # don't need the full count on insert
36
- execute(<<-CODE)
37
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
38
- BEGIN
39
- IF NEW.strand IS NOT NULL THEN
40
- PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
41
- IF (SELECT COUNT(*) FROM (
42
- SELECT 1 AS one FROM delayed_jobs WHERE strand = NEW.strand LIMIT NEW.max_concurrent
43
- ) subquery_for_count) = NEW.max_concurrent THEN
44
- NEW.next_in_strand := 'f';
38
+ execute(<<~SQL)
39
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
40
+ BEGIN
41
+ IF NEW.strand IS NOT NULL THEN
42
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
43
+ IF (SELECT COUNT(*) FROM (
44
+ SELECT 1 AS one FROM delayed_jobs WHERE strand = NEW.strand LIMIT NEW.max_concurrent
45
+ ) subquery_for_count) = NEW.max_concurrent THEN
46
+ NEW.next_in_strand := 'f';
47
+ END IF;
45
48
  END IF;
46
- END IF;
47
- RETURN NEW;
48
- END;
49
- $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
50
- CODE
49
+ RETURN NEW;
50
+ END;
51
+ $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
52
+ SQL
51
53
  end
52
54
  end
53
55
 
54
56
  def down
55
- if connection.adapter_name == 'PostgreSQL'
56
- execute(<<-CODE)
57
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
58
- DECLARE
59
- running_count integer;
60
- BEGIN
61
- IF OLD.strand IS NOT NULL THEN
62
- PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
63
- running_count := (SELECT COUNT(*) FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't');
64
- IF running_count < OLD.max_concurrent THEN
65
- UPDATE delayed_jobs SET next_in_strand = 't' WHERE id IN (
66
- SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
67
- j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT (OLD.max_concurrent - running_count) FOR UPDATE
68
- );
57
+ if connection.adapter_name == "PostgreSQL"
58
+ execute(<<~SQL)
59
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
60
+ DECLARE
61
+ running_count integer;
62
+ BEGIN
63
+ IF OLD.strand IS NOT NULL THEN
64
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
65
+ running_count := (SELECT COUNT(*) FROM delayed_jobs WHERE strand = OLD.strand AND next_in_strand = 't');
66
+ IF running_count < OLD.max_concurrent THEN
67
+ UPDATE delayed_jobs SET next_in_strand = 't' WHERE id IN (
68
+ SELECT id FROM delayed_jobs j2 WHERE next_in_strand = 'f' AND
69
+ j2.strand = OLD.strand ORDER BY j2.id ASC LIMIT (OLD.max_concurrent - running_count) FOR UPDATE
70
+ );
71
+ END IF;
69
72
  END IF;
70
- END IF;
71
- RETURN OLD;
72
- END;
73
- $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
74
- CODE
73
+ RETURN OLD;
74
+ END;
75
+ $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
76
+ SQL
75
77
 
76
- execute(<<-CODE)
77
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
78
- BEGIN
79
- IF NEW.strand IS NOT NULL THEN
80
- PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
81
- IF (SELECT COUNT(*) FROM delayed_jobs WHERE strand = NEW.strand) >= NEW.max_concurrent THEN
82
- NEW.next_in_strand := 'f';
78
+ execute(<<~SQL)
79
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
80
+ BEGIN
81
+ IF NEW.strand IS NOT NULL THEN
82
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
83
+ IF (SELECT COUNT(*) FROM delayed_jobs WHERE strand = NEW.strand) >= NEW.max_concurrent THEN
84
+ NEW.next_in_strand := 'f';
85
+ END IF;
83
86
  END IF;
84
- END IF;
85
- RETURN NEW;
86
- END;
87
- $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
88
- CODE
87
+ RETURN NEW;
88
+ END;
89
+ $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
90
+ SQL
89
91
  end
90
92
  end
91
93
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MakeCriticalColumnsNotNull < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  change_column_null :delayed_jobs, :run_at, false
@@ -1,21 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddIdToGetDelayedJobsIndex < ActiveRecord::Migration[4.2]
2
4
  disable_ddl_transaction!
3
5
 
4
6
  def up
5
- rename_index :delayed_jobs, 'get_delayed_jobs_index', 'get_delayed_jobs_index_old'
6
- add_index :delayed_jobs, %i[queue priority run_at id],
7
+ rename_index :delayed_jobs, "get_delayed_jobs_index", "get_delayed_jobs_index_old"
8
+ add_index :delayed_jobs,
9
+ %i[queue priority run_at id],
7
10
  algorithm: :concurrently,
8
- where: 'locked_at IS NULL AND next_in_strand',
9
- name: 'get_delayed_jobs_index'
10
- remove_index :delayed_jobs, name: 'get_delayed_jobs_index_old'
11
+ where: "locked_at IS NULL AND next_in_strand",
12
+ name: "get_delayed_jobs_index"
13
+ remove_index :delayed_jobs, name: "get_delayed_jobs_index_old"
11
14
  end
12
15
 
13
16
  def down
14
- rename_index :delayed_jobs, 'get_delayed_jobs_index', 'get_delayed_jobs_index_old'
15
- add_index :delayed_jobs, %i[priority run_at queue],
17
+ rename_index :delayed_jobs, "get_delayed_jobs_index", "get_delayed_jobs_index_old"
18
+ add_index :delayed_jobs,
19
+ %i[priority run_at queue],
16
20
  algorithm: :concurrently,
17
- where: 'locked_at IS NULL AND next_in_strand',
18
- name: 'get_delayed_jobs_index'
19
- remove_index :delayed_jobs, name: 'get_delayed_jobs_index_old'
21
+ where: "locked_at IS NULL AND next_in_strand",
22
+ name: "get_delayed_jobs_index"
23
+ remove_index :delayed_jobs, name: "get_delayed_jobs_index_old"
20
24
  end
21
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddOnHoldToSwitchmanShards < ActiveRecord::Migration[5.2]
2
4
  def change
3
5
  add_column :switchman_shards, :jobs_held, :bool, default: false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddBlockStrandedToSwitchmanShards < ActiveRecord::Migration[5.2]
2
4
  def change
3
5
  add_column :switchman_shards, :block_stranded, :bool, default: false
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SpeedUpMaxConcurrentDeleteTrigger < ActiveRecord::Migration[4.2]
2
4
  def up
3
- if connection.adapter_name == 'PostgreSQL'
5
+ if connection.adapter_name == "PostgreSQL"
4
6
  # tl;dr sacrifice some responsiveness to max_concurrent changes for faster performance
5
7
  # don't get the count every single time - it's usually safe to just set the next one in line
6
8
  # since the max_concurrent doesn't change all that often for a strand
7
9
  execute(<<-SQL)
8
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
10
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
9
11
  DECLARE
10
12
  running_count integer;
11
13
  should_lock boolean;
@@ -57,9 +59,9 @@ class SpeedUpMaxConcurrentDeleteTrigger < ActiveRecord::Migration[4.2]
57
59
  end
58
60
 
59
61
  def down
60
- if connection.adapter_name == 'PostgreSQL'
62
+ if connection.adapter_name == "PostgreSQL"
61
63
  execute(<<-SQL)
62
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
64
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
63
65
  DECLARE
64
66
  running_count integer;
65
67
  BEGIN
@@ -1,18 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddStrandOrderOverride < ActiveRecord::Migration[4.2]
2
4
  disable_ddl_transaction!
3
5
 
4
6
  def up
5
7
  add_column :delayed_jobs, :strand_order_override, :integer, default: 0, null: false
6
8
  add_column :failed_jobs, :strand_order_override, :integer, default: 0, null: false
7
- add_index :delayed_jobs, %i[strand strand_order_override id],
9
+ add_index :delayed_jobs,
10
+ %i[strand strand_order_override id],
8
11
  algorithm: :concurrently,
9
- where: 'strand IS NOT NULL',
10
- name: 'next_in_strand_index'
12
+ where: "strand IS NOT NULL",
13
+ name: "next_in_strand_index"
11
14
 
12
- if connection.adapter_name == 'PostgreSQL'
15
+ if connection.adapter_name == "PostgreSQL"
13
16
  # Use the strand_order_override as the primary sorting mechanism (useful when moving between jobs queues without preserving ID ordering)
14
17
  execute(<<-SQL)
15
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
18
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
16
19
  DECLARE
17
20
  running_count integer;
18
21
  should_lock boolean;
@@ -67,9 +70,9 @@ class AddStrandOrderOverride < ActiveRecord::Migration[4.2]
67
70
  remove_column :delayed_jobs, :strand_order_override, :integer
68
71
  remove_column :failed_jobs, :strand_order_override, :integer
69
72
 
70
- if connection.adapter_name == 'PostgreSQL'
73
+ if connection.adapter_name == "PostgreSQL"
71
74
  execute(<<-SQL)
72
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
75
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
73
76
  DECLARE
74
77
  running_count integer;
75
78
  should_lock boolean;
@@ -4,9 +4,10 @@ class AddNStrandIndex < ActiveRecord::Migration[5.2]
4
4
  disable_ddl_transaction!
5
5
 
6
6
  def change
7
- add_index :delayed_jobs, %i[strand next_in_strand id],
8
- name: 'n_strand_index',
9
- where: 'strand IS NOT NULL',
7
+ add_index :delayed_jobs,
8
+ %i[strand next_in_strand id],
9
+ name: "n_strand_index",
10
+ where: "strand IS NOT NULL",
10
11
  algorithm: :concurrently
11
12
  end
12
13
  end
@@ -9,22 +9,22 @@ class AddSingletonColumn < ActiveRecord::Migration[5.2]
9
9
  # only one job can be queued in a singleton
10
10
  add_index :delayed_jobs,
11
11
  :singleton,
12
- where: 'singleton IS NOT NULL AND locked_by IS NULL',
12
+ where: "singleton IS NOT NULL AND locked_by IS NULL",
13
13
  unique: true,
14
- name: 'index_delayed_jobs_on_singleton_not_running',
14
+ name: "index_delayed_jobs_on_singleton_not_running",
15
15
  algorithm: :concurrently
16
16
  # only one job can be running for a singleton
17
17
  add_index :delayed_jobs,
18
18
  :singleton,
19
- where: 'singleton IS NOT NULL AND locked_by IS NOT NULL',
19
+ where: "singleton IS NOT NULL AND locked_by IS NOT NULL",
20
20
  unique: true,
21
- name: 'index_delayed_jobs_on_singleton_running',
21
+ name: "index_delayed_jobs_on_singleton_running",
22
22
  algorithm: :concurrently
23
23
 
24
24
  reversible do |direction|
25
25
  direction.up do
26
26
  execute(<<~SQL)
27
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
27
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
28
28
  DECLARE
29
29
  running_count integer;
30
30
  should_lock boolean;
@@ -88,7 +88,7 @@ class AddSingletonColumn < ActiveRecord::Migration[5.2]
88
88
  $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
89
89
  SQL
90
90
  execute(<<~SQL)
91
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
91
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
92
92
  BEGIN
93
93
  IF NEW.strand IS NOT NULL THEN
94
94
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
@@ -111,7 +111,7 @@ class AddSingletonColumn < ActiveRecord::Migration[5.2]
111
111
  end
112
112
  direction.down do
113
113
  execute(<<~SQL)
114
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
114
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
115
115
  DECLARE
116
116
  running_count integer;
117
117
  should_lock boolean;
@@ -160,7 +160,7 @@ class AddSingletonColumn < ActiveRecord::Migration[5.2]
160
160
  $$ LANGUAGE plpgsql SET search_path TO #{::Switchman::Shard.current.name};
161
161
  SQL
162
162
  execute(<<~SQL)
163
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
163
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
164
164
  BEGIN
165
165
  IF NEW.strand IS NOT NULL THEN
166
166
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
@@ -181,13 +181,13 @@ class AddSingletonColumn < ActiveRecord::Migration[5.2]
181
181
  reversible do |direction|
182
182
  direction.up do
183
183
  drop_triggers
184
- execute("CREATE TRIGGER delayed_jobs_before_insert_row_tr BEFORE INSERT ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (NEW.strand IS NOT NULL OR NEW.singleton IS NOT NULL) EXECUTE PROCEDURE #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')}()")
185
- execute("CREATE TRIGGER delayed_jobs_after_delete_row_tr AFTER DELETE ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN ((OLD.strand IS NOT NULL OR OLD.singleton IS NOT NULL) AND OLD.next_in_strand=true) EXECUTE PROCEDURE #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')}()")
184
+ execute("CREATE TRIGGER delayed_jobs_before_insert_row_tr BEFORE INSERT ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (NEW.strand IS NOT NULL OR NEW.singleton IS NOT NULL) EXECUTE PROCEDURE #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")}()")
185
+ execute("CREATE TRIGGER delayed_jobs_after_delete_row_tr AFTER DELETE ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN ((OLD.strand IS NOT NULL OR OLD.singleton IS NOT NULL) AND OLD.next_in_strand=true) EXECUTE PROCEDURE #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")}()")
186
186
  end
187
187
  direction.down do
188
188
  drop_triggers
189
- execute("CREATE TRIGGER delayed_jobs_before_insert_row_tr BEFORE INSERT ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (NEW.strand IS NOT NULL) EXECUTE PROCEDURE #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')}()")
190
- execute("CREATE TRIGGER delayed_jobs_after_delete_row_tr AFTER DELETE ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (OLD.strand IS NOT NULL AND OLD.next_in_strand = 't') EXECUTE PROCEDURE #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn()')}")
189
+ execute("CREATE TRIGGER delayed_jobs_before_insert_row_tr BEFORE INSERT ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (NEW.strand IS NOT NULL) EXECUTE PROCEDURE #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")}()")
190
+ execute("CREATE TRIGGER delayed_jobs_after_delete_row_tr AFTER DELETE ON #{connection.quote_table_name(::Delayed::Job.table_name)} FOR EACH ROW WHEN (OLD.strand IS NOT NULL AND OLD.next_in_strand = 't') EXECUTE PROCEDURE #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn()")}")
191
191
  end
192
192
  end
193
193
  end
@@ -3,7 +3,7 @@
3
3
  class AddDeleteConflictingSingletonsBeforeUnlockTrigger < ActiveRecord::Migration[5.2]
4
4
  def up
5
5
  execute(<<~SQL)
6
- CREATE FUNCTION #{connection.quote_table_name('delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn')} () RETURNS trigger AS $$
6
+ CREATE FUNCTION #{connection.quote_table_name("delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn")} () RETURNS trigger AS $$
7
7
  BEGIN
8
8
  IF EXISTS (SELECT 1 FROM delayed_jobs j2 WHERE j2.singleton=OLD.singleton) THEN
9
9
  DELETE FROM delayed_jobs WHERE id<>OLD.id AND singleton=OLD.singleton;
@@ -17,11 +17,11 @@ class AddDeleteConflictingSingletonsBeforeUnlockTrigger < ActiveRecord::Migratio
17
17
  OLD.singleton IS NOT NULL AND
18
18
  OLD.singleton=NEW.singleton AND
19
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')}();
20
+ NEW.locked_by IS NULL) EXECUTE PROCEDURE #{connection.quote_table_name("delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn")}();
21
21
  SQL
22
22
  end
23
23
 
24
24
  def down
25
- execute("DROP FUNCTION #{connection.quote_table_name('delayed_jobs_before_unlock_delete_conflicting_singletons_row_tr_fn')}() CASCADE")
25
+ execute("DROP FUNCTION #{connection.quote_table_name("delayed_jobs_before_unlock_delete_conflicting_singletons_row_tr_fn")}() CASCADE")
26
26
  end
27
27
  end
@@ -5,7 +5,7 @@ class FixSingletonConditionInBeforeInsert < ActiveRecord::Migration[5.2]
5
5
  reversible do |direction|
6
6
  direction.up do
7
7
  execute(<<~SQL)
8
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
8
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
9
9
  BEGIN
10
10
  IF NEW.strand IS NOT NULL THEN
11
11
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
@@ -30,7 +30,7 @@ class FixSingletonConditionInBeforeInsert < ActiveRecord::Migration[5.2]
30
30
  end
31
31
  direction.down do
32
32
  execute(<<~SQL)
33
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
33
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
34
34
  BEGIN
35
35
  IF NEW.strand IS NOT NULL THEN
36
36
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
@@ -3,7 +3,7 @@
3
3
  class UpdateConflictingSingletonFunctionToUseIndex < ActiveRecord::Migration[5.2]
4
4
  def up
5
5
  execute(<<~SQL)
6
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn')} () RETURNS trigger AS $$
6
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn")} () RETURNS trigger AS $$
7
7
  BEGIN
8
8
  DELETE FROM delayed_jobs WHERE id<>OLD.id AND singleton=OLD.singleton AND locked_by IS NULL;
9
9
  RETURN NEW;
@@ -14,7 +14,7 @@ class UpdateConflictingSingletonFunctionToUseIndex < ActiveRecord::Migration[5.2
14
14
 
15
15
  def down
16
16
  execute(<<~SQL)
17
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn')} () RETURNS trigger AS $$
17
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_unlock_delete_conflicting_singletons_row_fn")} () RETURNS trigger AS $$
18
18
  BEGIN
19
19
  IF EXISTS (SELECT 1 FROM delayed_jobs j2 WHERE j2.singleton=OLD.singleton) THEN
20
20
  DELETE FROM delayed_jobs WHERE id<>OLD.id AND singleton=OLD.singleton;
@@ -3,7 +3,7 @@
3
3
  class UpdateAfterDeleteTriggerForSingletonIndex < ActiveRecord::Migration[5.2]
4
4
  def up
5
5
  execute(<<~SQL)
6
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
6
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
7
7
  DECLARE
8
8
  running_count integer;
9
9
  should_lock boolean;
@@ -70,7 +70,7 @@ class UpdateAfterDeleteTriggerForSingletonIndex < ActiveRecord::Migration[5.2]
70
70
 
71
71
  def down
72
72
  execute(<<~SQL)
73
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
73
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
74
74
  DECLARE
75
75
  running_count integer;
76
76
  should_lock boolean;
@@ -3,7 +3,7 @@
3
3
  class UpdateAfterDeleteTriggerForSingletonTransitionCases < ActiveRecord::Migration[5.2]
4
4
  def up
5
5
  execute(<<~SQL)
6
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
6
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
7
7
  DECLARE
8
8
  next_strand varchar;
9
9
  running_count integer;
@@ -104,7 +104,7 @@ class UpdateAfterDeleteTriggerForSingletonTransitionCases < ActiveRecord::Migrat
104
104
 
105
105
  def down
106
106
  execute(<<~SQL)
107
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_after_delete_row_tr_fn')} () RETURNS trigger AS $$
107
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_after_delete_row_tr_fn")} () RETURNS trigger AS $$
108
108
  DECLARE
109
109
  running_count integer;
110
110
  should_lock boolean;
@@ -5,7 +5,7 @@ class FixSingletonRaceConditionInsert < ActiveRecord::Migration[5.2]
5
5
  reversible do |direction|
6
6
  direction.up do
7
7
  execute(<<~SQL)
8
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
8
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
9
9
  BEGIN
10
10
  IF NEW.strand IS NOT NULL THEN
11
11
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
@@ -31,7 +31,7 @@ class FixSingletonRaceConditionInsert < ActiveRecord::Migration[5.2]
31
31
  end
32
32
  direction.down do
33
33
  execute(<<~SQL)
34
- CREATE OR REPLACE FUNCTION #{connection.quote_table_name('delayed_jobs_before_insert_row_tr_fn')} () RETURNS trigger AS $$
34
+ CREATE OR REPLACE FUNCTION #{connection.quote_table_name("delayed_jobs_before_insert_row_tr_fn")} () RETURNS trigger AS $$
35
35
  BEGIN
36
36
  IF NEW.strand IS NOT NULL THEN
37
37
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));