SYNC commit

This commit is contained in:
Felisp 2024-01-05 11:13:25 +01:00
parent 43a9781893
commit 017c18112c

View file

@ -13,7 +13,8 @@
;; along with this program. If not, see <https://www.gnu.org/licenses/>. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(ns rss-thread-watch.core (ns rss-thread-watch.core
(:require [clojure.java.io :As io] (:require [clojure.java.io :as io]
[clojure.edn :as edn]
[ring.adapter.jetty :as jetty] [ring.adapter.jetty :as jetty]
[ring.middleware.params :as rp] [ring.middleware.params :as rp]
[rss-thread-watch.watcher :as watcher] [rss-thread-watch.watcher :as watcher]
@ -45,16 +46,41 @@
(println "Error while updating cache: " e ", retrying in " (/ ms 1000 60) " minutes")))) (println "Error while updating cache: " e ", retrying in " (/ ms 1000 60) " minutes"))))
(Thread/sleep ms))))) (Thread/sleep ms)))))
(defn load-config
"Attempts to load config from file [f].
Returns loaded config map or nil if failed"
[f]
(let [fl (io/as-file f)]
(when (.exists fl)
(with-open [r (io/reader fl)]
(edn/read (java.io.PushbackReader. r))))))
(defn get-some-config
"Attempts to get config somehow,
first from command line argument
then from ./config.edn file
lastly uses default internal"
;; args do not include path to executable so first arg
;; should be config file
[cmd-args])
;; Todo: Add option to write default config to stdout
;; Todo: Discover config file if not arguments else
;; ./config.edn if not found spit error about
;; using default
(defn -main (defn -main
"Entry point, starts webserver" "Entry point, starts webserver"
[& args] [& args]
;; Parse and validate config ;; Parse and validate config
;; Think of a way to start repeated download for every catalog efficiently ;; Think of a way to start repeated download for every catalog efficiently
(let [config (get-some-config args)])
(println args)
(System/exit 0)
(set-interval (fn [] (set-interval (fn []
(println "Starting cache update") (println "Starting cache update")
(watcher/update-thread-cache! (:target CONFIG) (:starting-page CONFIG))) (watcher/update-thread-cache! (:target config) (:starting-page config)))
(* 1000 (:refresh-delay CONFIG))) (* 1000 (:refresh-delay config)))
(jetty/run-jetty (rp/wrap-params feed/http-handler) {:port (:port CONFIG) (jetty/run-jetty (rp/wrap-params feed/http-handler) {:port (:port CONFIG-DEFAULT)
:join? true})) :join? true}))
;; Docs: https://github.com/ring-clojure/ring/wiki/Getting-Started ;; Docs: https://github.com/ring-clojure/ring/wiki/Getting-Started
@ -62,7 +88,7 @@
"Development entry point" "Development entry point"
[] []
(jetty/run-jetty (rp/wrap-params #'feed/http-handler) (jetty/run-jetty (rp/wrap-params #'feed/http-handler)
{:port (:port CONFIG) {:port (:port CONFIG-DEFAULT)
;; Dont block REPL thread ;; Dont block REPL thread
:join? false})) :join? false}))
;; (repl-main) ;; (repl-main)