blob: 438c25ea043c9150eee31009d05c39d68a969f5a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
module Command.Log (
LogCommand,
) where
import Control.Monad.IO.Class
import Data.Bifunctor
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.Lazy qualified as TL
import Data.Text.Lazy.IO qualified as TL
import System.FilePath
import Command
import Eval
import Job
import Job.Types
import Output
data LogCommand = LogCommand JobRef
instance Command LogCommand where
commandName _ = "log"
commandDescription _ = "Show log for the given job"
type CommandArguments LogCommand = Text
commandUsage _ = T.pack $ unlines $
[ "Usage: minici log <job ref>"
]
commandInit _ _ = LogCommand . parseJobRef
commandExec = cmdLog
cmdLog :: LogCommand -> CommandExec ()
cmdLog (LogCommand ref) = do
einput <- getEvalInput
[ jid ] <- either tfail (return . map jobId) =<<
return . either (Left . textEvalError) (first T.pack . jobsetJobsEither) =<<
liftIO (runEval (evalJobReference ref) einput)
output <- getOutput
storageDir <- getStorageDir
liftIO $ mapM_ (outputEvent output . OutputMessage . TL.toStrict) . TL.lines =<<
TL.readFile (storageDir </> jobStorageSubdir jid </> "log")
|