Skip to content

Commit

Permalink
Added support to parse mdsplode results as JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Jan 7, 2024
1 parent f200fdf commit 9cff145
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{deps, [
{lfe, "2.1.3"},
{logjam, "1.2.3"},
{erlexec, "2.0.3"}
{erlexec, "2.0.3"},
{jsx, "3.1.0"}
]}.


Expand Down
2 changes: 1 addition & 1 deletion src/poise-app.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
;;; --------------------------

(defun start (_type _args)
(logger:set_application_level 'poise 'all)
(logger:set_application_level 'poise 'info)
(logjam:set-dev-config)
(log-info "Starting poise application ...")
(poise-sup:start_link))
Expand Down
19 changes: 12 additions & 7 deletions src/poise-svr.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,24 @@
(handle_info head state)
(handle_info `#(ok ,tail) state))
;; Command-specific message handlers for mdsplode
((`#(result "pong") state)
((`#(result "ping" "pong") state)
(log-info "The mdsplode binary is alive.")
`#(noreply ,state))
((`#(result "version" ,version) state)
(log-info "The mdsplode binary version: ~s" (list version))
`#(noreply ,state))
;; Raw stdout from mdsplode
((`#(stdout ,_pid ,msg) state)
(let* ((raw (binary_to_list msg))
(result (string:trim (io_lib:format "~s" (list raw)))))
(io:format "stdout: ~p~n" (list raw))
(handle_info `#(result ,result) state)
((`#(stdout ,_pid ,json) state)
(let ((parsed (jsx:decode json '(#(labels atom)))))
(log-debug "stdout: ~p~n" (list json))
(handle_info `#(result
,(binary_to_list (mref parsed 'command))
,(binary_to_list (mref parsed 'result)))
state)
`#(noreply ,state)))
;; Raw stderr from mdsplode
((`#(stderr ,_pid ,msg) state)
(io:format "stderr: ~s~n" (list (string:trim (lists:flatten (binary_to_list msg)))))
(log-debug "stderr: ~s~n" (list (string:trim (lists:flatten (binary_to_list msg)))))
`#(noreply ,state))
((`#(EXIT ,_from normal) state)
`#(noreply ,state))
Expand Down

0 comments on commit 9cff145

Please sign in to comment.