la_gear 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/la_gear.gemspec +1 -0
- data/lib/la_gear/active_record/publish_triggerable.rb +24 -3
- data/lib/la_gear/bus.rb +44 -7
- data/lib/la_gear/version.rb +1 -1
- data/lib/la_gear/worker.rb +1 -2
- data/test/helper.rb +2 -0
- data/test/test_bus.rb +709 -131
- data/test/test_publish_triggerable.rb +315 -83
- data/test/test_worker.rb +93 -0
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3b73127f098ada69cc2e0ab170a4da60d2207b6
|
4
|
+
data.tar.gz: d3e8b4e4352fbb3fbd4cd13eb3c4efabb3548cf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c566ae31db9318a8c28a8e7b2d2d9eb075ae14c2c1eef9e1416e95a478309023d6f2e8b959c58028eb9dba5bdf5c416e02e3d183659398f0fe3180e2974d7af9
|
7
|
+
data.tar.gz: dbc6562784c5f9a44927f239d3e0e4ecd8a3ed5ede4b14dbdae5dc0ee50a5ed0fe9e92c7fe0d0f647f8a6365d0440b73358881b0b939114a729de9dc762d4ef1
|
data/la_gear.gemspec
CHANGED
@@ -3,30 +3,51 @@ module LaGear
|
|
3
3
|
module PublishTriggerable
|
4
4
|
def publish_after_commit(routing_key, opts)
|
5
5
|
publish_method = "publish_#{routing_key}"
|
6
|
+
la_gear_opts = extract_la_gear_options(opts)
|
6
7
|
define_method publish_method do
|
7
8
|
message = block_given? ? yield(self) : {}
|
8
|
-
Bus.publish(routing_key.to_s, message)
|
9
|
+
Bus.publish(routing_key.to_s, message, la_gear_opts)
|
9
10
|
end
|
10
11
|
after_commit publish_method, opts
|
11
12
|
end
|
12
13
|
|
13
14
|
def send_after_commit(routing_key, opts)
|
14
15
|
publish_method = "publish_#{routing_key}"
|
16
|
+
la_gear_opts = extract_la_gear_options(opts)
|
15
17
|
define_method publish_method do
|
16
18
|
message = block_given? ? yield(self) : {}
|
17
|
-
Bus.publish_local(routing_key.to_s, message)
|
19
|
+
Bus.publish_local(routing_key.to_s, message, la_gear_opts)
|
18
20
|
end
|
19
21
|
after_commit publish_method, opts
|
20
22
|
end
|
21
23
|
|
22
24
|
def send_in_after_commit(routing_key, opts, interval)
|
23
25
|
publish_method = "publish_#{routing_key}"
|
26
|
+
la_gear_opts = extract_la_gear_options(opts)
|
24
27
|
define_method publish_method do
|
25
28
|
message = block_given? ? yield(self) : {}
|
26
|
-
Bus.publish_local_in(routing_key.to_s, message, interval)
|
29
|
+
Bus.publish_local_in(routing_key.to_s, message, la_gear_opts, interval)
|
27
30
|
end
|
28
31
|
after_commit publish_method, opts
|
29
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def extract_la_gear_options(opts = {})
|
37
|
+
la_gear_opts = {}
|
38
|
+
|
39
|
+
if opts.key?(:version)
|
40
|
+
la_gear_opts[:version] = opts[:version]
|
41
|
+
opts.delete(:version)
|
42
|
+
end
|
43
|
+
|
44
|
+
if opts.key?(:suffix)
|
45
|
+
la_gear_opts[:suffix] = opts[:suffix]
|
46
|
+
opts.delete(:suffix)
|
47
|
+
end
|
48
|
+
|
49
|
+
la_gear_opts
|
50
|
+
end
|
30
51
|
end
|
31
52
|
end
|
32
53
|
end
|
data/lib/la_gear/bus.rb
CHANGED
@@ -13,33 +13,70 @@ module LaGear
|
|
13
13
|
end
|
14
14
|
module_function :init_pool
|
15
15
|
|
16
|
-
def publish(routing_key, msg, bunny_opts = {}, sidekiq_opts = {})
|
16
|
+
def publish(routing_key, msg, la_gear_opts = {}, bunny_opts = {}, sidekiq_opts = {})
|
17
|
+
routing_key = NamespaceUtility.adjust_routing_key(routing_key, la_gear_opts)
|
17
18
|
DelayablePublisher.sidekiq_delay(sidekiq_opts).publish(routing_key, msg, bunny_opts)
|
18
19
|
end
|
19
20
|
module_function :publish
|
20
21
|
|
21
|
-
def publish_in(interval, routing_key, msg, bunny_opts = {}, sidekiq_opts = {})
|
22
|
+
def publish_in(interval, routing_key, msg, la_gear_opts = {}, bunny_opts = {}, sidekiq_opts = {})
|
23
|
+
routing_key = NamespaceUtility.adjust_routing_key(routing_key, la_gear_opts)
|
22
24
|
DelayablePublisher.sidekiq_delay_for(interval, sidekiq_opts).publish(routing_key, msg, bunny_opts)
|
23
25
|
end
|
24
26
|
module_function :publish_in
|
25
27
|
|
26
|
-
def publish_at(timestamp, routing_key, msg, bunny_opts = {}, sidekiq_opts = {})
|
28
|
+
def publish_at(timestamp, routing_key, msg, la_gear_opts = {}, bunny_opts = {}, sidekiq_opts = {})
|
29
|
+
routing_key = NamespaceUtility.adjust_routing_key(routing_key, la_gear_opts)
|
27
30
|
DelayablePublisher.sidekiq_delay_until(timestamp, sidekiq_opts).publish(routing_key, msg, bunny_opts)
|
28
31
|
end
|
29
32
|
module_function :publish_at
|
30
33
|
|
31
|
-
def publish_local(routing_key, msg)
|
32
|
-
routing_key.
|
34
|
+
def publish_local(routing_key, msg, la_gear_opts = {})
|
35
|
+
routing_key = NamespaceUtility.adjust_routing_key(routing_key, la_gear_opts)
|
36
|
+
NamespaceUtility.local_worker(routing_key).perform_async(*msg.values)
|
33
37
|
end
|
34
38
|
module_function :publish_local
|
35
39
|
|
36
|
-
def publish_local_in(routing_key, msg, interval)
|
37
|
-
routing_key.
|
40
|
+
def publish_local_in(routing_key, msg, la_gear_opts = {}, interval)
|
41
|
+
routing_key = NamespaceUtility.adjust_routing_key(routing_key, la_gear_opts)
|
42
|
+
NamespaceUtility.local_worker(routing_key).perform_in(interval, *msg.values)
|
38
43
|
end
|
39
44
|
module_function :publish_local_in
|
40
45
|
|
41
46
|
private
|
42
47
|
|
48
|
+
class NamespaceUtility
|
49
|
+
class << self
|
50
|
+
def local_worker(routing_key)
|
51
|
+
routing_key.split('.').map(&:classify).join('::').constantize
|
52
|
+
end
|
53
|
+
|
54
|
+
def adjust_routing_key(routing_key, opts = {})
|
55
|
+
if opts.key?(:version)
|
56
|
+
routing_key = add_version(routing_key, opts[:version])
|
57
|
+
opts.delete(:version)
|
58
|
+
elsif opts.key?(:suffix)
|
59
|
+
routing_key = add_suffix(routing_key, opts[:suffix])
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.delete(:suffix)
|
63
|
+
routing_key
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def add_version(routing_key, version)
|
69
|
+
return add_suffix(routing_key, "v#{version}") if version.present?
|
70
|
+
routing_key
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_suffix(routing_key, suffix)
|
74
|
+
return "#{routing_key}.#{suffix}" if suffix.present?
|
75
|
+
routing_key
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
43
80
|
class DelayablePublisher
|
44
81
|
def self.publish(routing_key, msg, opts = {})
|
45
82
|
opts = opts.merge(to_queue: routing_key)
|
data/lib/la_gear/version.rb
CHANGED
data/lib/la_gear/worker.rb
CHANGED