inst-jobs 2.3.3 → 2.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) 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 +3 -3
  21. data/db/migrate/20210812210128_add_singleton_column.rb +200 -0
  22. data/exe/inst_jobs +3 -2
  23. data/lib/delayed/backend/active_record.rb +183 -149
  24. data/lib/delayed/backend/base.rb +80 -75
  25. data/lib/delayed/batch.rb +11 -9
  26. data/lib/delayed/cli.rb +98 -84
  27. data/lib/delayed/core_ext/kernel.rb +4 -2
  28. data/lib/delayed/daemon.rb +70 -74
  29. data/lib/delayed/job_tracking.rb +26 -25
  30. data/lib/delayed/lifecycle.rb +27 -24
  31. data/lib/delayed/log_tailer.rb +17 -17
  32. data/lib/delayed/logging.rb +13 -16
  33. data/lib/delayed/message_sending.rb +43 -52
  34. data/lib/delayed/performable_method.rb +6 -8
  35. data/lib/delayed/periodic.rb +66 -65
  36. data/lib/delayed/plugin.rb +2 -4
  37. data/lib/delayed/pool.rb +198 -193
  38. data/lib/delayed/server/helpers.rb +6 -6
  39. data/lib/delayed/server.rb +51 -54
  40. data/lib/delayed/settings.rb +93 -81
  41. data/lib/delayed/testing.rb +21 -22
  42. data/lib/delayed/version.rb +1 -1
  43. data/lib/delayed/work_queue/in_process.rb +21 -18
  44. data/lib/delayed/work_queue/parent_process/client.rb +54 -55
  45. data/lib/delayed/work_queue/parent_process/server.rb +215 -209
  46. data/lib/delayed/work_queue/parent_process.rb +52 -53
  47. data/lib/delayed/worker/consul_health_check.rb +21 -19
  48. data/lib/delayed/worker/health_check.rb +21 -12
  49. data/lib/delayed/worker/null_health_check.rb +3 -1
  50. data/lib/delayed/worker/process_helper.rb +8 -9
  51. data/lib/delayed/worker.rb +271 -265
  52. data/lib/delayed/yaml_extensions.rb +12 -10
  53. data/lib/delayed_job.rb +37 -38
  54. data/lib/inst-jobs.rb +1 -1
  55. data/spec/active_record_job_spec.rb +129 -136
  56. data/spec/delayed/cli_spec.rb +7 -7
  57. data/spec/delayed/daemon_spec.rb +8 -8
  58. data/spec/delayed/message_sending_spec.rb +16 -9
  59. data/spec/delayed/periodic_spec.rb +13 -12
  60. data/spec/delayed/server_spec.rb +38 -38
  61. data/spec/delayed/settings_spec.rb +26 -25
  62. data/spec/delayed/work_queue/in_process_spec.rb +7 -7
  63. data/spec/delayed/work_queue/parent_process/client_spec.rb +15 -11
  64. data/spec/delayed/work_queue/parent_process/server_spec.rb +43 -40
  65. data/spec/delayed/work_queue/parent_process_spec.rb +21 -21
  66. data/spec/delayed/worker/consul_health_check_spec.rb +22 -22
  67. data/spec/delayed/worker/health_check_spec.rb +51 -49
  68. data/spec/delayed/worker_spec.rb +28 -25
  69. data/spec/sample_jobs.rb +45 -15
  70. data/spec/shared/delayed_batch.rb +74 -67
  71. data/spec/shared/delayed_method.rb +143 -102
  72. data/spec/shared/performable_method.rb +39 -38
  73. data/spec/shared/shared_backend.rb +534 -441
  74. data/spec/shared/testing.rb +14 -14
  75. data/spec/shared/worker.rb +155 -147
  76. data/spec/shared_jobs_specs.rb +13 -13
  77. data/spec/spec_helper.rb +43 -40
  78. metadata +81 -59
  79. data/lib/delayed/backend/redis/bulk_update.lua +0 -50
  80. data/lib/delayed/backend/redis/destroy_job.lua +0 -2
  81. data/lib/delayed/backend/redis/enqueue.lua +0 -29
  82. data/lib/delayed/backend/redis/fail_job.lua +0 -5
  83. data/lib/delayed/backend/redis/find_available.lua +0 -3
  84. data/lib/delayed/backend/redis/functions.rb +0 -59
  85. data/lib/delayed/backend/redis/get_and_lock_next_available.lua +0 -17
  86. data/lib/delayed/backend/redis/includes/jobs_common.lua +0 -203
  87. data/lib/delayed/backend/redis/job.rb +0 -528
  88. data/lib/delayed/backend/redis/set_running.lua +0 -5
  89. data/lib/delayed/backend/redis/tickle_strand.lua +0 -2
  90. data/spec/gemfiles/52.gemfile +0 -7
  91. data/spec/gemfiles/60.gemfile +0 -7
  92. data/spec/gemfiles/60.gemfile.lock +0 -246
  93. data/spec/gemfiles/61.gemfile +0 -7
  94. data/spec/redis_job_spec.rb +0 -148
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbfecef485b9884f4504d62b6e4d51345b1c729ae109e5dc619eeb5091dd9d22
4
- data.tar.gz: e6bd8e6efe0f4a15d77645fe0f4f6b2bd5c2d13be723fba7a42ae72768c834ae
3
+ metadata.gz: 7a5cde929174dd49e07d06025310bcea4cb0a6b55b3d83a40ea7b7bde9c9b775
4
+ data.tar.gz: 1028828aa017afc111c89f410425a58939c42697066279b7a22174463384d1f1
5
5
  SHA512:
6
- metadata.gz: 8931e016e05ac54872c3053990402cb85818b53f031eeb0c0118f581a2f3cca73dda2613b99316b1b3bb37fa840b1401b73f02bf307700042f4dc451d2b14067
7
- data.tar.gz: f301f6495d9854c0e8a53dfd22dd0e8db44994dda66aa22cbf920a7a18adf52170d523578ccd0f5a83971521a556074c270d531d626e216f1cf8af7e7bb0cae5
6
+ metadata.gz: ba08cb3d2e9ff3a72bdaf8c47d9265cc21a7bfd401b1657349c12043852955ac3c7e02d52c1ef1ab602207cbcc35e48e7293c77fceb34f12aec660d9e9638a7f
7
+ data.tar.gz: d86f8ead17b6ddc679350dc9b9e5ee52a2ffc5b8ad62be52e5f375a28e0ccd9b9a1a6aad5255e08273a26fa9ed0d90a31afd618caee5e0378adf5481494bdc78
@@ -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