inst-jobs 2.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20101216224513_create_delayed_jobs.rb +9 -7
  3. data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +8 -13
  4. data/db/migrate/20110610213249_optimize_delayed_jobs.rb +8 -8
  5. data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +25 -25
  6. data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +4 -8
  7. data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +1 -3
  8. data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +11 -15
  9. data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +1 -1
  10. data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -2
  11. data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +1 -1
  12. data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -3
  13. data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +9 -13
  14. data/db/migrate/20151210162949_improve_max_concurrent.rb +4 -8
  15. data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +3 -2
  16. data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +13 -17
  17. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +8 -8
  18. data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +72 -77
  19. data/db/migrate/20200825011002_add_strand_order_override.rb +93 -97
  20. data/db/migrate/20210809145804_add_n_strand_index.rb +12 -0
  21. data/db/migrate/20210812210128_add_singleton_column.rb +200 -0
  22. data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +27 -0
  23. data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +56 -0
  24. data/db/migrate/20210929204903_update_conflicting_singleton_function_to_use_index.rb +27 -0
  25. data/db/migrate/20211101190934_update_after_delete_trigger_for_singleton_index.rb +137 -0
  26. data/db/migrate/20211207094200_update_after_delete_trigger_for_singleton_transition_cases.rb +171 -0
  27. data/db/migrate/20211220112800_fix_singleton_race_condition_insert.rb +59 -0
  28. data/db/migrate/20211220113000_fix_singleton_race_condition_delete.rb +207 -0
  29. data/db/migrate/20220127091200_fix_singleton_unique_constraint.rb +31 -0
  30. data/db/migrate/20220128084800_update_insert_trigger_for_singleton_unique_constraint_change.rb +60 -0
  31. data/db/migrate/20220128084900_update_delete_trigger_for_singleton_unique_constraint_change.rb +209 -0
  32. data/db/migrate/20220203063200_remove_old_singleton_index.rb +31 -0
  33. data/db/migrate/20220328152900_add_failed_jobs_indicies.rb +12 -0
  34. data/exe/inst_jobs +3 -2
  35. data/lib/delayed/backend/active_record.rb +226 -168
  36. data/lib/delayed/backend/base.rb +119 -72
  37. data/lib/delayed/batch.rb +11 -9
  38. data/lib/delayed/cli.rb +98 -84
  39. data/lib/delayed/core_ext/kernel.rb +4 -2
  40. data/lib/delayed/daemon.rb +70 -74
  41. data/lib/delayed/job_tracking.rb +26 -25
  42. data/lib/delayed/lifecycle.rb +28 -23
  43. data/lib/delayed/log_tailer.rb +17 -17
  44. data/lib/delayed/logging.rb +13 -16
  45. data/lib/delayed/message_sending.rb +43 -52
  46. data/lib/delayed/performable_method.rb +6 -8
  47. data/lib/delayed/periodic.rb +72 -68
  48. data/lib/delayed/plugin.rb +2 -4
  49. data/lib/delayed/pool.rb +205 -168
  50. data/lib/delayed/rails_reloader_plugin.rb +30 -0
  51. data/lib/delayed/server/helpers.rb +6 -6
  52. data/lib/delayed/server.rb +51 -54
  53. data/lib/delayed/settings.rb +96 -81
  54. data/lib/delayed/testing.rb +21 -22
  55. data/lib/delayed/version.rb +1 -1
  56. data/lib/delayed/work_queue/in_process.rb +21 -17
  57. data/lib/delayed/work_queue/parent_process/client.rb +55 -53
  58. data/lib/delayed/work_queue/parent_process/server.rb +245 -207
  59. data/lib/delayed/work_queue/parent_process.rb +52 -53
  60. data/lib/delayed/worker/consul_health_check.rb +32 -33
  61. data/lib/delayed/worker/health_check.rb +35 -27
  62. data/lib/delayed/worker/null_health_check.rb +3 -1
  63. data/lib/delayed/worker/process_helper.rb +11 -12
  64. data/lib/delayed/worker.rb +257 -244
  65. data/lib/delayed/yaml_extensions.rb +12 -10
  66. data/lib/delayed_job.rb +37 -37
  67. data/lib/inst-jobs.rb +1 -1
  68. data/spec/active_record_job_spec.rb +152 -139
  69. data/spec/delayed/cli_spec.rb +7 -7
  70. data/spec/delayed/daemon_spec.rb +10 -9
  71. data/spec/delayed/message_sending_spec.rb +16 -9
  72. data/spec/delayed/periodic_spec.rb +14 -21
  73. data/spec/delayed/server_spec.rb +38 -38
  74. data/spec/delayed/settings_spec.rb +26 -25
  75. data/spec/delayed/work_queue/in_process_spec.rb +8 -9
  76. data/spec/delayed/work_queue/parent_process/client_spec.rb +17 -12
  77. data/spec/delayed/work_queue/parent_process/server_spec.rb +118 -42
  78. data/spec/delayed/work_queue/parent_process_spec.rb +21 -23
  79. data/spec/delayed/worker/consul_health_check_spec.rb +37 -50
  80. data/spec/delayed/worker/health_check_spec.rb +60 -52
  81. data/spec/delayed/worker_spec.rb +53 -24
  82. data/spec/sample_jobs.rb +45 -15
  83. data/spec/shared/delayed_batch.rb +74 -67
  84. data/spec/shared/delayed_method.rb +143 -102
  85. data/spec/shared/performable_method.rb +39 -38
  86. data/spec/shared/shared_backend.rb +801 -440
  87. data/spec/shared/testing.rb +14 -14
  88. data/spec/shared/worker.rb +157 -149
  89. data/spec/shared_jobs_specs.rb +13 -13
  90. data/spec/spec_helper.rb +57 -56
  91. metadata +183 -103
  92. data/lib/delayed/backend/redis/bulk_update.lua +0 -50
  93. data/lib/delayed/backend/redis/destroy_job.lua +0 -2
  94. data/lib/delayed/backend/redis/enqueue.lua +0 -29
  95. data/lib/delayed/backend/redis/fail_job.lua +0 -5
  96. data/lib/delayed/backend/redis/find_available.lua +0 -3
  97. data/lib/delayed/backend/redis/functions.rb +0 -59
  98. data/lib/delayed/backend/redis/get_and_lock_next_available.lua +0 -17
  99. data/lib/delayed/backend/redis/includes/jobs_common.lua +0 -203
  100. data/lib/delayed/backend/redis/job.rb +0 -535
  101. data/lib/delayed/backend/redis/set_running.lua +0 -5
  102. data/lib/delayed/backend/redis/tickle_strand.lua +0 -2
  103. data/spec/gemfiles/42.gemfile +0 -7
  104. data/spec/gemfiles/50.gemfile +0 -7
  105. data/spec/gemfiles/51.gemfile +0 -7
  106. data/spec/gemfiles/52.gemfile +0 -7
  107. data/spec/gemfiles/60.gemfile +0 -7
  108. data/spec/redis_job_spec.rb +0 -148
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d674b7da21caf04eb87ff9823ed549c93a901219669316090d088f0699564e59
4
- data.tar.gz: 021456d34f12eff8cc988db866018d701fc77ffdbb57e9fb308fc1bd25a91ecb
3
+ metadata.gz: 37ca25ff97580c47a56d0d40a1ab2f78c62a2f47629d0c2e5ba6c8e5c4ace0bd
4
+ data.tar.gz: 16d4a060bfc0c23f84360d305e35adb5482d0d96f50b50c1a45a8a0b02739c90
5
5
  SHA512:
6
- metadata.gz: ad78cfdd9026db24b714c532c8ee837a875e443afc375909f0c130e3cfbf87d1f872344f982d931838bfa6649a2f1edc59430f6444a2baee08f8afb568015cfc
7
- data.tar.gz: e2b127477f0687958178505628b9544aa5c49e7aa1d0ceef32892250aa26aeb1c77f12bcacd6682e17c2bc379f987b154a0f982e029852432c39f7b3a5335df8
6
+ metadata.gz: 7f981418c6f0493c84114777193674559f8a0a15006547600bc00cc44eaaff08232c7695f801a3b84c2919167c68c7fb7d91562aa1d4d47d9f98d28a1362b0e3
7
+ data.tar.gz: 4b31d64c30f9208c54b32796d6ad99f22f9beb3f405a8b4585398306d03b15063d3fde88fce2d063f4f76949da1e350bf4607b8bcf6709a4a20ff686f5c87b6d
@@ -6,19 +6,21 @@ class CreateDelayedJobs < ActiveRecord::Migration[4.2]
6
6
  end
7
7
 
8
8
  def up
9
- raise("#{connection.adapter_name} is not supported for delayed jobs queue") unless connection.adapter_name == 'PostgreSQL'
9
+ unless connection.adapter_name == "PostgreSQL"
10
+ raise("#{connection.adapter_name} is not supported for delayed jobs queue")
11
+ end
10
12
 
11
13
  create_table :delayed_jobs do |table|
12
14
  # Allows some jobs to jump to the front of the queue
13
- table.integer :priority, :default => 0
15
+ table.integer :priority, default: 0
14
16
  # Provides for retries, but still fail eventually.
15
- table.integer :attempts, :default => 0
17
+ table.integer :attempts, default: 0
16
18
  # YAML-encoded string of the object that will do work
17
- table.text :handler, :limit => (500 * 1024)
19
+ table.text :handler, limit: (500 * 1024)
18
20
  # reason for last failure (See Note below)
19
21
  table.text :last_error
20
22
  # The queue that this job is in
21
- table.string :queue, :default => nil
23
+ table.string :queue, default: nil
22
24
  # When to run.
23
25
  # Could be Time.zone.now for immediately, or sometime in the future.
24
26
  table.datetime :run_at
@@ -32,8 +34,8 @@ class CreateDelayedJobs < ActiveRecord::Migration[4.2]
32
34
  table.timestamps
33
35
  end
34
36
 
35
- add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
36
- add_index :delayed_jobs, [:queue], :name => 'delayed_jobs_queue'
37
+ add_index :delayed_jobs, %i[priority run_at], name: "delayed_jobs_priority"
38
+ add_index :delayed_jobs, [:queue], name: "delayed_jobs_queue"
37
39
  end
38
40
 
39
41
  def down
@@ -6,23 +6,18 @@ class CleanupDelayedJobsIndexes < ActiveRecord::Migration[4.2]
6
6
  end
7
7
 
8
8
  def up
9
- case connection.adapter_name
10
- when 'PostgreSQL'
11
- # "nulls first" syntax is postgresql specific, and allows for more
12
- # efficient querying for the next job
13
- connection.execute("CREATE INDEX get_delayed_jobs_index ON delayed_jobs (priority, run_at, failed_at nulls first, locked_at nulls first, queue)")
14
- else
15
- add_index :delayed_jobs, %w(priority run_at locked_at failed_at queue), :name => 'get_delayed_jobs_index'
16
- end
9
+ # "nulls first" syntax is postgresql specific, and allows for more
10
+ # efficient querying for the next job
11
+ connection.execute("CREATE INDEX get_delayed_jobs_index ON delayed_jobs (priority, run_at, failed_at nulls first, locked_at nulls first, queue)")
17
12
 
18
13
  # unused indexes
19
- remove_index :delayed_jobs, :name => 'delayed_jobs_queue'
20
- remove_index :delayed_jobs, :name => 'delayed_jobs_priority'
14
+ remove_index :delayed_jobs, name: "delayed_jobs_queue"
15
+ remove_index :delayed_jobs, name: "delayed_jobs_priority"
21
16
  end
22
17
 
23
18
  def down
24
- remove_index :delayed_jobs, :name => 'get_delayed_jobs_index'
25
- add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
26
- add_index :delayed_jobs, [:queue], :name => 'delayed_jobs_queue'
19
+ remove_index :delayed_jobs, name: "get_delayed_jobs_index"
20
+ add_index :delayed_jobs, %i[priority run_at], name: "delayed_jobs_priority"
21
+ add_index :delayed_jobs, [:queue], name: "delayed_jobs_queue"
27
22
  end
28
23
  end
@@ -7,10 +7,10 @@ class OptimizeDelayedJobs < ActiveRecord::Migration[4.2]
7
7
 
8
8
  def up
9
9
  create_table :failed_jobs do |t|
10
- t.integer "priority", :default => 0
11
- t.integer "attempts", :default => 0
12
- t.string "handler", :limit => 512000
13
- t.integer "original_id", :limit => 8
10
+ t.integer "priority", default: 0
11
+ t.integer "attempts", default: 0
12
+ t.string "handler", limit: 512_000
13
+ t.integer "original_id", limit: 8
14
14
  t.text "last_error"
15
15
  t.string "queue"
16
16
  t.datetime "run_at"
@@ -24,14 +24,14 @@ class OptimizeDelayedJobs < ActiveRecord::Migration[4.2]
24
24
  t.string "strand"
25
25
  end
26
26
 
27
- remove_index :delayed_jobs, :name => 'get_delayed_jobs_index'
27
+ remove_index :delayed_jobs, name: "get_delayed_jobs_index"
28
28
  remove_index :delayed_jobs, [:strand]
29
29
 
30
- add_index :delayed_jobs, %w(run_at queue locked_at strand priority), :name => 'index_delayed_jobs_for_get_next'
31
- add_index :delayed_jobs, %w(strand id), :name => 'index_delayed_jobs_on_strand'
30
+ add_index :delayed_jobs, %w[run_at queue locked_at strand priority], name: "index_delayed_jobs_for_get_next"
31
+ add_index :delayed_jobs, %w[strand id], name: "index_delayed_jobs_on_strand"
32
32
 
33
33
  # move all failed jobs to the new failed table
34
- Delayed::Backend::ActiveRecord::Job.where("failed_at IS NOT NULL").find_each do |job|
34
+ Delayed::Backend::ActiveRecord::Job.where.not(failed_at: nil).find_each do |job|
35
35
  job.fail! unless job.on_hold?
36
36
  end
37
37
  end
@@ -6,49 +6,49 @@ class AddDelayedJobsNextInStrand < ActiveRecord::Migration[4.2]
6
6
  end
7
7
 
8
8
  def up
9
- remove_index :delayed_jobs, :name => 'index_delayed_jobs_for_get_next'
9
+ remove_index :delayed_jobs, name: "index_delayed_jobs_for_get_next"
10
10
 
11
- add_column :delayed_jobs, :next_in_strand, :boolean, :default => true, :null => false
11
+ add_column :delayed_jobs, :next_in_strand, :boolean, default: true, null: false
12
12
 
13
13
  # create the new index
14
14
  connection.execute("CREATE INDEX get_delayed_jobs_index ON delayed_jobs (priority, run_at, queue) WHERE locked_at IS NULL AND next_in_strand = 't'")
15
15
 
16
16
  # create the insert trigger
17
- execute(<<-CODE)
18
- CREATE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
19
- BEGIN
20
- LOCK delayed_jobs IN SHARE ROW EXCLUSIVE MODE;
21
- IF (SELECT 1 FROM delayed_jobs WHERE strand = NEW.strand LIMIT 1) = 1 THEN
22
- NEW.next_in_strand := 'f';
23
- END IF;
24
- RETURN NEW;
25
- END;
26
- $$ LANGUAGE plpgsql;
27
- CODE
17
+ execute(<<~SQL)
18
+ CREATE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
19
+ BEGIN
20
+ LOCK delayed_jobs IN SHARE ROW EXCLUSIVE MODE;
21
+ IF (SELECT 1 FROM delayed_jobs WHERE strand = NEW.strand LIMIT 1) = 1 THEN
22
+ NEW.next_in_strand := 'f';
23
+ END IF;
24
+ RETURN NEW;
25
+ END;
26
+ $$ LANGUAGE plpgsql;
27
+ SQL
28
28
  execute("CREATE TRIGGER delayed_jobs_before_insert_row_tr BEFORE INSERT ON delayed_jobs FOR EACH ROW WHEN (NEW.strand IS NOT NULL) EXECUTE PROCEDURE delayed_jobs_before_insert_row_tr_fn()")
29
29
 
30
30
  # create the delete trigger
31
- execute(<<-CODE)
32
- CREATE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
33
- BEGIN
34
- UPDATE delayed_jobs SET next_in_strand = 't' WHERE id = (SELECT id FROM delayed_jobs j2 WHERE j2.strand = OLD.strand ORDER BY j2.strand, j2.id ASC LIMIT 1);
35
- RETURN OLD;
36
- END;
37
- $$ LANGUAGE plpgsql;
38
- CODE
31
+ execute(<<~SQL)
32
+ CREATE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
33
+ BEGIN
34
+ UPDATE delayed_jobs SET next_in_strand = 't' WHERE id = (SELECT id FROM delayed_jobs j2 WHERE j2.strand = OLD.strand ORDER BY j2.strand, j2.id ASC LIMIT 1);
35
+ RETURN OLD;
36
+ END;
37
+ $$ LANGUAGE plpgsql;
38
+ SQL
39
39
  execute("CREATE TRIGGER delayed_jobs_after_delete_row_tr AFTER DELETE ON delayed_jobs FOR EACH ROW WHEN (OLD.strand IS NOT NULL AND OLD.next_in_strand = 't') EXECUTE PROCEDURE delayed_jobs_after_delete_row_tr_fn()")
40
40
 
41
41
  execute(%{UPDATE delayed_jobs SET next_in_strand = 'f' WHERE strand IS NOT NULL AND id <> (SELECT id FROM delayed_jobs j2 WHERE j2.strand = delayed_jobs.strand ORDER BY j2.strand, j2.id ASC LIMIT 1)})
42
42
  end
43
43
 
44
44
  def down
45
- execute %{DROP TRIGGER delayed_jobs_before_insert_row_tr ON delayed_jobs}
45
+ execute %(DROP TRIGGER delayed_jobs_before_insert_row_tr ON delayed_jobs)
46
46
  execute %{DROP FUNCTION delayed_jobs_before_insert_row_tr_fn()}
47
- execute %{DROP TRIGGER delayed_jobs_after_delete_row_tr ON delayed_jobs}
47
+ execute %(DROP TRIGGER delayed_jobs_after_delete_row_tr ON delayed_jobs)
48
48
  execute %{DROP FUNCTION delayed_jobs_after_delete_row_tr_fn()}
49
49
 
50
50
  remove_column :delayed_jobs, :next_in_strand
51
- remove_index :delayed_jobs, :name => 'get_delayed_jobs_index'
52
- add_index :delayed_jobs, %w(run_at queue locked_at strand priority), :name => 'index_delayed_jobs_for_get_next'
51
+ remove_index :delayed_jobs, name: "get_delayed_jobs_index"
52
+ add_index :delayed_jobs, %w[run_at queue locked_at strand priority], name: "index_delayed_jobs_for_get_next"
53
53
  end
54
54
  end
@@ -6,28 +6,24 @@ class DelayedJobsDeleteTriggerLockForUpdate < ActiveRecord::Migration[4.2]
6
6
  end
7
7
 
8
8
  def up
9
- if connection.adapter_name == 'PostgreSQL'
10
- execute(<<-CODE)
9
+ execute(<<~SQL)
11
10
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
12
11
  BEGIN
13
12
  UPDATE delayed_jobs SET next_in_strand = 't' WHERE id = (SELECT id FROM delayed_jobs j2 WHERE j2.strand = OLD.strand ORDER BY j2.strand, j2.id ASC LIMIT 1 FOR UPDATE);
14
13
  RETURN OLD;
15
14
  END;
16
15
  $$ LANGUAGE plpgsql;
17
- CODE
18
- end
16
+ SQL
19
17
  end
20
18
 
21
19
  def down
22
- if connection.adapter_name == 'PostgreSQL'
23
- execute(<<-CODE)
20
+ execute(<<~SQL)
24
21
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
25
22
  BEGIN
26
23
  UPDATE delayed_jobs SET next_in_strand = 't' WHERE id = (SELECT id FROM delayed_jobs j2 WHERE j2.strand = OLD.strand ORDER BY j2.strand, j2.id ASC LIMIT 1);
27
24
  RETURN OLD;
28
25
  END;
29
26
  $$ LANGUAGE plpgsql;
30
- CODE
31
- end
27
+ SQL
32
28
  end
33
29
  end
@@ -6,9 +6,7 @@ class DropPsqlJobsPopFn < ActiveRecord::Migration[4.2]
6
6
  end
7
7
 
8
8
  def up
9
- if connection.adapter_name == 'PostgreSQL'
10
- connection.execute("DROP FUNCTION IF EXISTS pop_from_delayed_jobs(varchar, varchar, integer, integer, timestamp without time zone)")
11
- end
9
+ connection.execute("DROP FUNCTION IF EXISTS pop_from_delayed_jobs(varchar, varchar, integer, integer, timestamp without time zone)")
12
10
  end
13
11
 
14
12
  def down
@@ -10,8 +10,7 @@ class DelayedJobsUseAdvisoryLocks < ActiveRecord::Migration[4.2]
10
10
  # note that we're using half of the md5, so collisions are possible, but we don't really
11
11
  # care because that would just be the old behavior, whereas for the most part locking will
12
12
  # be much smaller
13
- if connection.adapter_name == 'PostgreSQL'
14
- execute(<<-CODE)
13
+ execute(<<~SQL)
15
14
  CREATE FUNCTION half_md5_as_bigint(strand varchar) RETURNS bigint AS $$
16
15
  DECLARE
17
16
  strand_md5 bytea;
@@ -27,9 +26,9 @@ class DelayedJobsUseAdvisoryLocks < ActiveRecord::Migration[4.2]
27
26
  get_byte(strand_md5, 7);
28
27
  END;
29
28
  $$ LANGUAGE plpgsql;
30
- CODE
29
+ SQL
31
30
 
32
- execute(<<-CODE)
31
+ execute(<<~SQL)
33
32
  CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
34
33
  BEGIN
35
34
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
@@ -39,9 +38,9 @@ class DelayedJobsUseAdvisoryLocks < ActiveRecord::Migration[4.2]
39
38
  RETURN NEW;
40
39
  END;
41
40
  $$ LANGUAGE plpgsql;
42
- CODE
41
+ SQL
43
42
 
44
- execute(<<-CODE)
43
+ execute(<<~SQL)
45
44
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
46
45
  BEGIN
47
46
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
@@ -49,13 +48,11 @@ class DelayedJobsUseAdvisoryLocks < ActiveRecord::Migration[4.2]
49
48
  RETURN OLD;
50
49
  END;
51
50
  $$ LANGUAGE plpgsql;
52
- CODE
53
- end
51
+ SQL
54
52
  end
55
53
 
56
54
  def down
57
- if connection.adapter_name == 'PostgreSQL'
58
- execute(<<-CODE)
55
+ execute(<<~SQL)
59
56
  CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
60
57
  BEGIN
61
58
  LOCK delayed_jobs IN SHARE ROW EXCLUSIVE MODE;
@@ -65,18 +62,17 @@ class DelayedJobsUseAdvisoryLocks < ActiveRecord::Migration[4.2]
65
62
  RETURN NEW;
66
63
  END;
67
64
  $$ LANGUAGE plpgsql;
68
- CODE
65
+ SQL
69
66
 
70
- execute(<<-CODE)
67
+ execute(<<~SQL)
71
68
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
72
69
  BEGIN
73
70
  UPDATE delayed_jobs SET next_in_strand = 't' WHERE id = (SELECT id FROM delayed_jobs j2 WHERE j2.strand = OLD.strand ORDER BY j2.strand, j2.id ASC LIMIT 1 FOR UPDATE);
74
71
  RETURN OLD;
75
72
  END;
76
73
  $$ LANGUAGE plpgsql;
77
- CODE
74
+ SQL
78
75
 
79
- execute('DROP FUNCTION half_md5_as_bigint(varchar)')
80
- end
76
+ execute("DROP FUNCTION half_md5_as_bigint(varchar)")
81
77
  end
82
78
  end
@@ -8,7 +8,7 @@ class IndexJobsOnLockedBy < ActiveRecord::Migration[4.2]
8
8
  end
9
9
 
10
10
  def up
11
- add_index :delayed_jobs, :locked_by, :algorithm => :concurrently, :where => "locked_by IS NOT NULL"
11
+ add_index :delayed_jobs, :locked_by, algorithm: :concurrently, where: "locked_by IS NOT NULL"
12
12
  end
13
13
 
14
14
  def down
@@ -8,10 +8,10 @@ class AddJobsRunAtIndex < ActiveRecord::Migration[4.2]
8
8
  end
9
9
 
10
10
  def up
11
- add_index :delayed_jobs, %w[run_at tag], :algorithm => :concurrently
11
+ add_index :delayed_jobs, %w[run_at tag], algorithm: :concurrently
12
12
  end
13
13
 
14
14
  def down
15
- remove_index :delayed_jobs, :name => "index_delayed_jobs_on_run_at_and_tag"
15
+ remove_index :delayed_jobs, name: "index_delayed_jobs_on_run_at_and_tag"
16
16
  end
17
17
  end
@@ -10,6 +10,6 @@ class ChangeDelayedJobsHandlerToText < ActiveRecord::Migration[4.2]
10
10
  end
11
11
 
12
12
  def down
13
- change_column :delayed_jobs, :handler, :string, :limit => 500.kilobytes
13
+ change_column :delayed_jobs, :handler, :string, limit: 500.kilobytes
14
14
  end
15
15
  end
@@ -7,9 +7,8 @@ class CopyFailedJobsOriginalId < ActiveRecord::Migration[4.2]
7
7
 
8
8
  def up
9
9
  # this is a smaller, less frequently accessed table, so we just update all at once
10
- Delayed::Backend::ActiveRecord::Job::Failed.where("original_job_id is null").update_all("original_job_id = original_id")
10
+ Delayed::Backend::ActiveRecord::Job::Failed.where(original_job_id: nil).update_all("original_job_id = original_id")
11
11
  end
12
12
 
13
- def down
14
- end
13
+ def down; end
15
14
  end
@@ -6,10 +6,9 @@ class AddMaxConcurrentToJobs < ActiveRecord::Migration[4.2]
6
6
  end
7
7
 
8
8
  def up
9
- add_column :delayed_jobs, :max_concurrent, :integer, :default => 1, :null => false
9
+ add_column :delayed_jobs, :max_concurrent, :integer, default: 1, null: false
10
10
 
11
- if connection.adapter_name == 'PostgreSQL'
12
- execute(<<-CODE)
11
+ execute(<<~SQL)
13
12
  CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
14
13
  BEGIN
15
14
  IF NEW.strand IS NOT NULL THEN
@@ -21,9 +20,9 @@ class AddMaxConcurrentToJobs < ActiveRecord::Migration[4.2]
21
20
  RETURN NEW;
22
21
  END;
23
22
  $$ LANGUAGE plpgsql;
24
- CODE
23
+ SQL
25
24
 
26
- execute(<<-CODE)
25
+ execute(<<~SQL)
27
26
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
28
27
  BEGIN
29
28
  IF OLD.strand IS NOT NULL THEN
@@ -38,15 +37,13 @@ class AddMaxConcurrentToJobs < ActiveRecord::Migration[4.2]
38
37
  RETURN OLD;
39
38
  END;
40
39
  $$ LANGUAGE plpgsql;
41
- CODE
42
- end
40
+ SQL
43
41
  end
44
42
 
45
43
  def down
46
44
  remove_column :delayed_jobs, :max_concurrent
47
45
 
48
- if connection.adapter_name == 'PostgreSQL'
49
- execute(<<-CODE)
46
+ execute(<<~SQL)
50
47
  CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
51
48
  BEGIN
52
49
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
@@ -56,9 +53,9 @@ class AddMaxConcurrentToJobs < ActiveRecord::Migration[4.2]
56
53
  RETURN NEW;
57
54
  END;
58
55
  $$ LANGUAGE plpgsql;
59
- CODE
56
+ SQL
60
57
 
61
- execute(<<-CODE)
58
+ execute(<<~SQL)
62
59
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
63
60
  BEGIN
64
61
  PERFORM pg_advisory_xact_lock(half_md5_as_bigint(OLD.strand));
@@ -66,7 +63,6 @@ class AddMaxConcurrentToJobs < ActiveRecord::Migration[4.2]
66
63
  RETURN OLD;
67
64
  END;
68
65
  $$ LANGUAGE plpgsql;
69
- CODE
70
- end
66
+ SQL
71
67
  end
72
68
  end
@@ -6,8 +6,7 @@ class ImproveMaxConcurrent < ActiveRecord::Migration[4.2]
6
6
  end
7
7
 
8
8
  def up
9
- if connection.adapter_name == 'PostgreSQL'
10
- execute(<<-CODE)
9
+ execute(<<~SQL)
11
10
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
12
11
  DECLARE
13
12
  running_count integer;
@@ -25,13 +24,11 @@ class ImproveMaxConcurrent < ActiveRecord::Migration[4.2]
25
24
  RETURN OLD;
26
25
  END;
27
26
  $$ LANGUAGE plpgsql;
28
- CODE
29
- end
27
+ SQL
30
28
  end
31
29
 
32
30
  def down
33
- if connection.adapter_name == 'PostgreSQL'
34
- execute(<<-CODE)
31
+ execute(<<~SQL)
35
32
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
36
33
  BEGIN
37
34
  IF OLD.strand IS NOT NULL THEN
@@ -46,7 +43,6 @@ class ImproveMaxConcurrent < ActiveRecord::Migration[4.2]
46
43
  RETURN OLD;
47
44
  END;
48
45
  $$ LANGUAGE plpgsql;
49
- CODE
50
- end
46
+ SQL
51
47
  end
52
48
  end
@@ -24,8 +24,8 @@ class AddBackDefaultStringLimitsJobs < ActiveRecord::Migration[4.2]
24
24
  end
25
25
 
26
26
  def drop_triggers
27
- execute %{DROP TRIGGER delayed_jobs_before_insert_row_tr ON delayed_jobs}
28
- execute %{DROP TRIGGER delayed_jobs_after_delete_row_tr ON delayed_jobs}
27
+ execute %(DROP TRIGGER delayed_jobs_before_insert_row_tr ON delayed_jobs)
28
+ execute %(DROP TRIGGER delayed_jobs_after_delete_row_tr ON delayed_jobs)
29
29
  end
30
30
 
31
31
  def readd_triggers
@@ -35,6 +35,7 @@ class AddBackDefaultStringLimitsJobs < ActiveRecord::Migration[4.2]
35
35
 
36
36
  def add_string_limit_if_missing(table, column)
37
37
  return if column_exists?(table, column, :string, limit: 255)
38
+
38
39
  change_column table, column, :string, limit: 255
39
40
  end
40
41
  end
@@ -1,16 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
3
+ class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
4
4
  def connection
5
5
  Delayed::Job.connection
6
6
  end
7
7
 
8
8
  def up
9
- if connection.adapter_name == 'PostgreSQL'
10
- # tl;dr sacrifice some responsiveness to max_concurrent changes for faster performance
11
- # don't get the count every single time - it's usually safe to just set the next one in line
12
- # since the max_concurrent doesn't change all that often for a strand
13
- execute(<<-CODE)
9
+ # tl;dr sacrifice some responsiveness to max_concurrent changes for faster performance
10
+ # don't get the count every single time - it's usually safe to just set the next one in line
11
+ # since the max_concurrent doesn't change all that often for a strand
12
+ execute(<<~SQL)
14
13
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
15
14
  DECLARE
16
15
  running_count integer;
@@ -36,10 +35,10 @@ class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
36
35
  RETURN OLD;
37
36
  END;
38
37
  $$ LANGUAGE plpgsql;
39
- CODE
38
+ SQL
40
39
 
41
- # don't need the full count on insert
42
- execute(<<-CODE)
40
+ # don't need the full count on insert
41
+ execute(<<~SQL)
43
42
  CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
44
43
  BEGIN
45
44
  IF NEW.strand IS NOT NULL THEN
@@ -53,13 +52,11 @@ class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
53
52
  RETURN NEW;
54
53
  END;
55
54
  $$ LANGUAGE plpgsql;
56
- CODE
57
- end
55
+ SQL
58
56
  end
59
57
 
60
58
  def down
61
- if connection.adapter_name == 'PostgreSQL'
62
- execute(<<-CODE)
59
+ execute(<<~SQL)
63
60
  CREATE OR REPLACE FUNCTION delayed_jobs_after_delete_row_tr_fn () RETURNS trigger AS $$
64
61
  DECLARE
65
62
  running_count integer;
@@ -77,9 +74,9 @@ class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
77
74
  RETURN OLD;
78
75
  END;
79
76
  $$ LANGUAGE plpgsql;
80
- CODE
77
+ SQL
81
78
 
82
- execute(<<-CODE)
79
+ execute(<<~SQL)
83
80
  CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
84
81
  BEGIN
85
82
  IF NEW.strand IS NOT NULL THEN
@@ -91,7 +88,6 @@ class SpeedUpMaxConcurrentTriggers < ActiveRecord::Migration[4.2]
91
88
  RETURN NEW;
92
89
  END;
93
90
  $$ LANGUAGE plpgsql;
94
- CODE
95
- end
91
+ SQL
96
92
  end
97
93
  end
@@ -9,19 +9,19 @@ class AddIdToGetDelayedJobsIndex < ActiveRecord::Migration[4.2]
9
9
 
10
10
  def up
11
11
  rename_index :delayed_jobs, "get_delayed_jobs_index", "get_delayed_jobs_index_old"
12
- add_index :delayed_jobs, [:queue, :priority, :run_at, :id],
13
- algorithm: :concurrently,
14
- where: "locked_at IS NULL AND next_in_strand",
15
- name: "get_delayed_jobs_index"
12
+ add_index :delayed_jobs, %i[queue priority run_at id],
13
+ algorithm: :concurrently,
14
+ where: "locked_at IS NULL AND next_in_strand",
15
+ name: "get_delayed_jobs_index"
16
16
  remove_index :delayed_jobs, name: "get_delayed_jobs_index_old"
17
17
  end
18
18
 
19
19
  def down
20
20
  rename_index :delayed_jobs, "get_delayed_jobs_index", "get_delayed_jobs_index_old"
21
- add_index :delayed_jobs, [:priority, :run_at, :queue],
22
- algorithm: :concurrently,
23
- where: "locked_at IS NULL AND next_in_strand",
24
- name: "get_delayed_jobs_index"
21
+ add_index :delayed_jobs, %i[priority run_at queue],
22
+ algorithm: :concurrently,
23
+ where: "locked_at IS NULL AND next_in_strand",
24
+ name: "get_delayed_jobs_index"
25
25
  remove_index :delayed_jobs, name: "get_delayed_jobs_index_old"
26
26
  end
27
27
  end