Commit eec3bc97 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] dev logs simulogs ok

parent 4b9fe1ab
...@@ -21,18 +21,20 @@ import Data.Swagger ...@@ -21,18 +21,20 @@ import Data.Swagger
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.API.Admin.Orchestrator.Types (JobLog(..)) import Gargantext.API.Admin.Orchestrator.Types (JobLog(..))
import Gargantext.API.Node.Corpus.New (AsyncJobs) import Gargantext.API.Node.Corpus.New (AsyncJobs)
import Gargantext.API.Prelude (GargServer{-, simuLogs-}) import Gargantext.API.Prelude (GargServer, simuLogs)
import Gargantext.Database.Action.Flow.Types (FlowCmdM) import Gargantext.Database.Action.Flow.Types (FlowCmdM)
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Prelude (Ord, Eq, (<$>), ($), liftBase, (.), Int, pure, (*), printDebug, (^)) -- (-), (^)) import Gargantext.Prelude (Ord, Eq, (<$>), ($), liftBase, (.), {-Int, pure, (*),-} printDebug, {-(^)-}) -- (-), (^))
import Prelude (Enum, Bounded, minBound, maxBound) import Prelude (Enum, Bounded, minBound, maxBound)
import Servant import Servant
import Servant.Job.Async (JobFunction(..), serveJobsAPI) import Servant.Job.Async (JobFunction(..), serveJobsAPI)
import Test.QuickCheck (elements) import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary import Test.QuickCheck.Arbitrary
import Data.Maybe (Maybe(..))
import Control.Concurrent (threadDelay) ------------------------------------------------------------------------
type API = Summary " Update node according to NodeType params"
:> AsyncJobs JobLog '[JSON] UpdateNodeParams JobLog
------------------------------------------------------------------------ ------------------------------------------------------------------------
data UpdateNodeParams = UpdateNodeParamsList { methodList :: Method } data UpdateNodeParams = UpdateNodeParamsList { methodList :: Method }
...@@ -99,7 +101,6 @@ instance Arbitrary Charts where ...@@ -99,7 +101,6 @@ instance Arbitrary Charts where
arbitrary = elements [ minBound .. maxBound ] arbitrary = elements [ minBound .. maxBound ]
------------------------------------------------------------------------ ------------------------------------------------------------------------
api :: UserId -> NodeId -> GargServer API api :: UserId -> NodeId -> GargServer API
api uId nId = api uId nId =
serveJobsAPI $ serveJobsAPI $
...@@ -111,56 +112,12 @@ api uId nId = ...@@ -111,56 +112,12 @@ api uId nId =
in updateNode uId nId p (liftBase . log') in updateNode uId nId p (liftBase . log')
) )
updateNode :: FlowCmdM env err m updateNode :: FlowCmdM env err m
=> UserId => UserId
-> NodeId -> NodeId
-> UpdateNodeParams -> UpdateNodeParams
-> (JobLog -> m ()) -> (JobLog -> m ())
-> m JobLog -> m JobLog
updateNode uId nId _p logStatus = do updateNode _uId _nId _p logStatus = do
simuLogs logStatus 10
-- Why this does not work ?
-- simuLogs logStatus 100
let
m = (10 :: Int) ^ (6 :: Int)
printDebug "updateNode xxxxxxxxxxxxxxxxxxxx" nId
--liftBase $ threadDelay ( m * 10)
logStatus $ JobLog { _scst_succeeded = Just 3
, _scst_failed = Just 0
, _scst_remaining = Just 10
, _scst_events = Just []
}
{-
status t n = do
_ <- liftBase $ threadDelay ( m * 1000)
let s = JobLog { _scst_succeeded = Just n
, _scst_failed = Just 0
, _scst_remaining = Just (t - n)
, _scst_events = Just []
}
printDebug "status " s
pure s
-}
printDebug "updateNode yyyyyyyyyyyyyyyyyyyy" uId
--liftBase $ threadDelay ( m * 10)
logStatus $ JobLog { _scst_succeeded = Just 6
, _scst_failed = Just 0
, _scst_remaining = Just 4
, _scst_events = Just []
}
printDebug "updateNode zzzzzzzzzzzzzzzzzzzz" nId
liftBase $ threadDelay ( m * 10)
pure $ JobLog { _scst_succeeded = Just 10
, _scst_failed = Just 0
, _scst_remaining = Just 0
, _scst_events = Just []
}
------------------------------------------------------------------------ ------------------------------------------------------------------------
type API = Summary " Update node according to NodeType params"
:> AsyncJobs JobLog '[JSON] UpdateNodeParams JobLog
...@@ -152,59 +152,26 @@ instance HasJoseError GargError where ...@@ -152,59 +152,26 @@ instance HasJoseError GargError where
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Utils -- | Utils
-- | Simulate logs -- | Simulate logs
simuLogs :: MonadBase IO m simuLogs :: MonadBase IO m
=> (JobLog -> m ()) => (JobLog -> m ())
-> Int -> Int
-> m JobLog -> m JobLog
simuLogs logStatus t = do simuLogs logStatus t = do
{- _ <- mapM (\n -> simuTask logStatus n t) $ take t [0,1..]
let task = JobLog { _scst_succeeded = Just 0
, _scst_failed = Just 0
, _scst_remaining = Just 0
, _scst_events = Just []
}
-}
-- f <- mapM (\status n -> simuTask logStatus status n t) task $ take t [1,2..]
_ <- mapM (\n -> simuTask' logStatus n t) $ take t [1,2..]
pure $ JobLog { _scst_succeeded = Just t pure $ JobLog { _scst_succeeded = Just t
, _scst_failed = Just 0 , _scst_failed = Just 0
, _scst_remaining = Just 0 , _scst_remaining = Just 0
, _scst_events = Just [] , _scst_events = Just []
} }
{-
simuTask :: MonadBase IO m simuTask :: MonadBase IO m
=> (JobLog -> m ())
-> JobLog
-> Int
-> Int
-> m JobLog
simuTask logStatus (JobLog _s f _r e) n t = do
let
m = (10 :: Int) ^ (6 :: Int)
_ <- liftBase $ threadDelay ( m * 10)
let status = JobLog { _scst_succeeded = Just n
, _scst_failed = f
, _scst_remaining = (-) <$> Just t <*> Just n
, _scst_events = e
}
printDebug "status" status
logStatus status
pure status
-}
simuTask' :: MonadBase IO m
=> (JobLog -> m ()) => (JobLog -> m ())
-> Int -> Int
-> Int -> Int
-> m () -> m ()
simuTask' logStatus cur total = do simuTask logStatus cur total = do
let _ <- liftBase $ threadDelay (m*5)
m = (10 :: Int) ^ (6 :: Int) where m = (10 :: Int) ^ (6 :: Int)
_ <- liftBase $ threadDelay ( m * 10)
let status = JobLog { _scst_succeeded = Just cur let status = JobLog { _scst_succeeded = Just cur
, _scst_failed = Just 0 , _scst_failed = Just 0
...@@ -214,6 +181,3 @@ simuTask' logStatus cur total = do ...@@ -214,6 +181,3 @@ simuTask' logStatus cur total = do
printDebug "status" status printDebug "status" status
logStatus status logStatus status
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