Commit b498ed42 authored by Klaus Aehlig's avatar Klaus Aehlig

Provide a function to write jobs to disk

This function writes a (non-archived) job to disk. The file
name can be computed from the job id, which is part of the job.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent ae858516
......@@ -48,6 +48,7 @@ module Ganeti.JQueue
, readSerialFromDisk
, allocateJobIds
, allocateJobId
, writeJobToDisk
) where
import Control.Concurrent.MVar
......@@ -337,6 +338,14 @@ loadJobFromDisk rootdir archived jid = do
liftM (\qj -> (qj, arch)) .
fromJResult "Parsing job file" $ Text.JSON.decode str
-- | Write a job to disk.
writeJobToDisk :: FilePath -> QueuedJob -> IO (Result ())
writeJobToDisk rootdir job = do
let filename = liveJobFile rootdir . qjId $ job
content = Text.JSON.encode . Text.JSON.showJSON $ job
tryAndLogIOError (atomicWriteFile filename content)
("Failed to write " ++ filename) Ok
-- | Read the job serial number from disk.
readSerialFromDisk :: IO (Result JobId)
readSerialFromDisk = do
......
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