inst-jobs 2.4.8 → 2.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b810ed7504a4de6c0338c2b6f0b2303e72e172225ca57d8ed3ebf8a9f05c6111
4
- data.tar.gz: 7fff2151aa908f846af19401a39390beee21ca2fdd9b9317425fdcf0345970fb
3
+ metadata.gz: 8e17453e7b2cfd39920dfb36c615bcd813ecf3416985e405e26d5062716ccaa7
4
+ data.tar.gz: 17ad240a2304ca6ee648308199ac8d83d53498ee93cd130bf3cbd86dde729673
5
5
  SHA512:
6
- metadata.gz: 1a98557f9c875df6e9961b849dd8d6fec4564e247eed2d68a717dbaef94ed5af4b2a61642c0c17a4bf7f1eaac102b9607a2da5b4fb9b2c40ef3cca2b6bafcef5
7
- data.tar.gz: 1fcaa3bc4d1191d2a8d56156e40755d032f635dcaef7f05fbaf19d197b6456d552578ae7fcf376d4fe90ab70c3406a81d8d959ff87b714b669defccb8d9b04d0
6
+ metadata.gz: 29ed31003455122f52a8f45ac22751acf3f71213e4f93fae280425d90f5a35919ef881220660c453469904cec107383d0764afa0d87458da3b4fdded272c5c78
7
+ data.tar.gz: a9cb6ff603ad8c683b326cebfdb24acef31a450f3e6fab88af3760adf8f726e4c4dc28797bbcb7bb5e38b0f2fef0af97ee3c145a8031db723e5c67bb9c94d385
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FixSingletonConditionInBeforeInsert < ActiveRecord::Migration[5.2]
4
+ def change
5
+ reversible do |direction|
6
+ direction.up do
7
+ execute(<<~SQL)
8
+ CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
9
+ BEGIN
10
+ IF NEW.strand IS NOT NULL THEN
11
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
12
+ IF (SELECT COUNT(*) FROM (
13
+ SELECT 1 FROM delayed_jobs WHERE strand = NEW.strand AND next_in_strand=true LIMIT NEW.max_concurrent
14
+ ) s) = NEW.max_concurrent THEN
15
+ NEW.next_in_strand := false;
16
+ END IF;
17
+ END IF;
18
+ IF NEW.singleton IS NOT NULL THEN
19
+ -- this condition seems silly, but it forces postgres to use the two partial indexes on singleton,
20
+ -- rather than doing a seq scan
21
+ PERFORM 1 FROM delayed_jobs WHERE singleton = NEW.singleton AND (locked_by IS NULL OR locked_by IS NOT NULL);
22
+ IF FOUND THEN
23
+ NEW.next_in_strand := false;
24
+ END IF;
25
+ END IF;
26
+ RETURN NEW;
27
+ END;
28
+ $$ LANGUAGE plpgsql;
29
+ SQL
30
+ end
31
+ direction.down do
32
+ execute(<<~SQL)
33
+ CREATE OR REPLACE FUNCTION delayed_jobs_before_insert_row_tr_fn () RETURNS trigger AS $$
34
+ BEGIN
35
+ IF NEW.strand IS NOT NULL THEN
36
+ PERFORM pg_advisory_xact_lock(half_md5_as_bigint(NEW.strand));
37
+ IF (SELECT COUNT(*) FROM (
38
+ SELECT 1 FROM delayed_jobs WHERE strand = NEW.strand AND next_in_strand=true LIMIT NEW.max_concurrent
39
+ ) s) = NEW.max_concurrent THEN
40
+ NEW.next_in_strand := false;
41
+ END IF;
42
+ END IF;
43
+ IF NEW.singleton IS NOT NULL THEN
44
+ PERFORM 1 FROM delayed_jobs WHERE singleton = NEW.singleton;
45
+ IF FOUND THEN
46
+ NEW.next_in_strand := false;
47
+ END IF;
48
+ END IF;
49
+ RETURN NEW;
50
+ END;
51
+ $$ LANGUAGE plpgsql;
52
+ SQL
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "2.4.8"
4
+ VERSION = "2.4.9"
5
5
  end
@@ -31,8 +31,8 @@ describe "Delayed::Backed::ActiveRecord::Job" do
31
31
  expect(@job_copy_for_worker2.send(:lock_exclusively!, "worker2")).to eq(false)
32
32
  end
33
33
 
34
- it "doesn't allow a second worker to get exclusive access if failed to be processed by worker1 and
35
- run_at time is now in future (due to backing off behaviour)" do
34
+ it "doesn't allow a second worker to get exclusive access if failed to be " \
35
+ "processed by worker1 and run_at time is now in future (due to backing off behaviour)" do
36
36
  @job.update(attempts: 1, run_at: 1.day.from_now)
37
37
  expect(@job_copy_for_worker2.send(:lock_exclusively!, "worker2")).to eq(false)
38
38
  end
@@ -3,9 +3,10 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe Delayed::Daemon do
6
+ subject { described_class.new(pid_folder) }
7
+
6
8
  let(:pid_folder) { "/test/pid/folder" }
7
9
  let(:pid) { 9999 }
8
- let(:subject) { described_class.new(pid_folder) }
9
10
 
10
11
  before do
11
12
  allow(subject).to receive(:pid).and_return(pid)
@@ -11,7 +11,6 @@ RSpec.describe Delayed::WorkQueue::InProcess do
11
11
  Delayed::Worker.lifecycle.reset!
12
12
  end
13
13
 
14
- let(:subject) { described_class.new }
15
14
  let(:worker_config) { { queue: "test", min_priority: 1, max_priority: 2 } }
16
15
  let(:args) { ["worker_name", worker_config] }
17
16
 
@@ -3,7 +3,8 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
6
- let(:subject) { described_class.new(addrinfo).tap(&:init) }
6
+ subject { described_class.new(addrinfo).tap(&:init) }
7
+
7
8
  let(:addrinfo) { double("Addrinfo") }
8
9
  let(:connection) { double("Socket") }
9
10
  let(:job) { Delayed::Job.new(locked_by: "worker_name") }
@@ -15,8 +15,9 @@ class JobClass
15
15
  end
16
16
 
17
17
  RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
18
+ subject { described_class.new(listen_socket) }
19
+
18
20
  let(:parent) { Delayed::WorkQueue::ParentProcess.new }
19
- let(:subject) { described_class.new(listen_socket) }
20
21
  let(:listen_socket) { Socket.unix_server_socket(parent.server_address) }
21
22
  let(:job) { JobClass.new }
22
23
  let(:worker_config) { { queue: "queue_name", min_priority: 1, max_priority: 2 } }
@@ -21,8 +21,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
21
21
  Delayed::Worker.lifecycle.reset!
22
22
  end
23
23
 
24
- let(:subject) { described_class.new }
25
-
26
24
  describe "#initalize(config = Settings.parent_process)" do
27
25
  it "must expand a relative path to be within the Rails root" do
28
26
  queue = described_class.new("server_address" => "tmp/foo.sock")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.8
4
+ version: 2.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-09-21 00:00:00.000000000 Z
12
+ date: 2021-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -432,6 +432,7 @@ files:
432
432
  - db/migrate/20210809145804_add_n_strand_index.rb
433
433
  - db/migrate/20210812210128_add_singleton_column.rb
434
434
  - db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb
435
+ - db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb
435
436
  - exe/inst_jobs
436
437
  - lib/delayed/backend/active_record.rb
437
438
  - lib/delayed/backend/base.rb