3 {-# LANGUAGE TemplateHaskell #-}
4 {-# LANGUAGE TypeFamilies #-}
6 module Gargantext.API.Admin.EnvTypes where
9 import Control.Monad.Except
10 import Control.Monad.Reader
12 import Data.Pool (Pool)
13 import Database.PostgreSQL.Simple (Connection)
14 import GHC.Generics (Generic)
15 import Network.HTTP.Client (Manager)
16 import Servant.Client (BaseUrl)
17 import Servant.Job.Async (HasJobEnv(..), Job)
18 import System.Log.FastLogger
19 import qualified Servant.Job.Core
21 import Gargantext.API.Admin.Types
22 import Gargantext.API.Admin.Orchestrator.Types
23 import Gargantext.API.Prelude (GargError)
24 import Gargantext.Core.NodeStory
25 import Gargantext.Core.Mail.Types (HasMail, mailSettings)
26 import Gargantext.Core.NLP (NLPServerMap, HasNLPServer(..))
27 import Gargantext.Database.Prelude (HasConnectionPool(..), HasConfig(..))
28 import Gargantext.Prelude
29 import Gargantext.Prelude.Config (GargConfig(..))
30 import Gargantext.Prelude.Mail.Types (MailConfig)
32 import qualified Gargantext.Utils.Jobs.Monad as Jobs
37 | UpdateNgramsListJobJSON
38 | UpdateNgramsListJobCSV
41 | DocumentFromWriteNodeJob
51 deriving (Show, Eq, Ord, Enum, Bounded)
54 { _env_settings :: !Settings
55 , _env_logger :: !LoggerSet
56 , _env_pool :: !(Pool Connection)
57 , _env_nodeStory :: !NodeStoryEnv
58 , _env_manager :: !Manager
59 , _env_self_url :: !BaseUrl
60 , _env_scrapers :: !ScrapersEnv
61 , _env_jobs :: !(Jobs.JobEnv GargJob (Dual [JobLog]) JobLog)
62 , _env_config :: !GargConfig
63 , _env_mail :: !MailConfig
64 , _env_nlp :: !NLPServerMap
70 instance HasConfig Env where
71 hasConfig = env_config
73 instance HasConnectionPool Env where
76 instance HasNodeStoryEnv Env where
77 hasNodeStory = env_nodeStory
79 instance HasNodeStoryVar Env where
80 hasNodeStoryVar = hasNodeStory . nse_getter
82 instance HasNodeStorySaver Env where
83 hasNodeStorySaver = hasNodeStory . nse_saver
85 instance HasNodeStoryImmediateSaver Env where
86 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
88 instance HasNodeArchiveStoryImmediateSaver Env where
89 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
91 instance HasSettings Env where
92 settings = env_settings
94 instance HasMail Env where
95 mailSettings = env_mail
97 instance HasNLPServer Env where
100 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
101 _env = env_scrapers . Servant.Job.Core._env
103 instance HasJobEnv Env JobLog JobLog where
104 job_env = env_scrapers
106 instance Jobs.MonadJob (ReaderT Env (ExceptT GargError IO)) GargJob (Dual [JobLog]) JobLog where
107 getJobEnv = asks (view env_jobs)
109 instance Jobs.MonadJobStatus (ReaderT Env (ExceptT GargError IO)) Dual where
110 type JobType (ReaderT Env (ExceptT GargError IO)) = GargJob
111 type JobOutputType (ReaderT Env (ExceptT GargError IO)) = JobLog
112 type JobEventType (ReaderT Env (ExceptT GargError IO)) = JobLog
113 type JobErrorType (ReaderT Env (ExceptT GargError IO)) = GargError
115 data MockEnv = MockEnv
116 { _menv_firewall :: !FireWall
125 { _dev_env_settings :: !Settings
126 , _dev_env_config :: !GargConfig
127 , _dev_env_pool :: !(Pool Connection)
128 , _dev_env_nodeStory :: !NodeStoryEnv
129 , _dev_env_mail :: !MailConfig
130 , _dev_env_nlp :: !NLPServerMap
135 instance HasConfig DevEnv where
136 hasConfig = dev_env_config
138 instance HasConnectionPool DevEnv where
139 connPool = dev_env_pool
141 instance HasSettings DevEnv where
142 settings = dev_env_settings
145 instance HasNodeStoryEnv DevEnv where
146 hasNodeStory = dev_env_nodeStory
148 instance HasNodeStoryVar DevEnv where
149 hasNodeStoryVar = hasNodeStory . nse_getter
151 instance HasNodeStorySaver DevEnv where
152 hasNodeStorySaver = hasNodeStory . nse_saver
154 instance HasNodeStoryImmediateSaver DevEnv where
155 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
157 instance HasNodeArchiveStoryImmediateSaver DevEnv where
158 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
160 instance HasMail DevEnv where
161 mailSettings = dev_env_mail
163 instance HasNLPServer DevEnv where
164 nlpServer = dev_env_nlp