Merge release Beta 1 into stable #21
1 changed files with 31 additions and 5 deletions
|
@ -13,7 +13,8 @@
|
|||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
(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.middleware.params :as rp]
|
||||
[rss-thread-watch.watcher :as watcher]
|
||||
|
@ -45,16 +46,41 @@
|
|||
(println "Error while updating cache: " e ", retrying in " (/ ms 1000 60) " minutes"))))
|
||||
(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
|
||||
"Entry point, starts webserver"
|
||||
[& args]
|
||||
;; Parse and validate config
|
||||
;; 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 []
|
||||
(println "Starting cache update")
|
||||
(watcher/update-thread-cache! (:target CONFIG) (:starting-page CONFIG)))
|
||||
(* 1000 (:refresh-delay CONFIG)))
|
||||
(jetty/run-jetty (rp/wrap-params feed/http-handler) {:port (:port CONFIG)
|
||||
(watcher/update-thread-cache! (:target config) (:starting-page config)))
|
||||
(* 1000 (:refresh-delay config)))
|
||||
(jetty/run-jetty (rp/wrap-params feed/http-handler) {:port (:port CONFIG-DEFAULT)
|
||||
:join? true}))
|
||||
|
||||
;; Docs: https://github.com/ring-clojure/ring/wiki/Getting-Started
|
||||
|
@ -62,7 +88,7 @@
|
|||
"Development entry point"
|
||||
[]
|
||||
(jetty/run-jetty (rp/wrap-params #'feed/http-handler)
|
||||
{:port (:port CONFIG)
|
||||
{:port (:port CONFIG-DEFAULT)
|
||||
;; Dont block REPL thread
|
||||
:join? false}))
|
||||
;; (repl-main)
|
||||
|
|
Loading…
Reference in a new issue