mirror of
https://github.com/vale981/stream
synced 2025-03-05 10:01:39 -05:00
some diagnosis
Still todo: real integration tests
This commit is contained in:
parent
c1a212ad7a
commit
6173ba060e
3 changed files with 36 additions and 8 deletions
|
@ -90,7 +90,7 @@
|
|||
; Error Diagnose ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn diagnose-error
|
||||
(defn diagnose-runtime-error
|
||||
"Deduces the problem from the error `message` and the process
|
||||
information `proc` and returns it.
|
||||
|
||||
|
@ -122,10 +122,37 @@
|
|||
|
||||
:else :unknown))
|
||||
|
||||
(defn diagnose-start-error
|
||||
"Deduces the problem from the error `message` and the process
|
||||
information `proc` and returns it.
|
||||
|
||||
The returned codes are:
|
||||
"
|
||||
[message _]
|
||||
(cond
|
||||
(string/includes? message "No such file") :ffmpeg-not-found
|
||||
:else :unknown))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; Monitoring ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- handle-process-error!
|
||||
[event id]
|
||||
(when-let [proc (get-process! id)]
|
||||
(let [problem
|
||||
(case (:detail-type event)
|
||||
:nonzero-exit (diagnose-runtime-error (:stderr (:details event)) proc)
|
||||
:start-failed (diagnose-start-error (:message (:details event)) proc)
|
||||
nil)]
|
||||
|
||||
(dosync
|
||||
(alter processes
|
||||
(fn [procs]
|
||||
(let [proc (get procs id)
|
||||
updated-proc (assoc proc :problems (conj (:problems proc) problem))]
|
||||
(assoc procs id updated-proc))))))))
|
||||
|
||||
(defn- put-process-event!
|
||||
[id data]
|
||||
(a/put! master-monitor {:type :process-event
|
||||
|
@ -135,12 +162,8 @@
|
|||
(defn- handle-status-event!
|
||||
"Handles status `event`s from the process with the `id`."
|
||||
[id event]
|
||||
(println "------------------------------>" event
|
||||
(case (:type event)
|
||||
:error (when (= :nonzero-exit (:detail-type :nonzero-exit))
|
||||
(when-let [proc (get-process! id)]
|
||||
(diagnose-error (:stderr (:details event)) proc)))
|
||||
:else nil))
|
||||
(case (:type event)
|
||||
:error (handle-process-error! event id))
|
||||
(put-process-event! id event))
|
||||
|
||||
;; TODO: specs
|
||||
|
|
|
@ -119,7 +119,7 @@
|
|||
(do
|
||||
(a/put! status (error-status err
|
||||
:start-failed
|
||||
:stderr err))
|
||||
:message err))
|
||||
(deliver prom {:success false :error err})
|
||||
nil)))))
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
(let [config {:cam-ip "0.0.0.0"
|
||||
:cam-rtsp-port "554"
|
||||
:profile "bla"
|
||||
:ffmpeg-path "nonex"
|
||||
:stream-server "server"
|
||||
:stream-key "key"}]
|
||||
;; TODO: proper spec testing
|
||||
|
@ -41,6 +42,10 @@
|
|||
(testing "starting a process (which will fail)"
|
||||
(is (not (:success @(p/start! proc)))))
|
||||
|
||||
(testing "problem diagnosis"
|
||||
(is ((:problems (api/get-process! (:id proc)))
|
||||
:ffmpeg-not-found)))
|
||||
|
||||
(testing "spilling junk into the monitor channel"
|
||||
(a/>!! (:monitor proc) "junk"))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue