]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/GraphQL/AsyncTask.hs
[graphql] more asynctask work
[gargantext.git] / src / Gargantext / API / GraphQL / AsyncTask.hs
1 {-# OPTIONS_GHC -fno-warn-unused-imports #-}
2 {-# LANGUAGE DeriveAnyClass #-}
3 {-# LANGUAGE DuplicateRecordFields #-}
4
5 module Gargantext.API.GraphQL.AsyncTask where
6
7 import Control.Concurrent.MVar (readMVar)
8 import Control.Lens
9 import Control.Monad.Base (liftBase)
10 import Control.Monad.Reader (ask, liftIO)
11 import Data.Morpheus.Types
12 ( GQLType
13 , Resolver
14 , ResolverM
15 , QUERY
16 , lift
17 )
18 import Data.Text (Text)
19 import qualified Data.Text as T
20 import Gargantext.API.Admin.Orchestrator.Types (JobLog(..))
21 import Gargantext.API.Prelude (GargM, GargError, HasJobEnv')
22 import Gargantext.Core.Mail.Types (HasMail)
23 import Gargantext.Database.Admin.Types.Node (NodeId(..))
24 import Gargantext.Database.Prelude (HasConnectionPool, HasConfig)
25 import Gargantext.Prelude
26 import GHC.Generics (Generic)
27 import Servant.Job.Async (HasJobEnv(job_env), jenv_jobs)
28 import Servant.Job.Core (env_map, env_state_mvar)
29
30 data JobLogArgs
31 = JobLogArgs
32 { job_log_id :: Int
33 } deriving (Generic, GQLType)
34
35 type GqlM e env = Resolver QUERY e (GargM env GargError)
36
37 resolveJobLogs
38 :: (HasConnectionPool env, HasConfig env, HasJobEnv' env)
39 => JobLogArgs -> GqlM e env [JobLog]
40 resolveJobLogs JobLogArgs { job_log_id } = dbJobLogs job_log_id
41
42 dbJobLogs
43 :: (HasConnectionPool env, HasConfig env, HasJobEnv' env)
44 => Int -> GqlM e env [JobLog]
45 dbJobLogs job_log_id = do
46 --getJobLogs job_log_id
47 env <- ask
48 _ <- lift $ do
49 --val <- liftBase $ readMVar $ env ^. job_env . jenv_jobs . env_state_mvar
50 let val = env ^. job_env
51 printDebug "[dbJobLogs] env ^. job_env ^. jenv_jobs" val
52 printDebug "[dbJobLogs] job_log_id" job_log_id
53 pure []