Commit a7ef9e77 authored by Petr Pudlak's avatar Petr Pudlak
Browse files

When jobs fail to start, include the appropriate message



Currently, when a job fails to starts, no error message is set, leading
to "OpExecError: None". Since the function already receives a message in
a ReasonElem, this patch:

- extends the reason trail message with a description of the error that
  caused the job failure and
- sets the message in the Op code result.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent c32b185e
......@@ -340,11 +340,14 @@ failJobs cfg qstate jobs = do
modifyJobs qstate $ onRunningJobs rmJobs
let trySaveJob :: JobWithStat -> ResultT String IO ()
trySaveJob = (() <$) . writeAndReplicateJob cfg qdir . jJob
reason jid = ( "gnt:daemon:luxid:startjobs"
, "job " ++ show (fromJobId jid) ++ " failed to start"
, reasonTrailTimestamp now )
failJob job = failQueuedJob (reason $ qjId job) now job
mapM_ (runResultT . trySaveJob . over jJobL failJob . fst) jobs
reason jid msg =
( "gnt:daemon:luxid:startjobs"
, "job " ++ show (fromJobId jid) ++ " failed to start: " ++ msg
, reasonTrailTimestamp now )
failJob err job = failQueuedJob (reason (qjId job) (show err)) now job
failAndSaveJobWithStat (jws, err) =
trySaveJob . over jJobL (failJob err) $ jws
mapM_ (runResultT . failAndSaveJobWithStat) jobs
logDebug $ "Failed jobs " ++ sjobs
-- | Schedule jobs to be run. This is the IO wrapper around the
......
......@@ -273,13 +273,16 @@ cancelQueuedJob now job =
let ops' = map (cancelOpCode now) $ qjOps job
in job { qjOps = ops', qjEndTimestamp = Just now }
-- | Set the state of a QueuedOpCode to canceled.
-- | Set the state of a QueuedOpCode to failed
-- and set the Op result using the given reason message.
failOpCode :: ReasonElem -> Timestamp -> QueuedOpCode -> QueuedOpCode
failOpCode reason now op =
failOpCode reason@(_, msg, _) now op =
over (qoInputL . validOpCodeL . metaParamsL . opReasonL) (++ [reason])
op { qoStatus = OP_STATUS_ERROR, qoEndTimestamp = Just now }
op { qoStatus = OP_STATUS_ERROR
, qoResult = Text.JSON.JSString . Text.JSON.toJSString $ msg
, qoEndTimestamp = Just now }
-- | Transform a QueuedJob that has not been started into its canceled form.
-- | Transform a QueuedJob that has not been started into its failed form.
failQueuedJob :: ReasonElem -> Timestamp -> QueuedJob -> QueuedJob
failQueuedJob reason now job =
let ops' = map (failOpCode reason now) $ qjOps job
......
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