eventhub-processor2 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,35 +1,35 @@
1
1
  module EventHub
2
- EH_X_INBOUND = 'event_hub.inbound'
2
+ EH_X_INBOUND = "event_hub.inbound"
3
3
 
4
- STATUS_INITIAL = 0 # To be set when dispatcher needs to dispatch to first process step.
4
+ STATUS_INITIAL = 0 # To be set when dispatcher needs to dispatch to first process step.
5
5
 
6
- STATUS_SUCCESS = 200 # To be set to indicate successful processed message. Dispatcher will routes message to the next step.
6
+ STATUS_SUCCESS = 200 # To be set to indicate successful processed message. Dispatcher will routes message to the next step.
7
7
 
8
- STATUS_RETRY = 300 # To be set to trigger retry cycle controlled by the dispatcher
9
- STATUS_RETRY_PENDING = 301 # Set and used by the dispatcher only.
10
- # Set before putting the message into a retry queue.
11
- # Once message has been retried it will sent do the same step with status.code = STATUS_SUCCESS
8
+ STATUS_RETRY = 300 # To be set to trigger retry cycle controlled by the dispatcher
9
+ STATUS_RETRY_PENDING = 301 # Set and used by the dispatcher only.
10
+ # Set before putting the message into a retry queue.
11
+ # Once message has been retried it will sent do the same step with status.code = STATUS_SUCCESS
12
12
 
13
- STATUS_INVALID = 400 # To be set to indicate invalid message (not json, invalid Event Hub Message).
14
- # Dispatcher will publish message to the invalid queue.
13
+ STATUS_INVALID = 400 # To be set to indicate invalid message (not json, invalid Event Hub Message).
14
+ # Dispatcher will publish message to the invalid queue.
15
15
 
16
- STATUS_DEADLETTER = 500 # To be set by dispatcher, processor or channel adapters to indicate
17
- # that message needs to be dead-lettered. Rejected messages could miss the
18
- # status.code = STATUS_DEADLETTER due to the RabbitMQ deadletter exchange mechanism.
16
+ STATUS_DEADLETTER = 500 # To be set by dispatcher, processor or channel adapters to indicate
17
+ # that message needs to be dead-lettered. Rejected messages could miss the
18
+ # status.code = STATUS_DEADLETTER due to the RabbitMQ deadletter exchange mechanism.
19
19
 
20
- STATUS_SCHEDULE = 600 # To be set to trigger scheduler based on schedule block, proceses next process step
21
- STATUS_SCHEDULE_RETRY = 601 # To be set to trigger scheduler based on schedule block, retry actual process step
22
- STATUS_SCHEDULE_PENDING = 602 # Set and used by the dispatcher only. Set before putting the scheduled message to the schedule queue.
20
+ STATUS_SCHEDULE = 600 # To be set to trigger scheduler based on schedule block, proceses next process step
21
+ STATUS_SCHEDULE_RETRY = 601 # To be set to trigger scheduler based on schedule block, retry actual process step
22
+ STATUS_SCHEDULE_PENDING = 602 # Set and used by the dispatcher only. Set before putting the scheduled message to the schedule queue.
23
23
 
24
24
  STATUS_CODE_TRANSLATION = {
25
- STATUS_INITIAL => 'STATUS_INITIAL',
26
- STATUS_SUCCESS => 'STATUS_SUCCESS',
27
- STATUS_RETRY => 'STATUS_RETRY',
28
- STATUS_RETRY_PENDING => 'STATUS_RETRY_PENDING',
29
- STATUS_INVALID => 'STATUS_INVALID',
30
- STATUS_DEADLETTER => 'STATUS_DEADLETTER',
31
- STATUS_SCHEDULE => 'STATUS_SCHEDULE',
32
- STATUS_SCHEDULE_RETRY => 'STATUS_SCHEDULE_RETRY',
33
- STATUS_SCHEDULE_PENDING =>'STATUS_SCHEDULE_PENDING',
25
+ STATUS_INITIAL => "STATUS_INITIAL",
26
+ STATUS_SUCCESS => "STATUS_SUCCESS",
27
+ STATUS_RETRY => "STATUS_RETRY",
28
+ STATUS_RETRY_PENDING => "STATUS_RETRY_PENDING",
29
+ STATUS_INVALID => "STATUS_INVALID",
30
+ STATUS_DEADLETTER => "STATUS_DEADLETTER",
31
+ STATUS_SCHEDULE => "STATUS_SCHEDULE",
32
+ STATUS_SCHEDULE_RETRY => "STATUS_SCHEDULE_RETRY",
33
+ STATUS_SCHEDULE_PENDING => "STATUS_SCHEDULE_PENDING"
34
34
  }
35
35
  end
@@ -10,18 +10,18 @@ module HashExtensions
10
10
  # e.g. hash.get(%w(event_hub plate.queue1 retry_s))
11
11
  # "a" => { "b" => { "c" => { "value"}}}
12
12
  def get(arg)
13
- path = arg.is_a?(String) ? arg.split('.') : arg
13
+ path = arg.is_a?(String) ? arg.split(".") : arg
14
14
  path.inject(self, :[])
15
15
  end
16
16
 
17
17
  # set value from provided key path, e.h. hash.set('a.b.c','new value')
18
18
  # if overwrite is false, value will be set if it was nil previously
19
19
  def set(arg, value, overwrite = true)
20
- *key_path, last = arg.is_a?(String) ? arg.split('.') : arg
20
+ *key_path, last = arg.is_a?(String) ? arg.split(".") : arg
21
21
  if overwrite
22
- key_path.inject(self) { |h, key| h.key?(key) ? h[key] : h[key] = {} } [last] = value
22
+ key_path.inject(self) { |h, key| h.key?(key) ? h[key] : h[key] = {} } [last] = value
23
23
  else
24
- key_path.inject(self) { |h, key| h.key?(key) ? h[key] : h[key] = {} } [last] ||= value
24
+ key_path.inject(self) { |h, key| h.key?(key) ? h[key] : h[key] = {} } [last] ||= value
25
25
  end
26
26
  end
27
27
 
@@ -30,10 +30,10 @@ module HashExtensions
30
30
  def all_keys_with_path(parent = nil)
31
31
  a = []
32
32
  each do |k, v|
33
- if v.is_a?(Hash)
34
- a << v.all_keys_with_path([parent, k].compact.join('.'))
33
+ a << if v.is_a?(Hash)
34
+ v.all_keys_with_path([parent, k].compact.join("."))
35
35
  else
36
- a << [parent, k].compact.join('.').to_s
36
+ [parent, k].compact.join(".").to_s
37
37
  end
38
38
  end
39
39
  a.flatten
@@ -41,7 +41,7 @@ module HashExtensions
41
41
  end
42
42
 
43
43
  def self.included(receiver)
44
- receiver.extend ClassMethods
44
+ receiver.extend ClassMethods
45
45
  receiver.send :include, InstanceMethods
46
46
  end
47
47
  end
@@ -11,16 +11,16 @@ module EventHub
11
11
  # EventHub::NameSpace::DemoProcessor => name_space.demo_processor
12
12
  # NameSpace::Demo => name_space.demo
13
13
  def get_name_from_class(instance)
14
- instance.class.to_s.split('::').map do |element|
15
- next if element == 'EventHub'
16
- element.split(/(?=[A-Z])/).join('_').downcase
17
- end.compact.join('.')
14
+ instance.class.to_s.split("::").map { |element|
15
+ next if element == "EventHub"
16
+ element.split(/(?=[A-Z])/).join("_").downcase
17
+ }.compact.join(".")
18
18
  end
19
19
 
20
20
  def create_bunny_connection
21
21
  server = EventHub::Configuration.server
22
22
 
23
- protocol = 'amqp'
23
+ protocol = "amqp"
24
24
  connection_properties = {}
25
25
  connection_properties[:user] = server[:user]
26
26
  connection_properties[:pass] = server[:password]
@@ -28,7 +28,7 @@ module EventHub
28
28
 
29
29
  # inject bunny logs on request
30
30
  unless server[:show_bunny_logs]
31
- connection_properties[:logger] = Logger.new('/dev/null')
31
+ connection_properties[:logger] = Logger.new("/dev/null")
32
32
  end
33
33
 
34
34
  # we don't need it since reactors can deal with it
@@ -50,7 +50,7 @@ module EventHub
50
50
  end
51
51
 
52
52
  # Formats stamp into UTC format
53
- def now_stamp(now=nil)
53
+ def now_stamp(now = nil)
54
54
  now ||= Time.now
55
55
  now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ")
56
56
  end
@@ -3,10 +3,10 @@ module EventHub
3
3
  def self.logger
4
4
  unless @logger
5
5
  @logger = ::EventHub::Components::MultiLogger.new
6
- @logger.add_device(Logger.new(STDOUT))
6
+ @logger.add_device(Logger.new($stdout))
7
7
  @logger.add_device(
8
8
  EventHub::Components::Logger.logstash(Configuration.name,
9
- Configuration.environment)
9
+ Configuration.environment)
10
10
  )
11
11
  end
12
12
  @logger
@@ -4,29 +4,29 @@ module EventHub
4
4
  class Message
5
5
  include Helper
6
6
 
7
- VERSION = '1.0.0'.freeze
7
+ VERSION = "1.0.0".freeze
8
8
 
9
9
  # Headers that are required (value can be nil) in order to pass valid?
10
10
  REQUIRED_HEADERS = [
11
- 'message_id',
12
- 'version',
13
- 'created_at',
14
- 'origin.module_id',
15
- 'origin.type',
16
- 'origin.site_id',
17
- 'process.name',
18
- 'process.step_position',
19
- 'process.execution_id',
20
- 'status.retried_count',
21
- 'status.code',
22
- 'status.message'
11
+ "message_id",
12
+ "version",
13
+ "created_at",
14
+ "origin.module_id",
15
+ "origin.type",
16
+ "origin.site_id",
17
+ "process.name",
18
+ "process.step_position",
19
+ "process.execution_id",
20
+ "status.retried_count",
21
+ "status.code",
22
+ "status.message"
23
23
  ].freeze
24
24
 
25
25
  attr_accessor :header, :body, :raw, :vhost, :routing_key
26
26
 
27
27
  # Build accessors for all required headers
28
28
  REQUIRED_HEADERS.each do |header|
29
- name = header.tr('.', '_')
29
+ name = header.tr(".", "_")
30
30
 
31
31
  define_method(name) do
32
32
  self.header.get(header)
@@ -39,18 +39,18 @@ module EventHub
39
39
 
40
40
  def self.from_json(raw)
41
41
  data = JSON.parse(raw)
42
- Message.new(data.get('header'), data.get('body'), raw)
42
+ Message.new(data.get("header"), data.get("body"), raw)
43
43
  rescue => e
44
44
  Message.new(
45
45
  {
46
- 'status' =>
46
+ "status" =>
47
47
  {
48
- 'code' => STATUS_INVALID,
49
- 'message' => "JSON parse error: #{e}"
48
+ "code" => STATUS_INVALID,
49
+ "message" => "JSON parse error: #{e}"
50
50
  }
51
51
  },
52
52
  {
53
- 'original_message_base64_encoded' => Base64.encode64(raw)
53
+ "original_message_base64_encoded" => Base64.encode64(raw)
54
54
  },
55
55
  raw
56
56
  )
@@ -58,33 +58,33 @@ module EventHub
58
58
 
59
59
  def initialize(header = nil, body = nil, raw = nil)
60
60
  @header = header || {}
61
- @body = body || {}
62
- @raw = raw
61
+ @body = body || {}
62
+ @raw = raw
63
63
 
64
64
  # set message defaults, that we have required headers
65
- @header.set('message_id', UUIDTools::UUID.timestamp_create.to_s, false)
66
- @header.set('version', VERSION, false)
67
- @header.set('created_at', now_stamp, false)
65
+ @header.set("message_id", UUIDTools::UUID.timestamp_create.to_s, false)
66
+ @header.set("version", VERSION, false)
67
+ @header.set("created_at", now_stamp, false)
68
68
 
69
- @header.set('origin.module_id', 'undefined', false)
70
- @header.set('origin.type', 'undefined', false)
71
- @header.set('origin.site_id', 'undefined', false)
69
+ @header.set("origin.module_id", "undefined", false)
70
+ @header.set("origin.type", "undefined", false)
71
+ @header.set("origin.site_id", "undefined", false)
72
72
 
73
- @header.set('process.name', 'undefined', false)
74
- @header.set('process.execution_id',
75
- UUIDTools::UUID.timestamp_create.to_s, false)
76
- @header.set('process.step_position', 0, false)
73
+ @header.set("process.name", "undefined", false)
74
+ @header.set("process.execution_id",
75
+ UUIDTools::UUID.timestamp_create.to_s, false)
76
+ @header.set("process.step_position", 0, false)
77
77
 
78
- @header.set('status.retried_count', 0, false)
79
- @header.set('status.code', STATUS_INITIAL, false)
80
- @header.set('status.message', '', false)
78
+ @header.set("status.retried_count", 0, false)
79
+ @header.set("status.code", STATUS_INITIAL, false)
80
+ @header.set("status.message", "", false)
81
81
  end
82
82
 
83
83
  def valid?
84
84
  # check for existence and defined value
85
85
  REQUIRED_HEADERS.all? do |key|
86
86
  @header.all_keys_with_path.include?(key) &&
87
- !send(key.tr('.', '_').to_sym).nil?
87
+ !send(key.tr(".", "_").to_sym).nil?
88
88
  end
89
89
  end
90
90
 
@@ -121,11 +121,11 @@ module EventHub
121
121
  end
122
122
 
123
123
  def to_json
124
- { 'header' => header, 'body' => body }.to_json
124
+ {"header" => header, "body" => body}.to_json
125
125
  end
126
126
 
127
127
  def to_s
128
- 'Msg: process '\
128
+ "Msg: process "\
129
129
  "[#{process_name}, #{process_step_position}, #{process_execution_id}]"\
130
130
  ", status [#{status_code},#{status_message},#{status_retried_count}]"
131
131
  end
@@ -135,20 +135,20 @@ module EventHub
135
135
  def copy(status_code = STATUS_SUCCESS)
136
136
  # use Marshal dump and load to make a deep object copy
137
137
  copied_header = Marshal.load(Marshal.dump(header))
138
- copied_body = Marshal.load(Marshal.dump(body))
138
+ copied_body = Marshal.load(Marshal.dump(body))
139
139
 
140
- copied_header.set('message_id', UUIDTools::UUID.timestamp_create.to_s)
141
- copied_header.set('created_at', now_stamp)
142
- copied_header.set('status.code', status_code)
140
+ copied_header.set("message_id", UUIDTools::UUID.timestamp_create.to_s)
141
+ copied_header.set("created_at", now_stamp)
142
+ copied_header.set("status.code", status_code)
143
143
 
144
144
  Message.new(copied_header, copied_body)
145
145
  end
146
146
 
147
147
  def append_to_execution_history(processor_name)
148
- header.set('execution_history', []) unless \
149
- header.get('execution_history')
150
- header.get('execution_history') << \
151
- { 'processor' => processor_name, 'timestamp' => now_stamp }
148
+ header.set("execution_history", []) unless \
149
+ header.get("execution_history")
150
+ header.get("execution_history") << \
151
+ {"processor" => processor_name, "timestamp" => now_stamp}
152
152
  end
153
153
 
154
154
  def self.translate_status_code(code)
@@ -1,4 +1,4 @@
1
- require_relative 'base'
1
+ require_relative "base"
2
2
 
3
3
  # EventHub module
4
4
  module EventHub
@@ -15,7 +15,7 @@ module EventHub
15
15
  def initialize(args = {})
16
16
  # Set processor name
17
17
  EventHub::Configuration.name = args[:name] ||
18
- get_name_from_class(self)
18
+ get_name_from_class(self)
19
19
 
20
20
  # Parse comand line options
21
21
  EventHub::Configuration.parse_options
@@ -54,7 +54,7 @@ module EventHub
54
54
  # get message as EventHub::Message class instance
55
55
  # args contain :queue_name, :content_type, :priority, :delivery_tag
56
56
  def handle_message(_message, _args = {})
57
- raise 'need to be implemented in derived class'
57
+ raise "need to be implemented in derived class"
58
58
  end
59
59
 
60
60
  # pass message as string like: '{ "header": ... , "body": { .. }}'
@@ -86,8 +86,8 @@ module EventHub
86
86
 
87
87
  def start_supervisor
88
88
  @config = Celluloid::Supervision::Configuration.define([
89
- {type: ActorHeartbeat, as: :actor_heartbeat, args: [ self ]},
90
- {type: ActorListener, as: :actor_listener, args: [ self ]}
89
+ {type: ActorHeartbeat, as: :actor_heartbeat, args: [self]},
90
+ {type: ActorListener, as: :actor_listener, args: [self]}
91
91
  ])
92
92
 
93
93
  sleeper = @sleeper
@@ -95,34 +95,34 @@ module EventHub
95
95
  restart_in_s = Configuration.processor[:restart_in_s]
96
96
  EventHub.logger.info("Restarting in #{restart_in_s} seconds...")
97
97
  sleeper.start(restart_in_s)
98
- end )
98
+ end)
99
99
 
100
100
  @config.deploy
101
101
  end
102
102
 
103
103
  def main_event_loop
104
+ Celluloid.boot
104
105
  setup_signal_handler
105
106
  start_supervisor
106
107
 
107
108
  loop do
108
109
  command = @command_queue.pop
109
- case
110
- when SIGNALS_FOR_TERMINATION.include?(command)
111
- EventHub.logger.info("Command [#{command}] received")
112
- @sleeper.stop
113
- break
114
- when SIGNALS_FOR_RELOAD_CONFIG.include?(command)
115
- EventHub::Configuration.load!
116
- EventHub.logger.info('Configuration file reloaded')
117
-
118
- # restart listener when actor is known
119
- if Celluloid::Actor[:actor_listener]
120
- Celluloid::Actor[:actor_listener].async.restart
121
- else
122
- EventHub.logger.info('Was unable to get a valid listener actor to restart... check!!!')
123
- end
110
+ if SIGNALS_FOR_TERMINATION.include?(command)
111
+ EventHub.logger.info("Command [#{command}] received")
112
+ @sleeper.stop
113
+ break
114
+ elsif SIGNALS_FOR_RELOAD_CONFIG.include?(command)
115
+ EventHub::Configuration.load!
116
+ EventHub.logger.info("Configuration file reloaded")
117
+
118
+ # restart listener when actor is known
119
+ if Celluloid::Actor[:actor_listener]
120
+ Celluloid::Actor[:actor_listener].async.restart
124
121
  else
125
- sleep 0.5
122
+ EventHub.logger.info("Was unable to get a valid listener actor to restart... check!!!")
123
+ end
124
+ else
125
+ sleep 0.5
126
126
  end
127
127
  end
128
128
 
@@ -8,7 +8,7 @@ module EventHub
8
8
  end
9
9
 
10
10
  def stop
11
- @writer.close if @writer and !@writer.closed?
11
+ @writer.close if @writer && !@writer.closed?
12
12
  end
13
13
  end
14
14
  end
@@ -11,14 +11,12 @@ class EventHub::Statistics
11
11
  end
12
12
 
13
13
  def measure(size, &block)
14
- begin
15
- start = Time.now
16
- yield
17
- success(Time.now - start, size)
18
- rescue
19
- failure
20
- raise
21
- end
14
+ start = Time.now
15
+ yield
16
+ success(Time.now - start, size)
17
+ rescue
18
+ failure
19
+ raise
22
20
  end
23
21
 
24
22
  def success(process_time, size)
@@ -1,3 +1,3 @@
1
1
  module EventHub
2
- VERSION = '1.8.0'.freeze
2
+ VERSION = "1.9.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventhub-processor2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steiner, Thomas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2021-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.17'
19
+ version: '0.18'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.17'
26
+ version: '0.18'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bunny
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.18'
117
+ version: '0.21'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.18'
124
+ version: '0.21'
125
+ - !ruby/object:Gem::Dependency
126
+ name: standardrb
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
125
139
  description: Next generation gem to build ruby based eventhub processor
126
140
  email:
127
141
  - thomas.steiner@ikey.ch
@@ -175,7 +189,7 @@ homepage: https://github.com/thomis/eventhub-processor2
175
189
  licenses:
176
190
  - MIT
177
191
  metadata: {}
178
- post_install_message:
192
+ post_install_message:
179
193
  rdoc_options: []
180
194
  require_paths:
181
195
  - lib
@@ -190,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
204
  - !ruby/object:Gem::Version
191
205
  version: '0'
192
206
  requirements: []
193
- rubygems_version: 3.1.2
194
- signing_key:
207
+ rubygems_version: 3.0.3
208
+ signing_key:
195
209
  specification_version: 4
196
210
  summary: Next generation gem to build ruby based eventhub processor
197
211
  test_files: []