railway-ipc 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/railway_ipc/consumer/consumer.rb +14 -24
- data/lib/railway_ipc/handler.rb +3 -6
- data/lib/railway_ipc/models/consumed_message.rb +8 -0
- data/lib/railway_ipc/null_handler.rb +1 -1
- data/lib/railway_ipc/version.rb +1 -1
- metadata +3 -4
- data/.tool-versions +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 110c82fedd170e47574c5cce683f08a1bad9b6fe27ce4ed91428c04153b4c317
|
4
|
+
data.tar.gz: 70da4ff747fbb8ca79f161c3e8148d7034ed1975ad5a9aa5f5f619d67e30dd31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa82d046eacfd17e63bd27c99a3078ed0fa7a5e9521e28b87e29bbda3da81167ec6d8940657c4d5fc298c814872910c3bbe8e11f82e17333fc7aa547a95c151
|
7
|
+
data.tar.gz: c332dfdb14d28209fe2f07ded7784bd5a82c98b5cb2810a547ddfb3f406d8879a9aab3f74ff44c0d8555f99de0a947e96fba3333626d2f5e7efe00e024118101
|
data/Gemfile.lock
CHANGED
@@ -35,29 +35,25 @@ module RailwayIpc
|
|
35
35
|
@protobuf_message = message_klass.decode(decoded_payload.message)
|
36
36
|
process_known_message_type
|
37
37
|
else
|
38
|
-
@handler = RailwayIpc::NullHandler.new
|
39
38
|
@protobuf_message = RailwayIpc::BaseMessage.decode(decoded_payload.message)
|
40
39
|
process_unknown_message_type
|
41
40
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
ack!
|
42
|
+
rescue StandardError => e
|
43
|
+
RailwayIpc.logger.log_exception(
|
44
|
+
feature: "railway_consumer",
|
45
|
+
error: e.class,
|
46
|
+
error_message: e.message,
|
47
|
+
payload: payload,
|
48
|
+
)
|
49
|
+
raise e
|
51
50
|
end
|
52
51
|
|
53
52
|
private
|
54
53
|
|
55
54
|
def process_protobuf!(message)
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
message.status = RailwayIpc::ConsumedMessage::STATUSES[:failed_to_process]
|
60
|
-
end
|
55
|
+
response = handler.handle(protobuf_message)
|
56
|
+
message.status = RailwayIpc::ConsumedMessage.response_to_status(response)
|
61
57
|
|
62
58
|
message.save!
|
63
59
|
end
|
@@ -65,28 +61,22 @@ module RailwayIpc
|
|
65
61
|
def process_known_message_type
|
66
62
|
message = RailwayIpc::ConsumedMessage.find_by(uuid: protobuf_message.uuid)
|
67
63
|
|
68
|
-
if message && message.processed?
|
69
|
-
|
70
|
-
|
64
|
+
return if message && message.processed?
|
65
|
+
|
66
|
+
if message && !message.processed?
|
71
67
|
message.with_lock("FOR UPDATE NOWAIT") { process_protobuf!(message) }
|
72
68
|
else
|
73
69
|
message = create_message_with_status!(RailwayIpc::ConsumedMessage::STATUSES[:processing])
|
74
70
|
message.with_lock("FOR UPDATE NOWAIT") { process_protobuf!(message) }
|
75
71
|
end
|
76
|
-
|
77
|
-
nil
|
78
72
|
end
|
79
73
|
|
80
74
|
def process_unknown_message_type
|
81
|
-
handler.ack!
|
82
|
-
|
83
75
|
if RailwayIpc::ConsumedMessage.exists?(uuid: protobuf_message.uuid)
|
84
76
|
return
|
85
77
|
else
|
86
78
|
create_message_with_status!(RailwayIpc::ConsumedMessage::STATUSES[:unknown_message_type])
|
87
79
|
end
|
88
|
-
|
89
|
-
nil
|
90
80
|
end
|
91
81
|
|
92
82
|
def create_message_with_status!(status)
|
data/lib/railway_ipc/handler.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module RailwayIpc
|
2
2
|
class Handler
|
3
|
-
include Sneakers::Worker
|
4
3
|
class << self
|
5
4
|
attr_reader :block
|
6
5
|
end
|
@@ -10,14 +9,12 @@ module RailwayIpc
|
|
10
9
|
end
|
11
10
|
|
12
11
|
def handle(message)
|
13
|
-
RailwayIpc.logger.info(message,
|
12
|
+
RailwayIpc.logger.info(message, 'Handling message')
|
14
13
|
response = self.class.block.call(message)
|
15
14
|
if response.success?
|
16
|
-
RailwayIpc.logger.info(message,
|
17
|
-
ack!
|
15
|
+
RailwayIpc.logger.info(message, 'Successfully handled message')
|
18
16
|
else
|
19
|
-
RailwayIpc.logger.error(message,
|
20
|
-
ack!
|
17
|
+
RailwayIpc.logger.error(message, 'Failed to handle message')
|
21
18
|
end
|
22
19
|
|
23
20
|
response
|
@@ -14,6 +14,14 @@ module RailwayIpc
|
|
14
14
|
validates :uuid, :status, presence: true
|
15
15
|
validates :status, inclusion: { in: STATUSES.values }
|
16
16
|
|
17
|
+
def self.response_to_status(response)
|
18
|
+
if response.success?
|
19
|
+
STATUSES[:success]
|
20
|
+
else
|
21
|
+
STATUSES[:failed_to_process]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
def processed?
|
18
26
|
self.status == STATUSES[:success]
|
19
27
|
end
|
data/lib/railway_ipc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railway-ipc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -214,7 +214,6 @@ extra_rdoc_files: []
|
|
214
214
|
files:
|
215
215
|
- ".gitignore"
|
216
216
|
- ".rspec"
|
217
|
-
- ".tool-versions"
|
218
217
|
- ".travis.yml"
|
219
218
|
- CODE_OF_CONDUCT.md
|
220
219
|
- Gemfile
|
@@ -281,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
280
|
- !ruby/object:Gem::Version
|
282
281
|
version: '0'
|
283
282
|
requirements: []
|
284
|
-
rubygems_version: 3.
|
283
|
+
rubygems_version: 3.1.2
|
285
284
|
signing_key:
|
286
285
|
specification_version: 4
|
287
286
|
summary: IPC components for Rails
|
data/.tool-versions
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby 2.6.3
|