Skip to content
Snippets Groups Projects
Commit fd958a3d authored by Iustin Pop's avatar Iustin Pop
Browse files

Abstract code related to job ID creation


Having makeJobIdS as a separate function will allow us to use it
outside of json encoding.

The patch also exports one more function from the Types module.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 4355b2de
No related branches found
No related tags found
No related merge requests found
......@@ -82,10 +82,12 @@ module Ganeti.Types
, JobId
, fromJobId
, makeJobId
, makeJobIdS
, RelativeJobId
, JobIdDep(..)
, JobDependency(..)
, OpSubmitPriority(..)
, opSubmitPriorityToRaw
, OpStatus(..)
, opStatusToRaw
, opStatusFromRaw
......@@ -402,10 +404,13 @@ makeJobId :: (Monad m) => Int -> m JobId
makeJobId i | i >= 0 = return $ JobId i
| otherwise = fail $ "Invalid value for job ID ' " ++ show i ++ "'"
-- | Builds a job ID from a string.
makeJobIdS :: (Monad m) => String -> m JobId
makeJobIdS s = tryRead "parsing job id" s >>= makeJobId
-- | Parses a job ID.
parseJobId :: (Monad m) => JSON.JSValue -> m JobId
parseJobId (JSON.JSString x) =
tryRead "parsing job id" (JSON.fromJSString x) >>= makeJobId
parseJobId (JSON.JSString x) = makeJobIdS $ JSON.fromJSString x
parseJobId (JSON.JSRational _ x) =
if denominator x /= 1
then fail $ "Got fractional job ID from master daemon?! Value:" ++ show x
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment