inst-jobs 0.15.20 → 1.0.1
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 +2 -0
- data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +2 -0
- data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +2 -0
- data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +2 -0
- data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +2 -0
- data/db/migrate/20110610213249_optimize_delayed_jobs.rb +2 -0
- data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +2 -0
- data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +2 -0
- data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +2 -0
- data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +2 -0
- data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +2 -0
- data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -0
- data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +2 -0
- data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +2 -0
- data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -0
- data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +2 -0
- data/db/migrate/20140512213941_add_source_to_jobs.rb +2 -0
- data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +2 -0
- data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +2 -0
- data/db/migrate/20151210162949_improve_max_concurrent.rb +2 -0
- data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +2 -0
- data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +2 -0
- data/db/migrate/20190726154743_make_critical_columns_not_null.rb +2 -0
- data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +2 -0
- data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +97 -0
- data/db/migrate/20200825011002_add_strand_order_override.rb +128 -0
- data/lib/delayed/backend/active_record.rb +17 -7
- data/lib/delayed/backend/base.rb +34 -20
- data/lib/delayed/backend/redis/functions.rb +2 -0
- data/lib/delayed/backend/redis/job.rb +2 -0
- data/lib/delayed/batch.rb +5 -3
- data/lib/delayed/cli.rb +2 -0
- data/lib/delayed/core_ext/kernel.rb +9 -0
- data/lib/delayed/daemon.rb +2 -0
- data/lib/delayed/engine.rb +2 -0
- data/lib/delayed/job_tracking.rb +2 -0
- data/lib/delayed/lifecycle.rb +2 -0
- data/lib/delayed/log_tailer.rb +2 -0
- data/lib/delayed/logging.rb +2 -0
- data/lib/delayed/message_sending.rb +79 -104
- data/lib/delayed/performable_method.rb +24 -6
- data/lib/delayed/periodic.rb +6 -4
- data/lib/delayed/plugin.rb +2 -0
- data/lib/delayed/pool.rb +2 -0
- data/lib/delayed/server.rb +2 -0
- data/lib/delayed/server/helpers.rb +2 -0
- data/lib/delayed/settings.rb +7 -1
- data/lib/delayed/testing.rb +2 -0
- data/lib/delayed/version.rb +3 -1
- data/lib/delayed/work_queue/in_process.rb +2 -0
- data/lib/delayed/work_queue/parent_process.rb +2 -0
- data/lib/delayed/work_queue/parent_process/client.rb +2 -0
- data/lib/delayed/work_queue/parent_process/server.rb +3 -1
- data/lib/delayed/worker.rb +3 -1
- data/lib/delayed/worker/consul_health_check.rb +3 -1
- data/lib/delayed/worker/health_check.rb +2 -0
- data/lib/delayed/worker/null_health_check.rb +2 -0
- data/lib/delayed/worker/process_helper.rb +2 -0
- data/lib/delayed/yaml_extensions.rb +2 -0
- data/lib/delayed_job.rb +4 -0
- data/lib/inst-jobs.rb +2 -0
- data/spec/active_record_job_spec.rb +4 -6
- data/spec/delayed/cli_spec.rb +2 -0
- data/spec/delayed/daemon_spec.rb +2 -0
- data/spec/delayed/message_sending_spec.rb +51 -0
- data/spec/delayed/server_spec.rb +2 -4
- data/spec/delayed/settings_spec.rb +2 -0
- data/spec/delayed/work_queue/in_process_spec.rb +2 -4
- data/spec/delayed/work_queue/parent_process/client_spec.rb +2 -4
- data/spec/delayed/work_queue/parent_process/server_spec.rb +2 -1
- data/spec/delayed/work_queue/parent_process_spec.rb +2 -1
- data/spec/delayed/worker/consul_health_check_spec.rb +3 -1
- data/spec/delayed/worker/health_check_spec.rb +2 -0
- data/spec/delayed/worker_spec.rb +29 -0
- data/spec/gemfiles/51.gemfile.lock +7 -7
- data/spec/gemfiles/52.gemfile.lock +17 -15
- data/spec/gemfiles/60.gemfile.lock +93 -89
- data/spec/migrate/20140924140513_add_story_table.rb +2 -0
- data/spec/redis_job_spec.rb +10 -12
- data/spec/sample_jobs.rb +2 -0
- data/spec/shared/delayed_batch.rb +17 -15
- data/spec/shared/delayed_method.rb +49 -204
- data/spec/shared/performable_method.rb +11 -9
- data/spec/shared/shared_backend.rb +27 -25
- data/spec/shared/testing.rb +7 -5
- data/spec/shared/worker.rb +15 -13
- data/spec/shared_jobs_specs.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- metadata +26 -7
data/lib/delayed/periodic.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fugit'
|
2
4
|
|
3
5
|
module Delayed
|
@@ -47,10 +49,10 @@ class Periodic
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def enqueue
|
50
|
-
Delayed::Job.enqueue(self,
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
Delayed::Job.enqueue(self, **@job_args.merge(:max_attempts => 1,
|
53
|
+
:run_at => @cron.next_time(Delayed::Periodic.now).utc.to_time,
|
54
|
+
:singleton => tag,
|
55
|
+
on_conflict: :patient))
|
54
56
|
end
|
55
57
|
|
56
58
|
def perform
|
data/lib/delayed/plugin.rb
CHANGED
data/lib/delayed/pool.rb
CHANGED
data/lib/delayed/server.rb
CHANGED
data/lib/delayed/settings.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'erb'
|
3
5
|
require 'active_support/core_ext/hash/indifferent_access'
|
@@ -23,7 +25,10 @@ module Delayed
|
|
23
25
|
:worker_health_check_config,
|
24
26
|
:worker_procname_prefix,
|
25
27
|
]
|
26
|
-
SETTINGS_WITH_ARGS = [
|
28
|
+
SETTINGS_WITH_ARGS = [
|
29
|
+
:job_detailed_log_format,
|
30
|
+
:num_strands
|
31
|
+
]
|
27
32
|
|
28
33
|
SETTINGS.each do |setting|
|
29
34
|
mattr_writer(setting)
|
@@ -65,6 +70,7 @@ module Delayed
|
|
65
70
|
|
66
71
|
self.num_strands = ->(strand_name){ nil }
|
67
72
|
self.default_job_options = ->{ Hash.new }
|
73
|
+
self.job_detailed_log_format = ->(job){ job.to_json(include_root: false, only: %w(tag strand priority attempts created_at max_attempts source)) }
|
68
74
|
|
69
75
|
# Send workers KILL after QUIT if they haven't exited within the
|
70
76
|
# slow_exit_timeout
|
data/lib/delayed/testing.rb
CHANGED
data/lib/delayed/version.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Delayed
|
2
4
|
module WorkQueue
|
3
5
|
class ParentProcess
|
@@ -5,7 +7,7 @@ class ParentProcess
|
|
5
7
|
attr_reader :clients, :listen_socket
|
6
8
|
|
7
9
|
include Delayed::Logging
|
8
|
-
SIGNALS = %i{INT TERM QUIT
|
10
|
+
SIGNALS = %i{INT TERM QUIT}
|
9
11
|
|
10
12
|
def initialize(listen_socket, parent_pid: nil, config: Settings.parent_process)
|
11
13
|
@listen_socket = listen_socket
|
data/lib/delayed/worker.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Delayed
|
2
4
|
|
3
5
|
class TimeoutError < RuntimeError; end
|
@@ -253,7 +255,7 @@ class Worker
|
|
253
255
|
def log_job(job, format = :short)
|
254
256
|
case format
|
255
257
|
when :long
|
256
|
-
"#{job.full_name} #{
|
258
|
+
"#{job.full_name} #{ Settings.job_detailed_log_format.call(job) }"
|
257
259
|
else
|
258
260
|
job.full_name
|
259
261
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'health_check'
|
2
4
|
require_relative 'process_helper'
|
3
5
|
require 'socket'
|
@@ -11,7 +13,7 @@ module Delayed
|
|
11
13
|
DEFAULT_SERVICE_NAME = 'inst-jobs_worker'.freeze
|
12
14
|
attr_reader :agent_client, :catalog_client
|
13
15
|
|
14
|
-
def initialize(
|
16
|
+
def initialize(*, **)
|
15
17
|
super
|
16
18
|
# Because we don't want the consul client to be a hard dependency we're
|
17
19
|
# only requiring it once it's absolutely needed
|
data/lib/delayed_job.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Delayed
|
2
4
|
MIN_PRIORITY = 0
|
3
5
|
HIGH_PRIORITY = 0
|
@@ -17,6 +19,8 @@ require 'active_support/core_ext/module/attribute_accessors'
|
|
17
19
|
require 'active_record'
|
18
20
|
require 'after_transaction_commit'
|
19
21
|
|
22
|
+
require 'delayed/core_ext/kernel'
|
23
|
+
|
20
24
|
require 'delayed/settings'
|
21
25
|
require 'delayed/yaml_extensions'
|
22
26
|
|
data/lib/inst-jobs.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path("../spec_helper", __FILE__)
|
2
4
|
|
3
5
|
describe 'Delayed::Backed::ActiveRecord::Job' do
|
@@ -5,10 +7,6 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
|
|
5
7
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
6
8
|
end
|
7
9
|
|
8
|
-
after :all do
|
9
|
-
Delayed.send(:remove_const, :Job)
|
10
|
-
end
|
11
|
-
|
12
10
|
before do
|
13
11
|
Delayed::Testing.clear_all!
|
14
12
|
end
|
@@ -17,7 +15,7 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
|
|
17
15
|
|
18
16
|
it "should recover as well as possible from a failure failing a job" do
|
19
17
|
allow(Delayed::Job::Failed).to receive(:create).and_raise(RuntimeError)
|
20
|
-
job = "test".
|
18
|
+
job = "test".delay(ignore_transaction: true).reverse
|
21
19
|
job_id = job.id
|
22
20
|
proc { job.fail! }.should raise_error(RuntimeError)
|
23
21
|
proc { Delayed::Job.find(job_id) }.should raise_error(ActiveRecord::RecordNotFound)
|
@@ -43,7 +41,7 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
|
|
43
41
|
it "should select the next job at random if enabled" do
|
44
42
|
begin
|
45
43
|
Delayed::Settings.select_random_from_batch = true
|
46
|
-
15.times { "test".
|
44
|
+
15.times { "test".delay.length }
|
47
45
|
founds = []
|
48
46
|
15.times do
|
49
47
|
job = Delayed::Job.get_and_lock_next_available('tester')
|
data/spec/delayed/cli_spec.rb
CHANGED
data/spec/delayed/daemon_spec.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'debug_inspector'
|
5
|
+
|
6
|
+
RSpec.describe Delayed::MessageSending do
|
7
|
+
before do
|
8
|
+
allow(::Rails.env).to receive(:test?).and_return(true)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:klass) do
|
12
|
+
Class.new do
|
13
|
+
def call_private(**enqueue_args)
|
14
|
+
delay(**enqueue_args).private_method
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def private_method
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "allows an object to send a private message to itself" do
|
25
|
+
klass.new.call_private
|
26
|
+
end
|
27
|
+
|
28
|
+
it "allows an object to send a private message to itself synchronouosly" do
|
29
|
+
klass.new.call_private(synchronous: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "warns about directly sending a private message asynchronously" do
|
33
|
+
expect { klass.new.delay.private_method }.to raise_error(NoMethodError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "warns about directly sending a private message synchronusly" do
|
37
|
+
expect { klass.new.delay(synchronous: true).private_method }.to raise_error(NoMethodError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "does not warn about directly sending a private message in production" do
|
41
|
+
allow(::Rails.env).to receive(:test?).and_return(false)
|
42
|
+
allow(::Rails.env).to receive(:development?).and_return(false)
|
43
|
+
klass.new.delay.private_method
|
44
|
+
end
|
45
|
+
|
46
|
+
it "does not warn about directly sending a private message synchronously in production" do
|
47
|
+
allow(::Rails.env).to receive(:test?).and_return(false)
|
48
|
+
allow(::Rails.env).to receive(:development?).and_return(false)
|
49
|
+
klass.new.delay(synchronous: true).private_method
|
50
|
+
end
|
51
|
+
end
|
data/spec/delayed/server_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'delayed/server'
|
3
5
|
|
@@ -18,10 +20,6 @@ RSpec.describe Delayed::Server, sinatra: true do
|
|
18
20
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
19
21
|
end
|
20
22
|
|
21
|
-
after :all do
|
22
|
-
Delayed.send(:remove_const, :Job)
|
23
|
-
end
|
24
|
-
|
25
23
|
describe "get '/running'" do
|
26
24
|
before do
|
27
25
|
3.times do |i|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe Delayed::WorkQueue::InProcess do
|
@@ -5,10 +7,6 @@ RSpec.describe Delayed::WorkQueue::InProcess do
|
|
5
7
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
6
8
|
end
|
7
9
|
|
8
|
-
after :all do
|
9
|
-
Delayed.send(:remove_const, :Job)
|
10
|
-
end
|
11
|
-
|
12
10
|
after :each do
|
13
11
|
Delayed::Worker.lifecycle.reset!
|
14
12
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
@@ -14,10 +16,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
14
16
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
15
17
|
end
|
16
18
|
|
17
|
-
after :all do
|
18
|
-
Delayed.send(:remove_const, :Job)
|
19
|
-
end
|
20
|
-
|
21
19
|
it 'marshals the given arguments to the server and returns the response' do
|
22
20
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
23
21
|
expect(connection).to receive(:eof?).and_return(false)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
@@ -29,7 +31,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
|
|
29
31
|
end
|
30
32
|
|
31
33
|
after :all do
|
32
|
-
Delayed.send(:remove_const, :Job)
|
33
34
|
Delayed::Settings.parent_process = {}
|
34
35
|
end
|
35
36
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'fileutils'
|
3
5
|
|
@@ -11,7 +13,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
|
|
11
13
|
end
|
12
14
|
|
13
15
|
after :all do
|
14
|
-
Delayed.send(:remove_const, :Job)
|
15
16
|
Delayed::Settings.parent_process = {}
|
16
17
|
end
|
17
18
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'imperium'
|
3
5
|
|
@@ -15,7 +17,7 @@ RSpec.describe Delayed::Worker::ConsulHealthCheck do
|
|
15
17
|
|
16
18
|
describe '#initialize' do
|
17
19
|
it 'must use the default agent client when the config is mostly empty' do
|
18
|
-
check = Delayed::Worker::ConsulHealthCheck.new(
|
20
|
+
check = Delayed::Worker::ConsulHealthCheck.new(worker_name: 'foobar')
|
19
21
|
expect(check.agent_client).to eq Imperium::Agent.default_client
|
20
22
|
end
|
21
23
|
|
data/spec/delayed/worker_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../spec_helper"
|
2
4
|
|
3
5
|
describe Delayed::Worker do
|
@@ -38,6 +40,33 @@ describe Delayed::Worker do
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
describe "#log_job" do
|
44
|
+
around(:each) do |block|
|
45
|
+
prev_logger = Delayed::Settings.job_detailed_log_format
|
46
|
+
block.call
|
47
|
+
Delayed::Settings.job_detailed_log_format = prev_logger
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has a reasonable default format" do
|
51
|
+
payload = double(perform: nil)
|
52
|
+
job = Delayed::Job.new(payload_object: payload, priority: 25, strand: "test_jobs")
|
53
|
+
short_log_format = subject.log_job(job, :short)
|
54
|
+
expect(short_log_format).to eq("RSpec::Mocks::Double")
|
55
|
+
long_format = subject.log_job(job, :long)
|
56
|
+
expect(long_format).to eq("RSpec::Mocks::Double {\"priority\":25,\"attempts\":0,\"created_at\":null,\"tag\":\"RSpec::Mocks::Double#perform\",\"max_attempts\":null,\"strand\":\"test_jobs\",\"source\":null}")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "logging format can be changed with settings" do
|
60
|
+
Delayed::Settings.job_detailed_log_format = ->(job){ "override format #{job.strand}"}
|
61
|
+
payload = double(perform: nil)
|
62
|
+
job = Delayed::Job.new(payload_object: payload, priority: 25, strand: "test_jobs")
|
63
|
+
short_log_format = subject.log_job(job, :short)
|
64
|
+
expect(short_log_format).to eq("RSpec::Mocks::Double")
|
65
|
+
long_format = subject.log_job(job, :long)
|
66
|
+
expect(long_format).to eq("RSpec::Mocks::Double override format test_jobs")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
41
70
|
describe "#run" do
|
42
71
|
it "passes extra config options through to the WorkQueue" do
|
43
72
|
expect(subject.work_queue).to receive(:get_and_lock_next_available).
|