inst-jobs 0.11.8 → 0.11.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delayed/message_sending.rb +43 -17
- data/lib/delayed/version.rb +1 -1
- data/spec/shared/delayed_method.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc1b53dbd69b8847b9a87b9605899225659e6bd
|
4
|
+
data.tar.gz: 05ff57cb08b532ddadb1cf82f0490820847ad466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a96b91c87fc000b003523e61cabe07ef7d433a7054423c9c50ecb96338a0e96c53d3de4589d6cb5baab91af2b81a6a2b8e9fca421f83bcd1b41cebde2a7cae6b
|
7
|
+
data.tar.gz: 0ed8814fa280e81da6e7d0632f91be46aaa4f09a34d9bfe715af0fd7f4b191433e59bf87400c2956f51d23dcceda3a59b83c13532bfd63f02e0d8e01c53be220
|
@@ -95,35 +95,54 @@ module Delayed
|
|
95
95
|
end
|
96
96
|
|
97
97
|
module ClassMethods
|
98
|
-
|
99
|
-
|
98
|
+
KWARG_ARG_TYPES = %i{key keyreq keyrest}.freeze
|
99
|
+
private_constant :KWARG_ARG_TYPES
|
100
|
+
|
101
|
+
def add_send_later_methods(method_name, enqueue_args={}, default_async=false)
|
102
|
+
aliased_method, punctuation = method_name.to_s.sub(/([?!=])$/, ''), $1
|
100
103
|
|
101
104
|
# we still need this for backwards compatibility
|
102
105
|
without_method = "#{aliased_method}_without_send_later#{punctuation}"
|
103
106
|
|
104
|
-
if public_method_defined?(
|
107
|
+
if public_method_defined?(method_name)
|
105
108
|
visibility = :public
|
106
|
-
elsif private_method_defined?(
|
109
|
+
elsif private_method_defined?(method_name)
|
107
110
|
visibility = :private
|
108
111
|
else
|
109
112
|
visibility = :protected
|
110
113
|
end
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
115
|
+
if has_kwargs? method_name
|
116
|
+
generated_delayed_methods.class_eval do
|
117
|
+
define_method without_method do |*args, **kwargs|
|
118
|
+
send(method_name, *args, synchronous: true, **kwargs)
|
119
|
+
end
|
117
120
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
define_method(method_name, -> (*args, synchronous: !default_async, **kwargs) do
|
122
|
+
if synchronous
|
123
|
+
super(*args, **kwargs)
|
124
|
+
else
|
125
|
+
send_later_enqueue_args(method_name, enqueue_args, *args, synchronous: true, **kwargs)
|
126
|
+
end
|
127
|
+
end)
|
128
|
+
end
|
129
|
+
else
|
130
|
+
generated_delayed_methods.class_eval do
|
131
|
+
define_method without_method do |*args|
|
132
|
+
send(method_name, *args, synchronous: true)
|
123
133
|
end
|
124
|
-
|
125
|
-
|
134
|
+
|
135
|
+
define_method(method_name, -> (*args, synchronous: !default_async) do
|
136
|
+
if synchronous
|
137
|
+
super(*args)
|
138
|
+
else
|
139
|
+
send_later_enqueue_args(method_name, enqueue_args, *args, synchronous: true)
|
140
|
+
end
|
141
|
+
end)
|
142
|
+
end
|
126
143
|
end
|
144
|
+
generated_delayed_methods.send(visibility, without_method)
|
145
|
+
generated_delayed_methods.send(visibility, method_name)
|
127
146
|
end
|
128
147
|
|
129
148
|
def handle_asynchronously(method, enqueue_args={})
|
@@ -138,12 +157,19 @@ module Delayed
|
|
138
157
|
add_send_later_methods(method, enqueue_args, Rails.env.production?)
|
139
158
|
end
|
140
159
|
|
141
|
-
private
|
160
|
+
private
|
161
|
+
|
162
|
+
def generated_delayed_methods
|
142
163
|
@generated_delayed_methods ||= Module.new.tap do |mod|
|
143
164
|
const_set(:DelayedMethods, mod)
|
144
165
|
prepend mod
|
145
166
|
end
|
146
167
|
end
|
168
|
+
|
169
|
+
def has_kwargs?(method_name)
|
170
|
+
original_arg_types = instance_method(method_name).parameters.map(&:first)
|
171
|
+
original_arg_types.any? { |arg_type| KWARG_ARG_TYPES.include?(arg_type) }
|
172
|
+
end
|
147
173
|
end
|
148
174
|
end
|
149
175
|
end
|
data/lib/delayed/version.rb
CHANGED
@@ -56,6 +56,21 @@ shared_examples_for 'random ruby objects' do
|
|
56
56
|
lambda { obj.test_method }.should change { Delayed::Job.jobs_count(:current) }.by(1)
|
57
57
|
end
|
58
58
|
|
59
|
+
it 'must work with kwargs in the original method' do
|
60
|
+
klass = Class.new do
|
61
|
+
attr_reader :run
|
62
|
+
def test_method(my_kwarg: nil); @run = my_kwarg; end
|
63
|
+
add_send_later_methods :test_method
|
64
|
+
|
65
|
+
def other_test(arg); @foo = arg; end
|
66
|
+
add_send_later_methods :other_test
|
67
|
+
end
|
68
|
+
|
69
|
+
obj = klass.new
|
70
|
+
obj.test_method(my_kwarg: 'foo', synchronous: true)
|
71
|
+
expect(obj.run).to eq 'foo'
|
72
|
+
end
|
73
|
+
|
59
74
|
it "should work without default_async" do
|
60
75
|
klass = Class.new do
|
61
76
|
attr_accessor :ran
|
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: 0.11.
|
4
|
+
version: 0.11.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Luetke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-01-
|
12
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: after_transaction_commit
|