Cleaner Jobs API
This big commit improves the jobs API in a way that now we can completely abstract away over a JobLog
. In particular, here is the summary of what has been done:
-
Our
MonadJobStatus
has a bigger API surface, to accommodate the fact we want our API to be potentially polymorphic over theJobEventType
. Now in principle we could swap aJobLog
for something different, change it once at the instance declaration and off we go; -
We now have a minimal, yet complete API to deal with tracking progress. In particular:
-- | Start tracking a new 'JobEventType' with 'n' remaining steps.
markStarted :: Int -> JobHandle m -> m ()
-- | Mark 'n' steps of the job as succeeded, while simultaneously substracting this number
-- from the remaining steps.
markProgress :: Int -> JobHandle m -> m ()
-- | Mark 'n' step of the job as failed, while simultaneously substracting this number
-- from the remaining steps. Attach an optional error message to the failure.
markFailure :: Int -> Maybe T.Text -> JobHandle m -> m ()
-- | Finish tracking a job by marking all the remaining steps as succeeded.
markComplete :: JobHandle m -> m ()
-- | Finish tracking a job by marking all the remaining steps as failed. Attach an optional
-- message to the failure.
markFailed :: Maybe T.Text -> JobHandle m -> m ()
This allows for a clean tracking on progress, without all the visual cluttering. Practical example:
graphRecompute :: (FlowCmdM env err m, MonadJobStatus m)
=> UserId
-> NodeId
-> JobHandle m
-> m ()
graphRecompute u n jobHandle = do
markStarted 1 jobHandle
_g <- recomputeGraph u n Spinglass BridgenessMethod_Basic Nothing Nothing NgramsTerms NgramsTerms False
markComplete jobHandle
This MR could in principle be merged as-it-is, although there is a bit of repetition I had to introduce due to the runCmdGargDev
which would be nice to eliminate, but that's not a blocker for getting this MR reviewed and merged.