Add core program starting

This commit is contained in:
Felisp 2023-12-24 00:15:22 +01:00
parent 31ed46d6d9
commit f1276154ac

View file

@ -1,29 +1,62 @@
;; Copyright (C) 2023 Felisp
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as published by
;; the Free Software Foundation, version 3 of the License.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(ns rss-thread-watch.core
(:require [ring.adapter.jetty :as jetty])
(:require [ring.adapter.jetty :as jetty]
[ring.middleware.params :as rp]
[rss-thread-watch.watcher :as watcher]
[rss-thread-watch.feed-generator :as feed])
(:gen-class))
;; Internal default config
(def CONFIG
"Internal default config"
{:target "https://api.4chan.org/mlp/catalog.json" ;Where to download catalog from
:start-index-at 50.0 ;We will search all threads that are lower in catalog than this % value
:refresh-delay (* 60 5) ;Redownload catalog every 5 mins
:port 6969 ;Liston on 6969
})
:starting-page 7 ;only monitor threads from this from this page and up
:refresh-delay (* 60 5) ;Redownload catalog every 5 mins
:port 6969 ;Listen on 6969
})
(defn set-interval
"Calls function every ms"
[callback ms]
(future (while true (do (try
(callback)
(println "Recached")
(catch Exception e
(binding [*out* *err*]
(println "Error while updating cache: " e ", retrying in 5 minutes"))))
(Thread/sleep ms)))))
(defn -main
"Entry point, starts webserver"
[& args]
())
(defn handler [rqst]
{:status 404
:header {"Content-Type" "text/html"}
:body "No poines here ^:("})
(println "Starting on port: " (:port CONFIG)
"\nGonna recache every: " (:refresh-delay CONFIG) "s")
(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)
:join? true}))
;; Docs: https://github.com/ring-clojure/ring/wiki/Getting-Started
(defn repl-main
"Development entry point"
[]
(jetty/run-jetty handler {:port (:port CONFIG)
;; Dont block REPL thread
:join? false}))
(jetty/run-jetty (rp/wrap-params #'feed/http-handler)
{:port (:port CONFIG)
;; Dont block REPL thread
:join? false}))
;; (repl-main)