3 {-# LANGUAGE TemplateHaskell #-}
5 module Gargantext.API.Admin.EnvTypes where
8 import Control.Monad.Except
9 import Control.Monad.Reader
11 import Data.Pool (Pool)
12 import Database.PostgreSQL.Simple (Connection)
13 import GHC.Generics (Generic)
14 import Network.HTTP.Client (Manager)
15 import Servant.Client (BaseUrl)
16 import Servant.Job.Async (HasJobEnv(..), Job)
17 import System.Log.FastLogger
18 import qualified Servant.Job.Core
20 import Gargantext.API.Admin.Types
21 import Gargantext.API.Admin.Orchestrator.Types
22 import Gargantext.API.Prelude (GargError)
23 import Gargantext.Core.NodeStory
24 import Gargantext.Core.Mail.Types (HasMail, mailSettings)
25 import Gargantext.Core.NLP (NLPServerMap, HasNLPServer(..))
26 import Gargantext.Database.Prelude (HasConnectionPool(..), HasConfig(..))
27 import Gargantext.Prelude
28 import Gargantext.Prelude.Config (GargConfig(..))
29 import Gargantext.Prelude.Mail.Types (MailConfig)
31 import qualified Gargantext.Utils.Jobs.Monad as Jobs
36 | UpdateNgramsListJobJSON
37 | UpdateNgramsListJobCSV
40 | DocumentFromWriteNodeJob
50 deriving (Show, Eq, Ord, Enum, Bounded)
53 { _env_settings :: !Settings
54 , _env_logger :: !LoggerSet
55 , _env_pool :: !(Pool Connection)
56 , _env_nodeStory :: !NodeStoryEnv
57 , _env_manager :: !Manager
58 , _env_self_url :: !BaseUrl
59 , _env_scrapers :: !ScrapersEnv
60 , _env_jobs :: !(Jobs.JobEnv GargJob (Dual [JobLog]) JobLog)
61 , _env_config :: !GargConfig
62 , _env_mail :: !MailConfig
63 , _env_nlp :: !NLPServerMap
69 instance HasConfig Env where
70 hasConfig = env_config
72 instance HasConnectionPool Env where
75 instance HasNodeStoryEnv Env where
76 hasNodeStory = env_nodeStory
78 instance HasNodeStoryVar Env where
79 hasNodeStoryVar = hasNodeStory . nse_getter
81 instance HasNodeStorySaver Env where
82 hasNodeStorySaver = hasNodeStory . nse_saver
84 instance HasNodeStoryImmediateSaver Env where
85 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
87 instance HasNodeArchiveStoryImmediateSaver Env where
88 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
90 instance HasSettings Env where
91 settings = env_settings
93 instance HasMail Env where
94 mailSettings = env_mail
96 instance HasNLPServer Env where
99 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
100 _env = env_scrapers . Servant.Job.Core._env
102 instance HasJobEnv Env JobLog JobLog where
103 job_env = env_scrapers
105 instance Jobs.MonadJob (ReaderT Env (ExceptT GargError IO)) GargJob (Dual [JobLog]) JobLog where
106 getJobEnv = asks (view env_jobs)
108 data MockEnv = MockEnv
109 { _menv_firewall :: !FireWall
118 { _dev_env_settings :: !Settings
119 , _dev_env_config :: !GargConfig
120 , _dev_env_pool :: !(Pool Connection)
121 , _dev_env_nodeStory :: !NodeStoryEnv
122 , _dev_env_mail :: !MailConfig
123 , _dev_env_nlp :: !NLPServerMap
128 instance HasConfig DevEnv where
129 hasConfig = dev_env_config
131 instance HasConnectionPool DevEnv where
132 connPool = dev_env_pool
134 instance HasSettings DevEnv where
135 settings = dev_env_settings
138 instance HasNodeStoryEnv DevEnv where
139 hasNodeStory = dev_env_nodeStory
141 instance HasNodeStoryVar DevEnv where
142 hasNodeStoryVar = hasNodeStory . nse_getter
144 instance HasNodeStorySaver DevEnv where
145 hasNodeStorySaver = hasNodeStory . nse_saver
147 instance HasNodeStoryImmediateSaver DevEnv where
148 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
150 instance HasNodeArchiveStoryImmediateSaver DevEnv where
151 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
153 instance HasMail DevEnv where
154 mailSettings = dev_env_mail
156 instance HasNLPServer DevEnv where
157 nlpServer = dev_env_nlp