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