inst-jobs 1.0.0 → 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/lib/delayed/core_ext/kernel.rb +9 -0
- data/lib/delayed/message_sending.rb +43 -5
- data/lib/delayed/performable_method.rb +14 -5
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/worker/consul_health_check.rb +1 -1
- data/lib/delayed_job.rb +2 -0
- data/spec/active_record_job_spec.rb +0 -4
- data/spec/delayed/message_sending_spec.rb +51 -0
- data/spec/delayed/server_spec.rb +0 -4
- data/spec/delayed/work_queue/in_process_spec.rb +0 -4
- data/spec/delayed/work_queue/parent_process/client_spec.rb +0 -4
- data/spec/delayed/work_queue/parent_process/server_spec.rb +0 -1
- data/spec/delayed/work_queue/parent_process_spec.rb +0 -1
- data/spec/delayed/worker/consul_health_check_spec.rb +1 -1
- data/spec/gemfiles/60.gemfile.lock +6 -4
- data/spec/redis_job_spec.rb +0 -4
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dad83034c6ca9ae9a7f7129581ecd36f64d1d51f93aa1126582ff2141068020
|
4
|
+
data.tar.gz: 8b155f2ed6ce13b956d8383bc484ef19ed3b661502bf2aed734a4618befebf40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 783af3d9f654e07a55a6be57691216a255bb548a720ae31d7c085ba0c70be20164a2a2c6a7b36767976468e034b5bafc6de427f577a05c2c70d0a6621301e86d
|
7
|
+
data.tar.gz: cbc4ff85dea6bc2f12d8eb2cecb25cecae4dc47e5e5155e46c63ebdbc4884e15f43f41b69b8611c44cbb42f4539843ecffe8cf5e96cab852bf9ace06a7a6b6fa
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Kernel
|
2
|
+
def sender(i = 0)
|
3
|
+
frame_self = nil
|
4
|
+
# 3. one for the block, one for this method, one for the method calling this
|
5
|
+
# method, and _then_ we get to the self for who sent the message we want
|
6
|
+
RubyVM::DebugInspector.open { |dc| frame_self = dc.frame_self(3 + i) }
|
7
|
+
frame_self
|
8
|
+
end
|
9
|
+
end
|
@@ -1,14 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
if ::Rails.env.test? || ::Rails.env.development?
|
4
|
+
require 'debug_inspector'
|
5
|
+
end
|
6
|
+
|
3
7
|
module Delayed
|
4
8
|
module MessageSending
|
5
9
|
class DelayProxy < BasicObject
|
6
|
-
def initialize(object, enqueue_args)
|
10
|
+
def initialize(object, synchronous: false, public_send: false, **enqueue_args)
|
7
11
|
@object = object
|
8
12
|
@enqueue_args = enqueue_args
|
13
|
+
@synchronous = synchronous
|
14
|
+
@public_send = public_send
|
9
15
|
end
|
10
16
|
|
11
17
|
def method_missing(method, *args, **kwargs)
|
18
|
+
if @synchronous
|
19
|
+
if @public_send
|
20
|
+
if kwargs.empty?
|
21
|
+
return @object.public_send(method, *args)
|
22
|
+
else
|
23
|
+
return @object.public_send(method, *args, **kwargs)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
if kwargs.empty?
|
27
|
+
return @object.send(method, *args)
|
28
|
+
else
|
29
|
+
return @object.send(method, *args, **kwargs)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if @public_send && @object.private_methods.include?(method)
|
35
|
+
::Kernel.raise ::NoMethodError.new("undefined method `#{method}' for #{@object}", method)
|
36
|
+
end
|
37
|
+
|
12
38
|
ignore_transaction = @enqueue_args.delete(:ignore_transaction)
|
13
39
|
on_failure = @enqueue_args.delete(:on_failure)
|
14
40
|
on_permanent_failure = @enqueue_args.delete(:on_permanent_failure)
|
@@ -42,17 +68,29 @@ module Delayed
|
|
42
68
|
end
|
43
69
|
end
|
44
70
|
|
45
|
-
def delay(**enqueue_args)
|
71
|
+
def delay(public_send: nil, **enqueue_args)
|
46
72
|
# support procs/methods as enqueue arguments
|
47
73
|
enqueue_args.each do |k,v|
|
48
74
|
if v.respond_to?(:call)
|
49
75
|
enqueue_args[k] = v.call(self)
|
50
76
|
end
|
51
77
|
end
|
52
|
-
|
53
|
-
|
78
|
+
|
79
|
+
public_send ||= __calculate_public_send_for_delay
|
80
|
+
|
81
|
+
DelayProxy.new(self, public_send: public_send, **enqueue_args)
|
82
|
+
end
|
83
|
+
|
84
|
+
def __calculate_public_send_for_delay
|
85
|
+
# enforce public send in dev and test, but not prod (since it uses
|
86
|
+
# debug APIs, it's expensive)
|
87
|
+
public_send = if ::Rails.env.test? || ::Rails.env.development?
|
88
|
+
sender = self.sender(1)
|
89
|
+
# if the caller isn't self, use public_send; i.e. enforce method visibility
|
90
|
+
sender != self
|
91
|
+
else
|
92
|
+
false
|
54
93
|
end
|
55
|
-
DelayProxy.new(self, enqueue_args)
|
56
94
|
end
|
57
95
|
|
58
96
|
module ClassMethods
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Delayed
|
4
|
-
class PerformableMethod < Struct.new(:object, :method, :args, :kwargs, :fail_cb, :permanent_fail_cb)
|
5
|
-
def initialize(object, method, args: [], kwargs: {}, on_failure: nil, on_permanent_failure: nil)
|
4
|
+
class PerformableMethod < Struct.new(:object, :method, :args, :kwargs, :fail_cb, :permanent_fail_cb, :public_send)
|
5
|
+
def initialize(object, method, args: [], kwargs: {}, on_failure: nil, on_permanent_failure: nil, public_send: true)
|
6
6
|
raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method, true)
|
7
7
|
|
8
8
|
self.object = object
|
@@ -11,6 +11,7 @@ module Delayed
|
|
11
11
|
self.method = method.to_sym
|
12
12
|
self.fail_cb = on_failure
|
13
13
|
self.permanent_fail_cb = on_permanent_failure
|
14
|
+
self.public_send = public_send
|
14
15
|
end
|
15
16
|
|
16
17
|
def display_name
|
@@ -24,10 +25,18 @@ module Delayed
|
|
24
25
|
|
25
26
|
def perform
|
26
27
|
kwargs = self.kwargs || {}
|
27
|
-
if
|
28
|
-
|
28
|
+
if public_send
|
29
|
+
if kwargs.empty?
|
30
|
+
object.public_send(method, *args)
|
31
|
+
else
|
32
|
+
object.public_send(method, *args, **kwargs)
|
33
|
+
end
|
29
34
|
else
|
30
|
-
|
35
|
+
if kwargs.empty?
|
36
|
+
object.send(method, *args)
|
37
|
+
else
|
38
|
+
object.send(method, *args, **kwargs)
|
39
|
+
end
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
data/lib/delayed/version.rb
CHANGED
@@ -13,7 +13,7 @@ module Delayed
|
|
13
13
|
DEFAULT_SERVICE_NAME = 'inst-jobs_worker'.freeze
|
14
14
|
attr_reader :agent_client, :catalog_client
|
15
15
|
|
16
|
-
def initialize(
|
16
|
+
def initialize(*, **)
|
17
17
|
super
|
18
18
|
# Because we don't want the consul client to be a hard dependency we're
|
19
19
|
# only requiring it once it's absolutely needed
|
data/lib/delayed_job.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
@@ -16,10 +16,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
|
|
16
16
|
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
17
17
|
end
|
18
18
|
|
19
|
-
after :all do
|
20
|
-
Delayed.send(:remove_const, :Job)
|
21
|
-
end
|
22
|
-
|
23
19
|
it 'marshals the given arguments to the server and returns the response' do
|
24
20
|
expect(addrinfo).to receive(:connect).once.and_return(connection)
|
25
21
|
expect(connection).to receive(:eof?).and_return(false)
|
@@ -17,7 +17,7 @@ RSpec.describe Delayed::Worker::ConsulHealthCheck do
|
|
17
17
|
|
18
18
|
describe '#initialize' do
|
19
19
|
it 'must use the default agent client when the config is mostly empty' do
|
20
|
-
check = Delayed::Worker::ConsulHealthCheck.new(
|
20
|
+
check = Delayed::Worker::ConsulHealthCheck.new(worker_name: 'foobar')
|
21
21
|
expect(check.agent_client).to eq Imperium::Agent.default_client
|
22
22
|
end
|
23
23
|
|
@@ -1,10 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
inst-jobs (1.0.
|
4
|
+
inst-jobs (1.0.1)
|
5
5
|
activerecord (>= 4.2)
|
6
6
|
activesupport (>= 4.2)
|
7
7
|
after_transaction_commit (>= 1.0, < 3)
|
8
|
+
debug_inspector (~> 0.0.3)
|
8
9
|
fugit (~> 1.3)
|
9
10
|
railties (>= 4.2)
|
10
11
|
redis (> 3.0)
|
@@ -70,7 +71,7 @@ GEM
|
|
70
71
|
zeitwerk (~> 2.2)
|
71
72
|
addressable (2.7.0)
|
72
73
|
public_suffix (>= 2.0.2, < 5.0)
|
73
|
-
after_transaction_commit (2.2.
|
74
|
+
after_transaction_commit (2.2.1)
|
74
75
|
activerecord (>= 5.2)
|
75
76
|
backports (3.15.0)
|
76
77
|
builder (3.2.4)
|
@@ -80,13 +81,14 @@ GEM
|
|
80
81
|
concurrent-ruby (1.1.7)
|
81
82
|
crass (1.0.6)
|
82
83
|
database_cleaner (1.6.1)
|
84
|
+
debug_inspector (0.0.3)
|
83
85
|
diff-lcs (1.3)
|
84
86
|
erubi (1.9.0)
|
85
87
|
et-orbi (1.2.4)
|
86
88
|
tzinfo
|
87
|
-
fugit (1.
|
89
|
+
fugit (1.4.0)
|
88
90
|
et-orbi (~> 1.1, >= 1.1.8)
|
89
|
-
raabro (~> 1.
|
91
|
+
raabro (~> 1.4)
|
90
92
|
globalid (0.4.2)
|
91
93
|
activesupport (>= 4.2.0)
|
92
94
|
httpclient (2.8.3)
|
data/spec/redis_job_spec.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.1
|
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: 2020-10-
|
12
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -115,6 +115,20 @@ dependencies:
|
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '1.3'
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
name: debug_inspector
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.0.3
|
125
|
+
type: :runtime
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.0.3
|
118
132
|
- !ruby/object:Gem::Dependency
|
119
133
|
name: bump
|
120
134
|
requirement: !ruby/object:Gem::Requirement
|
@@ -361,6 +375,7 @@ files:
|
|
361
375
|
- lib/delayed/backend/redis/tickle_strand.lua
|
362
376
|
- lib/delayed/batch.rb
|
363
377
|
- lib/delayed/cli.rb
|
378
|
+
- lib/delayed/core_ext/kernel.rb
|
364
379
|
- lib/delayed/daemon.rb
|
365
380
|
- lib/delayed/engine.rb
|
366
381
|
- lib/delayed/job_tracking.rb
|
@@ -396,6 +411,7 @@ files:
|
|
396
411
|
- spec/active_record_job_spec.rb
|
397
412
|
- spec/delayed/cli_spec.rb
|
398
413
|
- spec/delayed/daemon_spec.rb
|
414
|
+
- spec/delayed/message_sending_spec.rb
|
399
415
|
- spec/delayed/server_spec.rb
|
400
416
|
- spec/delayed/settings_spec.rb
|
401
417
|
- spec/delayed/work_queue/in_process_spec.rb
|
@@ -474,6 +490,7 @@ test_files:
|
|
474
490
|
- spec/delayed/cli_spec.rb
|
475
491
|
- spec/delayed/daemon_spec.rb
|
476
492
|
- spec/delayed/worker_spec.rb
|
493
|
+
- spec/delayed/message_sending_spec.rb
|
477
494
|
- spec/delayed/settings_spec.rb
|
478
495
|
- spec/delayed/work_queue/in_process_spec.rb
|
479
496
|
- spec/delayed/work_queue/parent_process_spec.rb
|