rsmp 0.5.5 → 0.6.2

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: a436495b7890003c9c745d9539326867be2604dc31308042d6f9fa982d8a1595
4
- data.tar.gz: '083589d05fe1fcff4ffcdd79e92ae4c34b9d8383257005ef316fb265ab5a24af'
3
+ metadata.gz: c4431d2545043cf60f1988e1bbb269e5727719fb6dd152c58908c5cd62b153ef
4
+ data.tar.gz: 4cb2c6fe95608ae4093876d2630e5a29547fdea1d6f66cdb697855e7a301470a
5
5
  SHA512:
6
- metadata.gz: f443511ee9ea01faa4189f84182208362ad25f7a7d483198126b00b78de5454cd1a092ccd8348664553c31502497c4ec3f1df295d7daa7eaa53e22bd8298521b
7
- data.tar.gz: 49436d1f1e79fec40b5a0a6f4482e4af29edac9b097380b0cf3359f1a35174a89234a3ea227a99767adb8931640383f5cca81e18105a9f00a44f7edaa11bc5c5
6
+ metadata.gz: 0dcf33801ca97d92861380ed7ee4a4cb59a343eb0744daf448afbe20fa91e2147a8a59359420cd76dd62b1cbe49026b36e284d6534d8cd71538f68ea378e06c3
7
+ data.tar.gz: 59e10a8475fa23b0e0d66c257ee5458acb156db1390e88ae464a73b40b63bea3be7372304bd5d331fb0dfaaf19308c731d3aaae158de5d7f16ebe67bb17ddda3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.5.5)
4
+ rsmp (0.6.2)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.1)
7
7
  colorize (~> 0.8.1)
@@ -11,11 +11,11 @@ log:
11
11
  active: true
12
12
  color: true
13
13
  timestamp: true
14
- id: true
15
14
  component: true
16
15
  ip: false
17
16
  port: true
18
- site_id: true
17
+ site_id: 9
18
+ component_id: 3
19
19
  text: true
20
20
  direction: false
21
21
  level: false
data/config/tlc.yaml CHANGED
@@ -33,10 +33,10 @@ log:
33
33
  active: true
34
34
  color: true
35
35
  timestamp: true
36
- id: true
37
- component: true
36
+ component_id: true
38
37
  ip: false
39
- site_id: true
38
+ site_id: 9
39
+ component: 3
40
40
  level: false
41
41
  debug: true
42
42
  text: true
data/lib/rsmp/archive.rb CHANGED
@@ -21,11 +21,11 @@ module RSMP
21
21
  def self.prepare_item item
22
22
  raise ArgumentError unless item.is_a? Hash
23
23
 
24
- cleaned = item.select { |k,v| [:author,:level,:ip,:port,:site_id,:component_id,:str,:message,:exception].include? k }
24
+ cleaned = item.select { |k,v| [:author,:level,:ip,:port,:site_id,:component,:str,:message,:exception].include? k }
25
25
  cleaned[:timestamp] = Clock.now
26
26
  if item[:message]
27
27
  cleaned[:direction] = item[:message].direction
28
- cleaned[:component_id] = item[:message].attributes['cId']
28
+ cleaned[:component] = item[:message].attributes['cId']
29
29
  end
30
30
 
31
31
  cleaned
@@ -15,8 +15,10 @@ module RSMP
15
15
  return unless settings
16
16
  check_main_component settings
17
17
  settings.each_pair do |type,components_by_type|
18
- components_by_type.each_pair do |id,settings|
19
- @components[id] = build_component(id:id, type:type, settings:settings)
18
+ if components_by_type
19
+ components_by_type.each_pair do |id,settings|
20
+ @components[id] = build_component(id:id, type:type, settings:settings)
21
+ end
20
22
  end
21
23
  end
22
24
  end
data/lib/rsmp/error.rb CHANGED
@@ -41,6 +41,9 @@ module RSMP
41
41
  class TimeoutError < Error
42
42
  end
43
43
 
44
+ class DisonnectError < Error
45
+ end
46
+
44
47
  class ConnectionError < Error
45
48
  end
46
49
 
data/lib/rsmp/logger.rb CHANGED
@@ -5,33 +5,60 @@ module RSMP
5
5
 
6
6
  def initialize settings={}
7
7
  defaults = {
8
- 'prefix'=>nil,
9
8
  'active'=>false,
10
9
  'path'=>nil,
11
10
  'stream'=>nil,
12
- 'author'=>false,
13
11
  'color'=>true,
14
- 'site_id'=>true,
15
- 'component'=>false,
16
- 'level'=>false,
17
- 'ip'=>false,
18
- 'port'=>false,
19
- 'index'=>false,
20
- 'timestamp'=>true,
21
- 'json'=>false,
22
12
  'debug'=>false,
23
13
  'statistics'=>false,
24
14
  'hide_ip_and_port' => false,
25
- 'acknowledgements' => false
15
+ 'acknowledgements' => false,
16
+ 'json'=>false,
17
+ 'tabs'=>'-',
18
+
19
+ 'prefix'=>false,
20
+ 'index'=>false,
21
+ 'author'=>false,
22
+ 'timestamp'=>true,
23
+ 'ip'=>false,
24
+ 'port'=>false,
25
+ 'site_id'=>true,
26
+ 'component'=>true,
27
+ 'direction'=>false,
28
+ 'level'=>false,
29
+ 'id'=>true,
30
+ 'str'=>true,
31
+ }
32
+
33
+ default_lengths = {
34
+ 'index'=>7,
35
+ 'author'=>13,
36
+ 'timestamp'=>24,
37
+ 'ip'=>22,
38
+ 'port'=>5,
39
+ 'site_id'=>19,
40
+ 'component'=>19,
41
+ 'direction'=>4,
42
+ 'level'=>7,
43
+ 'id'=>4,
26
44
  }
45
+
27
46
  if settings
28
47
  @settings = defaults.merge settings
29
48
  else
30
49
  @settings = defaults
31
50
  end
32
51
 
33
- @muted = {}
52
+ # copy default length for items that are set to true
53
+ @settings = @settings.map do |key,value|
54
+ if value == true && default_lengths[key]
55
+ [ key, default_lengths[key] ]
56
+ else
57
+ [ key, value ]
58
+ end
59
+ end.to_h
34
60
 
61
+ @muted = {}
35
62
  setup_output_destination
36
63
  end
37
64
 
@@ -138,45 +165,39 @@ module RSMP
138
165
  end
139
166
  log.join("\n")
140
167
  end
141
-
142
- def build_output item
143
- parts = []
144
- parts << "#{@settings['prefix']} " if @settings['prefix']
145
- parts << item[:index].to_s.ljust(7) if @settings["index"] == true
146
- parts << item[:author].to_s.ljust(13) if @settings["author"] == true
147
- parts << Clock.to_s(item[:timestamp]).ljust(24) unless @settings["timestamp"] == false
148
- parts << item[:ip].to_s.ljust(22) unless @settings["ip"] == false
149
- parts << item[:port].to_s.ljust(8) unless @settings["port"] == false
150
- parts << item[:site_id].to_s.ljust(13) unless @settings["site_id"] == false
151
- parts << item[:component_id].to_s.ljust(18) unless @settings["component"] == false
152
-
153
- directions = {in:"-->",out:"<--"}
154
- parts << directions[item[:direction]].to_s.ljust(4) unless @settings["direction"] == false
155
-
156
- parts << item[:level].to_s.capitalize.ljust(7) unless @settings["level"] == false
157
168
 
169
+ def build_part parts, item, key, &block
170
+ skey = key.to_s
171
+ return unless @settings[skey]
158
172
 
159
- unless @settings["id"] == false
160
- length = 4
161
- if item[:message]
162
- parts << Logger.shorten_message_id(item[:message].m_id,length).ljust(length)
163
- else
164
- parts << ''.ljust(length)
165
- end
166
- end
167
- parts << item[:str].to_s.strip unless @settings["text"] == false
168
- parts << item[:message].json unless @settings["json"] == false || item[:message] == nil
169
-
170
- if item[:exception]
171
- parts << "#{item[:exception].class.to_s}\n"
172
- parts << item[:exception].backtrace.join("\n")
173
- end
174
-
175
- parts.map do |s|
176
- next '-'.ljust(s.length) if s !~ /\S/ # replace the first char with a dash if string is all whitespace
177
- s
178
- end.join(' ').rstrip
173
+ part = item[key]
174
+ part = yield part if block
175
+ part = part.to_s
176
+ part = part.ljust @settings[skey] if @settings[skey].is_a?(Integer)
177
+
178
+ # replace the first char with a dash if string is all whitespace
179
+ part = @settings['tabs'].ljust(part.length) if @settings['tabs'] && part !~ /\S/
180
+ parts << part
179
181
  end
180
182
 
183
+ def build_output item
184
+ parts = []
185
+ build_part( parts, item, :prefix ) { @settings['prefix'] if @settings['prefix'] != false}
186
+ build_part( parts, item, :index )
187
+ build_part( parts, item, :author )
188
+ build_part( parts, item, :timestamp ) { |part| Clock.to_s part }
189
+ build_part( parts, item, :ip )
190
+ build_part( parts, item, :port )
191
+ build_part( parts, item, :site_id )
192
+ build_part( parts, item, :component )
193
+ build_part( parts, item, :direction ) { |part| {in:"-->",out:"<--"}[part] }
194
+ build_part( parts, item, :level ) { |part| part.capitalize }
195
+ build_part( parts, item, :id ) { Logger.shorten_message_id(item[:message].m_id,4) if item[:message] }
196
+ build_part( parts, item, :str )
197
+ build_part( parts, item, :json ) { item[:message].json if item[:message] }
198
+ build_part( parts, item, :exception ) { |e| [e.class,e.backtrace].flatten.join("\n") }
199
+
200
+ parts.join(' ').chomp(@settings['tabs']).rstrip
201
+ end
181
202
  end
182
- end
203
+ end
data/lib/rsmp/node.rb CHANGED
@@ -14,9 +14,18 @@ module RSMP
14
14
  @deferred = []
15
15
  @clock = Clock.new
16
16
  @error_queue = Async::Queue.new
17
+ @ignore_errors = []
18
+ end
19
+
20
+ def ignore_errors classes, &block
21
+ was, @ignore_errors = @ignore_errors, [classes].flatten
22
+ yield
23
+ ensure
24
+ @ignore_errors = was
17
25
  end
18
26
 
19
27
  def notify_error e, options={}
28
+ return if @ignore_errors.find { |klass| e.is_a? klass }
20
29
  if options[:level] == :internal
21
30
  log ["#{e.to_s} in task: #{Async::Task.current.to_s}",e.backtrace].flatten.join("\n"), level: :error
22
31
  end
data/lib/rsmp/proxy.rb CHANGED
@@ -86,7 +86,7 @@ module RSMP
86
86
  return if @state == :stopped
87
87
  set_state :stopping
88
88
  stop_tasks
89
- notify_error ConnectionError.new("Connection was closed")
89
+ notify_error DisonnectError.new("Connection was closed")
90
90
  ensure
91
91
  close_socket
92
92
  clear
@@ -7,6 +7,7 @@ module RSMP
7
7
  attr_reader :rsmp_versions, :site_id, :supervisor_settings, :proxies, :logger
8
8
 
9
9
  def initialize options={}
10
+
10
11
  handle_supervisor_settings( options[:supervisor_settings] || {} )
11
12
  super options
12
13
  @proxies = []
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.5.5"
2
+ VERSION = "0.6.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-09 00:00:00.000000000 Z
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  - !ruby/object:Gem::Version
259
259
  version: '0'
260
260
  requirements: []
261
- rubygems_version: 3.2.26
261
+ rubygems_version: 3.2.15
262
262
  signing_key:
263
263
  specification_version: 4
264
264
  summary: RoadSide Message Protocol (RSMP) library.