inst-jobs 0.15.21 → 1.0.2
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 +9 -5
- 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 +90 -106
- data/lib/delayed/performable_method.rb +34 -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 +2 -0
- 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 +101 -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/42.gemfile.lock +192 -0
- data/spec/gemfiles/50.gemfile.lock +197 -0
- data/spec/gemfiles/51.gemfile.lock +198 -0
- data/spec/gemfiles/52.gemfile.lock +206 -0
- data/spec/gemfiles/60.gemfile.lock +224 -0
- 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 +12 -1
- metadata +36 -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
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,101 @@
|
|
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
|
+
before (:all) do
|
12
|
+
class SpecClass
|
13
|
+
def call_private(**enqueue_args)
|
14
|
+
delay(**enqueue_args).private_method
|
15
|
+
end
|
16
|
+
|
17
|
+
def call_protected(**enqueue_args)
|
18
|
+
other = self.class.new
|
19
|
+
other.delay(**enqueue_args).protected_method
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def private_method
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def protected_method
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
after(:all) do
|
35
|
+
Object.send(:remove_const, :SpecClass)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:klass) { SpecClass }
|
39
|
+
|
40
|
+
it "allows an object to send a private message to itself" do
|
41
|
+
job = klass.new.call_private(ignore_transaction: true)
|
42
|
+
job.invoke_job
|
43
|
+
end
|
44
|
+
|
45
|
+
it "allows an object to send a private message to itself synchronouosly" do
|
46
|
+
klass.new.call_private(synchronous: true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "warns about directly sending a private message asynchronously" do
|
50
|
+
expect { klass.new.delay.private_method }.to raise_error(NoMethodError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "warns about directly sending a private message synchronusly" do
|
54
|
+
expect { klass.new.delay(synchronous: true).private_method }.to raise_error(NoMethodError)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "does not warn about directly sending a private message in production" do
|
58
|
+
allow(::Rails.env).to receive(:test?).and_return(false)
|
59
|
+
allow(::Rails.env).to receive(:development?).and_return(false)
|
60
|
+
klass.new.delay.private_method
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not warn about directly sending a private message synchronously in production" do
|
64
|
+
allow(::Rails.env).to receive(:test?).and_return(false)
|
65
|
+
allow(::Rails.env).to receive(:development?).and_return(false)
|
66
|
+
klass.new.delay(synchronous: true).private_method
|
67
|
+
end
|
68
|
+
|
69
|
+
it "allows an object to send a protected message to itself" do
|
70
|
+
job = klass.new.call_protected(ignore_transaction: true)
|
71
|
+
job.invoke_job
|
72
|
+
end
|
73
|
+
|
74
|
+
it "allows an object to send a protected message to itself synchronouosly" do
|
75
|
+
klass.new.call_protected(synchronous: true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "warns about directly sending a protected message asynchronously" do
|
79
|
+
expect { klass.new.delay.protected_method }.to raise_error(NoMethodError)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "warns about directly sending a protected message synchronusly" do
|
83
|
+
expect { klass.new.delay(synchronous: true).protected_method }.to raise_error(NoMethodError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "doesn't explode if you can't dump the sender" do
|
87
|
+
klass = Class.new do
|
88
|
+
def delay_something
|
89
|
+
Kernel.delay.sleep(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
def encode_with(encoder)
|
93
|
+
raise "yaml encoding failed"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
obj = klass.new
|
98
|
+
expect { YAML.dump(obj) }.to raise_error("yaml encoding failed")
|
99
|
+
expect { obj.delay_something }.not_to raise_error
|
100
|
+
end
|
101
|
+
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
|
|