Quit on promise rejections.

This commit is contained in:
John Wiseman 2020-01-21 18:32:19 -08:00
parent e5dc170ca5
commit ea0bb782dc

View File

@ -502,37 +502,41 @@
(let [start-time (current-time)] (let [start-time (current-time)]
;; If --config-path is specified, definitely try to read that ;; If --config-path is specified, definitely try to read that
;; file. Otherwise, only read config.yaml if it exists. ;; file. Otherwise, only read config.yaml if it exists.
(p/let [base-config (if-let [config-path (.-config commander)] (p/try
(util/read-config config-path) (p/let [base-config (if-let [config-path (.-config commander)]
(if (fs/existsSync default-config-path) (util/read-config config-path)
(util/read-config default-config-path) (if (fs/existsSync default-config-path)
{})) (util/read-config default-config-path)
cli-config (build-config-from-commander commander) {}))
secrets (util/read-config (.-secrets commander)) cli-config (build-config-from-commander commander)
config (build-config base-config cli-config secrets) secrets (util/read-config (.-secrets commander))
db (read-history-db (:history-db-path config)) config (build-config base-config cli-config secrets)
data (get-adsbexchange-live-data db (read-history-db (:history-db-path config))
{:url (get-in config [:adsbx :url]) data (get-adsbexchange-live-data
:api-key (get-in config [:adsbx :api-key]) {:url (get-in config [:adsbx :url])
:lat (:lat config) :api-key (get-in config [:adsbx :api-key])
:lon (:lon config) :lat (:lat config)
:radius-nm (* (:radius-km config) 0.539957)}) :lon (:lon config)
now (current-time) :radius-nm (* (:radius-km config) 0.539957)})
[new-db potential-circles] (-> db now (current-time)
(update-history-db (:aircraft data) now config) [new-db potential-circles] (-> db
(detect-circles now config))] (update-history-db (:aircraft data) now config)
(p/do (detect-circles now config))]
(when potential-circles (p/do
(doseq [ac potential-circles] (when potential-circles
(log-warn "%s: New circle detected: %s" (:icao ac) (ac-desc ac))) (doseq [ac potential-circles]
(process-potential-circles potential-circles config now)) (log-warn "%s: New circle detected: %s" (:icao ac) (ac-desc ac)))
(write-history-db new-db (:history-db-path config)) (process-potential-circles potential-circles config now))
(let [end-time (current-time)] (write-history-db new-db (:history-db-path config))
(log-info (let [end-time (current-time)]
"Completed processing in %f seconds: tracking %s aircraft; %s potential circles" (log-info
(/ (- end-time start-time) 1000) "Completed processing in %f seconds: tracking %s aircraft; %s potential circles"
(count new-db) (/ (- end-time start-time) 1000)
(count potential-circles))))))) (count new-db)
(count potential-circles)))))
(p/catch :default e
(log-error "%s" (.-stack e))
(.exit js/process 1)))))
;; (.on js/process "unhandledRejection" ;; (.on js/process "unhandledRejection"