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.Database.Prelude (HasConnectionPool(..), HasConfig(..))
26 import Gargantext.Prelude
27 import Gargantext.Prelude.Config (GargConfig(..))
28 import Gargantext.Prelude.Mail.Types (MailConfig)
30 import qualified Gargantext.Utils.Jobs.Monad as Jobs
35 | UpdateNgramsListJobJSON
36 | UpdateNgramsListJobCSV
39 | DocumentFromWriteNodeJob
49 deriving (Show, Eq, Ord, Enum, Bounded)
52 { _env_settings :: !Settings
53 , _env_logger :: !LoggerSet
54 , _env_pool :: !(Pool Connection)
55 , _env_nodeStory :: !NodeStoryEnv
56 , _env_manager :: !Manager
57 , _env_self_url :: !BaseUrl
58 , _env_scrapers :: !ScrapersEnv
59 , _env_jobs :: !(Jobs.JobEnv GargJob (Dual [JobLog]) JobLog)
60 , _env_config :: !GargConfig
61 , _env_mail :: !MailConfig
67 instance HasConfig Env where
68 hasConfig = env_config
70 instance HasConnectionPool Env where
73 instance HasNodeStoryEnv Env where
74 hasNodeStory = env_nodeStory
76 instance HasNodeStoryVar Env where
77 hasNodeStoryVar = hasNodeStory . nse_getter
79 instance HasNodeStorySaver Env where
80 hasNodeStorySaver = hasNodeStory . nse_saver
82 instance HasNodeStoryImmediateSaver Env where
83 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
85 instance HasNodeArchiveStoryImmediateSaver Env where
86 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
88 instance HasSettings Env where
89 settings = env_settings
91 instance HasMail Env where
92 mailSettings = env_mail
94 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
95 _env = env_scrapers . Servant.Job.Core._env
97 instance HasJobEnv Env JobLog JobLog where
98 job_env = env_scrapers
100 instance Jobs.MonadJob (ReaderT Env (ExceptT GargError IO)) GargJob (Dual [JobLog]) JobLog where
101 getJobEnv = asks (view env_jobs)
103 data MockEnv = MockEnv
104 { _menv_firewall :: !FireWall
113 { _dev_env_settings :: !Settings
114 , _dev_env_config :: !GargConfig
115 , _dev_env_pool :: !(Pool Connection)
116 , _dev_env_nodeStory :: !NodeStoryEnv
117 , _dev_env_mail :: !MailConfig
122 instance HasConfig DevEnv where
123 hasConfig = dev_env_config
125 instance HasConnectionPool DevEnv where
126 connPool = dev_env_pool
128 instance HasSettings DevEnv where
129 settings = dev_env_settings
132 instance HasNodeStoryEnv DevEnv where
133 hasNodeStory = dev_env_nodeStory
135 instance HasNodeStoryVar DevEnv where
136 hasNodeStoryVar = hasNodeStory . nse_getter
138 instance HasNodeStorySaver DevEnv where
139 hasNodeStorySaver = hasNodeStory . nse_saver
141 instance HasNodeStoryImmediateSaver DevEnv where
142 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
144 instance HasNodeArchiveStoryImmediateSaver DevEnv where
145 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
147 instance HasMail DevEnv where
148 mailSettings = dev_env_mail