inst-jobs 2.3.3 → 2.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20101216224513_create_delayed_jobs.rb +9 -7
- data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +8 -13
- data/db/migrate/20110610213249_optimize_delayed_jobs.rb +8 -8
- data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +25 -25
- data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +4 -8
- data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +1 -3
- data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +11 -15
- data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +1 -1
- data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -2
- data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +1 -1
- data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -3
- data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +9 -13
- data/db/migrate/20151210162949_improve_max_concurrent.rb +4 -8
- data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +3 -2
- data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +13 -17
- data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +8 -8
- data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +72 -77
- data/db/migrate/20200825011002_add_strand_order_override.rb +93 -97
- data/db/migrate/20210809145804_add_n_strand_index.rb +3 -3
- data/db/migrate/20210812210128_add_singleton_column.rb +200 -0
- data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +27 -0
- data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +56 -0
- data/exe/inst_jobs +3 -2
- data/lib/delayed/backend/active_record.rb +204 -150
- data/lib/delayed/backend/base.rb +106 -82
- data/lib/delayed/batch.rb +11 -9
- data/lib/delayed/cli.rb +98 -84
- data/lib/delayed/core_ext/kernel.rb +4 -2
- data/lib/delayed/daemon.rb +70 -74
- data/lib/delayed/job_tracking.rb +26 -25
- data/lib/delayed/lifecycle.rb +27 -24
- data/lib/delayed/log_tailer.rb +17 -17
- data/lib/delayed/logging.rb +13 -16
- data/lib/delayed/message_sending.rb +43 -52
- data/lib/delayed/performable_method.rb +6 -8
- data/lib/delayed/periodic.rb +72 -65
- data/lib/delayed/plugin.rb +2 -4
- data/lib/delayed/pool.rb +198 -193
- data/lib/delayed/server/helpers.rb +6 -6
- data/lib/delayed/server.rb +51 -54
- data/lib/delayed/settings.rb +93 -81
- data/lib/delayed/testing.rb +21 -22
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/work_queue/in_process.rb +21 -18
- data/lib/delayed/work_queue/parent_process/client.rb +54 -55
- data/lib/delayed/work_queue/parent_process/server.rb +219 -208
- data/lib/delayed/work_queue/parent_process.rb +52 -53
- data/lib/delayed/worker/consul_health_check.rb +21 -19
- data/lib/delayed/worker/health_check.rb +29 -22
- data/lib/delayed/worker/null_health_check.rb +3 -1
- data/lib/delayed/worker/process_helper.rb +8 -9
- data/lib/delayed/worker.rb +271 -265
- data/lib/delayed/yaml_extensions.rb +12 -10
- data/lib/delayed_job.rb +37 -38
- data/lib/inst-jobs.rb +1 -1
- data/spec/active_record_job_spec.rb +129 -136
- data/spec/delayed/cli_spec.rb +7 -7
- data/spec/delayed/daemon_spec.rb +10 -9
- data/spec/delayed/message_sending_spec.rb +16 -9
- data/spec/delayed/periodic_spec.rb +13 -12
- data/spec/delayed/server_spec.rb +38 -38
- data/spec/delayed/settings_spec.rb +26 -25
- data/spec/delayed/work_queue/in_process_spec.rb +7 -8
- data/spec/delayed/work_queue/parent_process/client_spec.rb +17 -12
- data/spec/delayed/work_queue/parent_process/server_spec.rb +70 -41
- data/spec/delayed/work_queue/parent_process_spec.rb +21 -23
- data/spec/delayed/worker/consul_health_check_spec.rb +22 -22
- data/spec/delayed/worker/health_check_spec.rb +60 -52
- data/spec/delayed/worker_spec.rb +28 -25
- data/spec/sample_jobs.rb +45 -15
- data/spec/shared/delayed_batch.rb +74 -67
- data/spec/shared/delayed_method.rb +143 -102
- data/spec/shared/performable_method.rb +39 -38
- data/spec/shared/shared_backend.rb +547 -441
- data/spec/shared/testing.rb +14 -14
- data/spec/shared/worker.rb +155 -147
- data/spec/shared_jobs_specs.rb +13 -13
- data/spec/spec_helper.rb +46 -41
- metadata +79 -55
- data/lib/delayed/backend/redis/bulk_update.lua +0 -50
- data/lib/delayed/backend/redis/destroy_job.lua +0 -2
- data/lib/delayed/backend/redis/enqueue.lua +0 -29
- data/lib/delayed/backend/redis/fail_job.lua +0 -5
- data/lib/delayed/backend/redis/find_available.lua +0 -3
- data/lib/delayed/backend/redis/functions.rb +0 -59
- data/lib/delayed/backend/redis/get_and_lock_next_available.lua +0 -17
- data/lib/delayed/backend/redis/includes/jobs_common.lua +0 -203
- data/lib/delayed/backend/redis/job.rb +0 -528
- data/lib/delayed/backend/redis/set_running.lua +0 -5
- data/lib/delayed/backend/redis/tickle_strand.lua +0 -2
- data/spec/gemfiles/52.gemfile +0 -7
- data/spec/gemfiles/60.gemfile +0 -7
- data/spec/gemfiles/60.gemfile.lock +0 -246
- data/spec/gemfiles/61.gemfile +0 -7
- data/spec/redis_job_spec.rb +0 -148
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 207f92edc1bf044fe040fac47e1eb3eff01d8d11ff66f3a5fa3ff3429ffca748
|
4
|
+
data.tar.gz: 0aa8bb0e7c81fe22eca78171b6827ba84f325e2981cda075691072f4305a355d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9278910b958ca2854c7b3d5e10a0b3911ee14938067897abb166929db2888f8577d8507622e372b12a5e5db53fbb09d50d5bdcea591364ca5b40ab7a46d1a27
|
7
|
+
data.tar.gz: 9b4b76b471d442e102a217d16d426dc0eed0e3e2a9bded47cc5d8505806264f189629cea337d084f0300398b96c52f9036a6670aa4b5ef426fff9f56775001a0
|
@@ -6,19 +6,21 @@ class CreateDelayedJobs < ActiveRecord::Migration[4.2]
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def up
|
9
|
-
|
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, :
|
15
|
+
table.integer :priority, default: 0
|
14
16
|
# Provides for retries, but still fail eventually.
|
15
|
-
table.integer :attempts, :
|
17
|
+
table.integer :attempts, default: 0
|
16
18
|
# YAML-encoded string of the object that will do work
|
17
|
-
table.text :handler, :
|
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, :
|
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, [
|
36
|
-
add_index :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
|
-
|
10
|
-
|
11
|
-
|
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, :
|
20
|
-
remove_index :delayed_jobs, :
|
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, :
|
25
|
-
add_index :delayed_jobs, [
|
26
|
-
add_index :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", :
|
11
|
-
t.integer "attempts", :
|
12
|
-
t.string "handler", :
|
13
|
-
t.integer "original_id", :
|
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, :
|
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
|
31
|
-
add_index :delayed_jobs, %w
|
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(
|
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, :
|
9
|
+
remove_index :delayed_jobs, name: "index_delayed_jobs_for_get_next"
|
10
10
|
|
11
|
-
add_column :delayed_jobs, :next_in_strand, :boolean, :
|
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(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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 %
|
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 %
|
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, :
|
52
|
-
add_index :delayed_jobs, %w
|
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
|
-
|
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
|
-
|
18
|
-
end
|
16
|
+
SQL
|
19
17
|
end
|
20
18
|
|
21
19
|
def down
|
22
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
29
|
+
SQL
|
31
30
|
|
32
|
-
|
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
|
-
|
41
|
+
SQL
|
43
42
|
|
44
|
-
|
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
|
-
|
53
|
-
end
|
51
|
+
SQL
|
54
52
|
end
|
55
53
|
|
56
54
|
def down
|
57
|
-
|
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
|
-
|
65
|
+
SQL
|
69
66
|
|
70
|
-
|
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
|
-
|
74
|
+
SQL
|
78
75
|
|
79
|
-
|
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, :
|
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], :
|
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, :
|
15
|
+
remove_index :delayed_jobs, name: "index_delayed_jobs_on_run_at_and_tag"
|
16
16
|
end
|
17
17
|
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(
|
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, :
|
9
|
+
add_column :delayed_jobs, :max_concurrent, :integer, default: 1, null: false
|
10
10
|
|
11
|
-
|
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
|
-
|
23
|
+
SQL
|
25
24
|
|
26
|
-
|
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
|
-
|
42
|
-
end
|
40
|
+
SQL
|
43
41
|
end
|
44
42
|
|
45
43
|
def down
|
46
44
|
remove_column :delayed_jobs, :max_concurrent
|
47
45
|
|
48
|
-
|
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
|
-
|
56
|
+
SQL
|
60
57
|
|
61
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
29
|
-
end
|
27
|
+
SQL
|
30
28
|
end
|
31
29
|
|
32
30
|
def down
|
33
|
-
|
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
|
-
|
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 %
|
28
|
-
execute %
|
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
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
38
|
+
SQL
|
40
39
|
|
41
|
-
|
42
|
-
|
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
|
-
|
57
|
-
end
|
55
|
+
SQL
|
58
56
|
end
|
59
57
|
|
60
58
|
def down
|
61
|
-
|
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
|
-
|
77
|
+
SQL
|
81
78
|
|
82
|
-
|
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
|
-
|
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, [
|
13
|
-
|
14
|
-
|
15
|
-
|
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, [
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|