mirror of
https://github.com/vale981/stream
synced 2025-03-04 17:41:38 -05:00
use the promise returned by the start command
This commit is contained in:
parent
6d152d6795
commit
053f982a9d
2 changed files with 26 additions and 23 deletions
|
@ -35,6 +35,8 @@
|
||||||
:audio-bitrate "128k" :audio-channels 1 :audio-sampling-rate 44100
|
:audio-bitrate "128k" :audio-channels 1 :audio-sampling-rate 44100
|
||||||
:rtsp-user nil :rtsp-password nil :buffer-size "100M"})
|
:rtsp-user nil :rtsp-password nil :buffer-size "100M"})
|
||||||
|
|
||||||
|
(def ^:const +default-timeout+ 1000)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
; Utilities ;
|
; Utilities ;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -196,7 +198,7 @@
|
||||||
takes precedence.
|
takes precedence.
|
||||||
"
|
"
|
||||||
[supervisor & {:keys [event timeout matcher]
|
[supervisor & {:keys [event timeout matcher]
|
||||||
:or {timeout 1000}}]
|
:or {timeout +default-timeout+}}]
|
||||||
(let [prom (promise)]
|
(let [prom (promise)]
|
||||||
(if (and (not event) (not matcher))
|
(if (and (not event) (not matcher))
|
||||||
(throw+ {:type ::commander-error
|
(throw+ {:type ::commander-error
|
||||||
|
@ -307,39 +309,42 @@
|
||||||
|
|
||||||
(defn get-process-state!
|
(defn get-process-state!
|
||||||
"Queries wether a process is running."
|
"Queries wether a process is running."
|
||||||
[process]
|
[proc]
|
||||||
(with-process process proc
|
(sys/get-service-state! (:unit-name proc)))
|
||||||
(sys/get-service-state! (:unit-name proc))))
|
|
||||||
|
|
||||||
(defn start-process!
|
(defn start-process!
|
||||||
"Starts the service associated to the process."
|
"Starts the service associated to the process `proc` (either id or
|
||||||
[process]
|
process object). Returns a promise that resolves to event `:failed`
|
||||||
(with-process process proc
|
or `:active` or times out after `timeout` ms."
|
||||||
(sys/start-service! (:unit-name proc))))
|
([proc timeout]
|
||||||
|
(let [prom
|
||||||
|
(wait-for! (:supervisor proc)
|
||||||
|
:matcher #(some #{(:event %1)} [:active :failed]))]
|
||||||
|
(sys/start-service! (:unit-name proc))
|
||||||
|
prom))
|
||||||
|
([proc]
|
||||||
|
(start-process! process +default-timeout+)))
|
||||||
|
|
||||||
(defn stop-process!
|
(defn stop-process!
|
||||||
"Stops the service associated to the process."
|
"Stops the service associated to the process."
|
||||||
[process]
|
[proc]
|
||||||
(with-process process proc
|
(sys/stop-service! (:unit-name proc)))
|
||||||
(sys/stop-service! (:unit-name proc))))
|
|
||||||
|
|
||||||
(defn process-running?
|
(defn process-running?
|
||||||
"Queries wether a process is running."
|
"Queries wether a process is running."
|
||||||
[process]
|
[proc]
|
||||||
(= (get-process-state! process) "active"))
|
(= (get-process-state! proc) "active"))
|
||||||
|
|
||||||
(defn enable-process!
|
(defn enable-process!
|
||||||
"Enables a process."
|
"Enables a process."
|
||||||
[process]
|
[proc]
|
||||||
(with-process process proc
|
(sys/enable-service! (:unit-name proc)))
|
||||||
(sys/enable-service! (:unit-name proc))))
|
|
||||||
|
|
||||||
(defn process-enabled?
|
(defn process-enabled?
|
||||||
"Enables a process."
|
"Enables a process."
|
||||||
[process]
|
[proc]
|
||||||
(with-process process proc
|
(= (sys/get-service-file-state! (:unit-name proc))
|
||||||
(= (sys/get-service-file-state! (:unit-name proc))
|
:enabled))
|
||||||
:enabled)))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
; Init ;
|
; Init ;
|
||||||
|
|
|
@ -166,9 +166,7 @@
|
||||||
(is :loaded (api/get-process-state! proc)))
|
(is :loaded (api/get-process-state! proc)))
|
||||||
|
|
||||||
(testing "starting a process"
|
(testing "starting a process"
|
||||||
(is true (api/start-process! proc))
|
(is (not (= :timeout (:event @(api/start-process! proc))))))
|
||||||
;; now: the process ought to be **failed**
|
|
||||||
(is :failed (api/get-process-state! proc)))
|
|
||||||
|
|
||||||
(testing "waiting for the process to start"
|
(testing "waiting for the process to start"
|
||||||
(let [prom (api/wait-for!
|
(let [prom (api/wait-for!
|
||||||
|
|
Loading…
Add table
Reference in a new issue