From ac96dea6cb2972cd421b8d1c0fa15a6a47546e8d Mon Sep 17 00:00:00 2001 From: stuebinm Date: Wed, 23 Mar 2022 02:35:58 +0100 Subject: server: add a "panic i'm on a train"-offline mode (this also adds general cli arguments, but the main point is that downloading monstrously large repositories is a silly idea when i'm on a train with surprisingly bad wifi) --- server/Main.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'server/Main.hs') diff --git a/server/Main.hs b/server/Main.hs index 60098b6..6806ee7 100644 --- a/server/Main.hs +++ b/server/Main.hs @@ -1,6 +1,9 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} @@ -39,7 +42,8 @@ import Servant (Application, Capture, type (:>)) import Servant.HTML.Lucid (HTML) import Servant.Server.StaticFiles (serveDirectoryWebApp) -import Server (JobStatus, Org (..), +import Server (CliOptions (..), + JobStatus, Org (..), ServerState, Sha1, emptyState, exneuland, interval, loadConfig, @@ -53,6 +57,8 @@ import Servant.API (Header) import Servant.API.WebSocket (WebSocketPending) import Servant.Client (ClientM, client, mkClientEnv, runClientM) +import Universum.Bool.Reexport (Bool) +import WithCli (HasArguments, withCli) type family PolyEndpoint method format payload where PolyEndpoint Get format payload = @@ -97,9 +103,11 @@ app queue = serve (Proxy @Routes) . server queue postNewMaps :: Maybe Text -> MapService -> ClientM Text postNewMaps = client (Proxy @(MapServiceAPI Post)) + + main :: IO () -main = do - config <- loadConfig "./config.toml" +main = withCli $ \CliOptions {..} -> do + config <- loadConfig (fromMaybe "./config.toml" config) state <- newMVar (emptyState config) queue :: TQueue Job <- newTQueueIO loggerMiddleware <- mkRequestLogger @@ -117,7 +125,7 @@ main = do threadDelay (view interval config * 1000000) -- TODO: what about tls / https? - whenJust (view exneuland config) $ \baseurl -> do + unless offline $ whenJust (view exneuland config) $ \baseurl -> do manager' <- newManager defaultManagerSettings updater <- async $ runStdoutLoggingT $ forever $ do done <- readMVar state @@ -129,7 +137,7 @@ main = do link updater -- spawns threads for each job in the queue - linter <- async $ void $ linterThread config queue state + linter <- async $ void $ linterThread offline config queue state link linter link poker -- cgit v1.2.3