3 Description : Gargantext starter
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Script to start gargantext with different modes (Dev, Prod, Mock).
14 {-# LANGUAGE QuasiQuotes #-}
15 {-# LANGUAGE StandaloneDeriving #-}
16 {-# LANGUAGE Strict #-}
17 {-# LANGUAGE TypeOperators #-}
18 {-# OPTIONS_GHC -fno-warn-orphans #-}
24 import Data.Maybe (fromMaybe)
25 import Data.Text (unpack)
26 import Data.Version (showVersion)
27 import Database.PostgreSQL.Simple.SqlQQ (sql)
28 import GHC.IO.Exception (IOException)
29 import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
30 import Gargantext.API.Admin.EnvTypes (DevEnv)
31 import Gargantext.API.Dev (withDevEnv, runCmdDev)
32 import Gargantext.Database.Prelude (Cmd'', Cmd, execPGSQuery)
33 import Gargantext.Prelude
34 import Options.Generic
35 import System.Cron.Schedule
36 import System.Exit (exitSuccess)
37 import qualified Paths_gargantext as PG -- cabal magic build module
40 instance ParseRecord Mode
41 instance ParseField Mode
42 instance ParseFields Mode
45 MyOptions { run :: w ::: Mode
46 <?> "Possible modes: Dev | Mock | Prod"
47 , port :: w ::: Maybe Int
48 <?> "By default: 8008"
49 , ini :: w ::: Maybe Text
50 <?> "Ini-file path of gargantext.ini"
51 , version :: w ::: Bool
52 <?> "Show version number and exit"
56 instance ParseRecord (MyOptions Wrapped)
57 deriving instance Show (MyOptions Unwrapped)
62 MyOptions myMode myPort myIniFile myVersion <- unwrapRecord
64 ---------------------------------------------------------------
66 putStrLn $ "Version: " <> showVersion PG.version
67 System.Exit.exitSuccess
70 ---------------------------------------------------------------
71 let myPort' = case myPort of
75 myIniFile' = case myIniFile of
76 Nothing -> panic "[ERROR] gargantext.ini needed"
79 ---------------------------------------------------------------
80 let start = case myMode of
81 Mock -> panic "[ERROR] Mock mode unsupported"
82 _ -> startGargantext myMode myPort' (unpack myIniFile')
83 putStrLn $ "Starting with " <> show myMode <> " mode."
85 ---------------------------------------------------------------
87 putStrLn $ "Starting Schedule Jobs"
89 withDevEnv (unpack myIniFile') $ \env -> do
90 tids <- execSchedule $ do
91 addJob (runCmdDev env refreshIndex) "5 * * * *"
92 putStrLn ("Refresh Index Cron Job started" <> show tids)
97 refreshIndex :: Cmd'' DevEnv IOException ()
99 _ <- execPGSQuery [sql| refresh materialized view context_node_ngrams_view; |] ()