Commit 19c6f5ad authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] Adding Schedule job to gargantext-server

parent 22b4b146
......@@ -11,29 +11,31 @@ Script to start gargantext with different modes (Dev, Prod, Mock).
-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main where
import Data.Version (showVersion)
import Data.Maybe (fromMaybe)
import Data.Text (unpack)
import qualified Paths_gargantext as PG -- cabal magic build module
import Data.Version (showVersion)
import Database.PostgreSQL.Simple.SqlQQ (sql)
import GHC.IO.Exception (IOException)
import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
import Gargantext.API.Admin.EnvTypes (DevEnv)
import Gargantext.API.Dev (withDevEnv, runCmdDev)
import Gargantext.Database.Prelude (Cmd'', Cmd, execPGSQuery)
import Gargantext.Prelude
import Options.Generic
import System.Cron.Schedule
import System.Exit (exitSuccess)
import qualified Paths_gargantext as PG -- cabal magic build module
import Gargantext.Prelude
import Gargantext.API (startGargantext, Mode(..)) -- , startGargantextMock)
--------------------------------------------------------
-- Graph Tests
--import qualified Gargantext.Graph.Utils as U
--import qualified Gargantext.Graph.Distances.Conditional as C
--import qualified Gargantext.Graph.Distances.Distributional as D
--import qualified Gargantext.Graph.Distances.Matrice as M
--------------------------------------------------------
instance ParseRecord Mode
instance ParseField Mode
......@@ -59,24 +61,44 @@ main :: IO ()
main = do
MyOptions myMode myPort myIniFile myVersion <- unwrapRecord
"Gargantext server"
---------------------------------------------------------------
if myVersion then do
putStrLn $ "Version: " <> showVersion PG.version
System.Exit.exitSuccess
else
return ()
---------------------------------------------------------------
let myPort' = case myPort of
Just p -> p
Nothing -> 8008
let start = case myMode of
Mock -> panic "[ERROR] Mock mode unsupported"
_ -> startGargantext myMode myPort' (unpack myIniFile')
where
myIniFile' = case myIniFile of
Nothing -> panic "[ERROR] gargantext.ini needed"
Just i -> i
---------------------------------------------------------------
let start = case myMode of
Mock -> panic "[ERROR] Mock mode unsupported"
_ -> startGargantext myMode myPort' (unpack myIniFile')
putStrLn $ "Starting with " <> show myMode <> " mode."
start
---------------------------------------------------------------
putStrLn $ "Starting Schedule Jobs"
withDevEnv (unpack myIniFile') $ \env -> do
tids <- execSchedule $ do
addJob (runCmdDev env refreshIndex) "5 * * * *"
putStrLn ("Refresh Index Cron Job started" <> show tids)
refreshIndex :: Cmd'' DevEnv IOException ()
refreshIndex = do
_ <- execPGSQuery [sql| refresh materialized view context_node_ngrams_view; |] ()
pure ()
This diff is collapsed.
......@@ -689,6 +689,7 @@ executable gargantext-init
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -O2 -Wmissing-signatures
build-depends:
base
, cron
, extra
, gargantext
, gargantext-prelude
......@@ -792,12 +793,14 @@ executable gargantext-server
base
, cassava
, containers
, cron
, extra
, full-text-search
, gargantext
, gargantext-prelude
, ini
, optparse-generic
, postgresql-simple
, text
, unordered-containers
, vector
......@@ -826,6 +829,7 @@ executable gargantext-upgrade
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -O2 -Wmissing-signatures
build-depends:
base
, cron
, extra
, gargantext
, gargantext-prelude
......
......@@ -330,15 +330,17 @@ executables:
- -fprof-auto
dependencies:
- base
- cassava
- containers
- cron
- full-text-search
- gargantext
- gargantext-prelude
- vector
- cassava
- ini
- optparse-generic
- postgresql-simple
- unordered-containers
- full-text-search
- vector
gargantext-cli:
main: Main.hs
......@@ -421,6 +423,7 @@ executables:
- gargantext
- gargantext-prelude
- base
- cron
gargantext-invitations:
main: Main.hs
......@@ -451,6 +454,7 @@ executables:
- gargantext-prelude
- base
- postgresql-simple
- cron
gargantext-admin:
main: Main.hs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment