gorg_service 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/gorg_service/message.rb +12 -17
- data/lib/gorg_service/message/error_log.rb +76 -0
- data/lib/gorg_service/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05925a6b430592a5e9c01f98423987239a0302d7
|
4
|
+
data.tar.gz: 55dd773958591108940af27364b2c5707f0d1209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a06683f30182e6942c534c87d4fecea0203ba2e869e8fa1f94ce2d824c7ec6d5454e34b189488312505973d0a6c6c24ed1b5653a2fb73e10ed93569e2334a9c0
|
7
|
+
data.tar.gz: c315f15ab148e9309252d75d4867bd929aa76e7704cf54fb3dee7afb7abbc865283d941732579fbee7217bad23ac382f9369bd04e67164cb6f5ff37bea56d32d
|
data/README.md
CHANGED
@@ -139,11 +139,26 @@ It provides the following attributes :
|
|
139
139
|
|
140
140
|
- `event` : this is the same as the routing key
|
141
141
|
- `id`: message UUID
|
142
|
-
- `errors`:
|
142
|
+
- `errors`: A list of `GorgService::Message::ErrorLog`
|
143
143
|
- `data`: `Hash` containing the data to be processed
|
144
144
|
- `creation_time`: message emission date as `DateTime`
|
145
145
|
- `sender` : message producer id
|
146
146
|
|
147
|
+
|
148
|
+
Error log structure :
|
149
|
+
|
150
|
+
- `id` : Error uuid
|
151
|
+
- `type` : Type of error (debug, info, warning, softerror, harderror)
|
152
|
+
- `sender` : Id of service emitting this error
|
153
|
+
- `message` : Error message
|
154
|
+
- `debug` : Hash containing debug infos
|
155
|
+
|
156
|
+
## To Do
|
157
|
+
|
158
|
+
- Internal logs using Logger
|
159
|
+
- Allow disable JSON Schema Validation on incomming messages
|
160
|
+
- Message and ErrorLog attributes validation
|
161
|
+
|
147
162
|
## Development
|
148
163
|
|
149
164
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/gorg_service/message.rb
CHANGED
@@ -6,6 +6,7 @@ require 'json-schema'
|
|
6
6
|
require 'securerandom'
|
7
7
|
|
8
8
|
require "gorg_service/message/json_schema"
|
9
|
+
require "gorg_service/message/error_log"
|
9
10
|
|
10
11
|
class GorgService
|
11
12
|
class Message
|
@@ -26,7 +27,7 @@ class GorgService
|
|
26
27
|
@id=id
|
27
28
|
@event=event
|
28
29
|
@data=data
|
29
|
-
@errors=errors
|
30
|
+
@errors=errors&&errors.map{|e| e.is_a?(GorgService::Message::ErrorLog) ? e : GorgService::Message::ErrorLog.parse(e)}
|
30
31
|
@creation_time=creation_time
|
31
32
|
@sender= sender
|
32
33
|
end
|
@@ -41,7 +42,7 @@ class GorgService
|
|
41
42
|
}
|
42
43
|
if errors.any?
|
43
44
|
body[:errors_count]=@errors.count
|
44
|
-
body[:errors]=@errors
|
45
|
+
body[:errors]=@errors.map{|e| e.to_h}
|
45
46
|
end
|
46
47
|
body
|
47
48
|
end
|
@@ -53,16 +54,12 @@ class GorgService
|
|
53
54
|
|
54
55
|
# Log FailError in message body
|
55
56
|
def log_error error
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
error_debug: {internal_error: error.error_raised.inspect},
|
63
|
-
}
|
64
|
-
hsh[:error_debug] = {internal_error: error.error_raised.inspect} if error.error_raised
|
65
|
-
errors<<hsh
|
57
|
+
e=GorgService::Message::ErrorLog.new(
|
58
|
+
type: error.type.downcase,
|
59
|
+
message: error.message||"",
|
60
|
+
debug: error.error_raised && {internal_error: error.error_raised.inspect}
|
61
|
+
)
|
62
|
+
errors<<e
|
66
63
|
end
|
67
64
|
|
68
65
|
### Class methods
|
@@ -78,18 +75,16 @@ class GorgService
|
|
78
75
|
|
79
76
|
JSON::Validator.validate!(GorgService::Message::JSON_SCHEMA,json_body)
|
80
77
|
|
78
|
+
puts json_body["errors"].inspect
|
79
|
+
|
81
80
|
msg=self.new(
|
82
81
|
id: json_body["event_uuid"],
|
83
82
|
event: json_body["event_name"],
|
84
83
|
data: convert_keys_to_sym(json_body["data"]),
|
85
84
|
creation_time: json_body["event_creation_time"] && DateTime.parse(json_body["event_creation_time"]),
|
86
85
|
sender: json_body["event_sender_id"],
|
87
|
-
errors: json_body["errors"]&&json_body["errors"].map{|e|
|
86
|
+
errors: json_body["errors"]&&json_body["errors"].map{|e| GorgService::Message::ErrorLog.parse(e)},
|
88
87
|
)
|
89
|
-
|
90
|
-
msg.errors=msg.errors.each do |e|
|
91
|
-
e[:timestamp]=(e[:timestamp] ? DateTime.parse(e[:timestamp]) : nil)
|
92
|
-
end
|
93
88
|
msg
|
94
89
|
rescue JSON::ParserError => e
|
95
90
|
raise GorgService::HardfailError.new(e), "Unprocessable message : Unable to parse JSON message body"
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
class GorgService
|
8
|
+
class Message
|
9
|
+
class ErrorLog
|
10
|
+
|
11
|
+
attr_accessor :type, :id, :sender, :message, :timestamp, :debug
|
12
|
+
|
13
|
+
def initialize( type: "info",
|
14
|
+
id: SecureRandom.uuid,
|
15
|
+
sender: GorgService.configuration.application_id,
|
16
|
+
message: "",
|
17
|
+
timestamp: DateTime.now,
|
18
|
+
debug: {})
|
19
|
+
@type=type
|
20
|
+
@id=id
|
21
|
+
@sender=sender
|
22
|
+
@message=message
|
23
|
+
@timestamp=timestamp
|
24
|
+
@debug=debug
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_h
|
28
|
+
h={"error_type" => type,
|
29
|
+
"error_uuid" => id,
|
30
|
+
"error_sender" => sender,
|
31
|
+
"error_message" => message,
|
32
|
+
"timestamp" => timestamp.iso8601,
|
33
|
+
}
|
34
|
+
h["error_debug"]= debug if debug
|
35
|
+
h
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_json
|
39
|
+
to_h.to_json
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def parse(obj)
|
44
|
+
obj=JSON.parse(obj) unless obj.is_a? Hash
|
45
|
+
|
46
|
+
obj=convert_keys_to_sym(obj)
|
47
|
+
|
48
|
+
self.new( type: obj[:error_type],
|
49
|
+
id: obj[:error_uuid],
|
50
|
+
sender: obj[:error_sender],
|
51
|
+
message: obj[:error_message],
|
52
|
+
timestamp: DateTime.parse(obj[:timestamp]),
|
53
|
+
debug: obj[:error_debug])
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def convert_keys_to_sym input_hash
|
60
|
+
s2s =
|
61
|
+
lambda do |h|
|
62
|
+
Hash === h ?
|
63
|
+
Hash[
|
64
|
+
h.map do |k, v|
|
65
|
+
[k.respond_to?(:to_sym) ? k.to_sym : k, s2s[v]]
|
66
|
+
end
|
67
|
+
] : h
|
68
|
+
end
|
69
|
+
s2s[input_hash]
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/gorg_service/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gorg_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Narbonne
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/gorg_service/errors.rb
|
152
152
|
- lib/gorg_service/listener.rb
|
153
153
|
- lib/gorg_service/message.rb
|
154
|
+
- lib/gorg_service/message/error_log.rb
|
154
155
|
- lib/gorg_service/message/json_schema.rb
|
155
156
|
- lib/gorg_service/message_handler.rb
|
156
157
|
- lib/gorg_service/version.rb
|