meshx-plugin-sdk 0.0.5 → 0.0.7
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/lib/meshx-plugin-sdk.rb +60 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3bf6ecabe26119c0568758141559606b088d74e870ea8a6c12833c54f5e4111
|
4
|
+
data.tar.gz: ba9b2f28d78e312bfe386e4498b736fdf79956564d180400026b6fc2ac0d41ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 347573dfea28927e4d53f8301a138a352fd94d18a611e30fed3587f13e45e7de2eea93fbfc2b52ad8c6a14300b144ac7f1b64d9dae00acf7361415e4def02675
|
7
|
+
data.tar.gz: 5ec0f0bfc776a00c00f5c52e2786270df76007bbe10b506bca6c5cf16316cdc4d3a2c259f9cc0ecdbd268ff94c06182942ed90b3f948a2e6b275b878ab2009b2
|
data/lib/meshx-plugin-sdk.rb
CHANGED
@@ -121,33 +121,63 @@ class Controller
|
|
121
121
|
@plugin = Plugin.new(@api, @log, @config)
|
122
122
|
end
|
123
123
|
|
124
|
+
def valid_json?(json)
|
125
|
+
JSON.parse(json)
|
126
|
+
true
|
127
|
+
rescue JSON::ParserError, TypeError => e
|
128
|
+
false
|
129
|
+
end
|
130
|
+
|
124
131
|
def run()
|
132
|
+
|
133
|
+
begin
|
134
|
+
@log.info("calling on_init()")
|
135
|
+
@plugin.on_init()
|
136
|
+
rescue StandardError => e
|
137
|
+
@log.error("error calling on_init(): #{e.message}")
|
138
|
+
end
|
139
|
+
|
140
|
+
begin
|
141
|
+
@log.info("calling on_start()")
|
142
|
+
@plugin.on_start()
|
143
|
+
rescue StandardError => e
|
144
|
+
@log.error("error calling on_start(): #{e.message}")
|
145
|
+
end
|
146
|
+
|
125
147
|
keep_reading = true
|
126
148
|
@log.info("starting controller loop")
|
127
149
|
while keep_reading
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
150
|
+
begin
|
151
|
+
rtn = @api.get_messages()
|
152
|
+
@log.info("rtn: #{rtn.message} #{rtn.error} #{rtn.exit_code}")
|
153
|
+
# convert message to fileevent
|
154
|
+
if valid_json?(rtn.message)
|
155
|
+
hash = JSON.parse()
|
156
|
+
hash["items"].each do |item|
|
157
|
+
@log.info("message kind: #{item["kind"]}")
|
158
|
+
case item["kind"]
|
159
|
+
when "FileEvent"
|
160
|
+
@log.info("FileEvent")
|
161
|
+
event = FileEvent.new(item)
|
162
|
+
@plugin.on_file_event(event)
|
163
|
+
when "FolderEvent"
|
164
|
+
@log.info("FolderEvent")
|
165
|
+
event = FolderEvent.new(item)
|
166
|
+
@plugin.on_folder_event(event)
|
167
|
+
when "CompleteEvent"
|
168
|
+
@log.info("CompleteEvent")
|
169
|
+
event = CompleteEvent.new(item)
|
170
|
+
@plugin.on_complete_event(event)
|
171
|
+
keep_reading = false
|
172
|
+
else
|
173
|
+
@log.info("unknown event kind: #{item["kind"]}")
|
174
|
+
end
|
175
|
+
end
|
148
176
|
else
|
149
|
-
@log.info("
|
150
|
-
end
|
177
|
+
@log.info("invalid message [#{rtn.message}]")
|
178
|
+
end
|
179
|
+
rescue Exception => e
|
180
|
+
@log.error("error event processing: #{e.message}")
|
151
181
|
end
|
152
182
|
end
|
153
183
|
@log.info("ending controller loop sending complete event")
|
@@ -155,6 +185,14 @@ class Controller
|
|
155
185
|
if res2.exit_code != 0
|
156
186
|
@log.error("failed to send complete event: #{res2.error} #{res2.exit_code}")
|
157
187
|
end
|
188
|
+
|
189
|
+
begin
|
190
|
+
@log.info("calling on_end()")
|
191
|
+
@plugin.on_end()
|
192
|
+
rescue StandardError => e
|
193
|
+
@log.error("error calling on_end(): #{e.message}")
|
194
|
+
end
|
195
|
+
|
158
196
|
end
|
159
197
|
end
|
160
198
|
|