1 {-| Implementation of the job information.
7 Copyright (C) 2009 Google Inc.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 import Text.JSON (readJSON, showJSON, JSON)
31 import qualified Text.JSON as J
33 -- | The JobStatus data type. Note that this is ordered especially
34 -- such that greater/lesser comparison on values of this type makes
36 data JobStatus = JobQueued
44 deriving (Eq, Enum, Ord, Bounded, Show)
46 instance JSON JobStatus where
47 showJSON js = showJSON w
50 JobWaitLock -> "waiting"
51 JobCanceling -> "canceling"
52 JobRunning -> "running"
53 JobCanceled -> "canceled"
54 JobSuccess -> "success"
56 JobGone -> "gone" -- Fake status
57 readJSON s = case readJSON s of
58 J.Ok "queued" -> J.Ok JobQueued
59 J.Ok "waiting" -> J.Ok JobWaitLock
60 J.Ok "canceling" -> J.Ok JobCanceling
61 J.Ok "running" -> J.Ok JobRunning
62 J.Ok "success" -> J.Ok JobSuccess
63 J.Ok "canceled" -> J.Ok JobCanceled
64 J.Ok "error" -> J.Ok JobError
65 _ -> J.Error ("Unkown job status " ++ show s)