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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab62556fdb38e6d714ae0eeaf2210fc39c6611e5a193734b0edb44b18851edf1
4
- data.tar.gz: be864c9a46dcb21e120fab860781189fbfea59f72a9f563ac68146df84b23b69
3
+ metadata.gz: 110c82fedd170e47574c5cce683f08a1bad9b6fe27ce4ed91428c04153b4c317
4
+ data.tar.gz: 70da4ff747fbb8ca79f161c3e8148d7034ed1975ad5a9aa5f5f619d67e30dd31
5
5
  SHA512:
6
- metadata.gz: 225b0aded5a0880fbae40da74823707fea29741d98c13b4fedb9e80e7df9acc0e00c8a9d711df6a949b5bf7ac8898a5e3f0be7897c30a5068326fdc5d2ce9015
7
- data.tar.gz: 235bb3d12d988761fffa79128d6cb4e4f68bec15856ca6fcc4262312d025ea840cf1f5a948c34ac83607981ff6f63857260e071a5edac240aaa88c4dd5e56b28
6
+ metadata.gz: ffa82d046eacfd17e63bd27c99a3078ed0fa7a5e9521e28b87e29bbda3da81167ec6d8940657c4d5fc298c814872910c3bbe8e11f82e17333fc7aa547a95c151
7
+ data.tar.gz: c332dfdb14d28209fe2f07ded7784bd5a82c98b5cb2810a547ddfb3f406d8879a9aab3f74ff44c0d8555f99de0a947e96fba3333626d2f5e7efe00e024118101
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- railway-ipc (0.1.4)
4
+ railway-ipc (0.1.6)
5
5
  bunny (~> 2.2.0)
6
6
  sneakers (~> 2.3.5)
7
7
 
@@ -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
- rescue StandardError => e
44
- RailwayIpc.logger.log_exception(
45
- feature: "railway_consumer",
46
- error: e.class,
47
- error_message: e.message,
48
- payload: payload,
49
- )
50
- raise e
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
- if handler.handle(protobuf_message).success?
57
- message.status = RailwayIpc::ConsumedMessage::STATUSES[:success]
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
- handler.ack!
70
- elsif message && !message.processed?
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)
@@ -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, "Handling 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, "Successfully handled message")
17
- ack!
15
+ RailwayIpc.logger.info(message, 'Successfully handled message')
18
16
  else
19
- RailwayIpc.logger.error(message, "Failed to handle 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
@@ -1,7 +1,7 @@
1
1
  module RailwayIpc
2
2
  class NullHandler < RailwayIpc::Handler
3
3
  def handle(message)
4
- ack!
4
+ nil
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module RailwayIpc
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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.5
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-03 00:00:00.000000000 Z
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.0.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