Fix unused-do-binds for ghc 6.12
[ganeti-local] / Ganeti / Jobs.hs
1 {-| Implementation of the job information.
2
3 -}
4
5 {-
6
7 Copyright (C) 2009 Google Inc.
8
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.
13
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.
18
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
22 02110-1301, USA.
23
24 -}
25
26 module Ganeti.Jobs
27     ( JobStatus(..)
28     ) where
29
30 import Text.JSON (readJSON, showJSON, JSON)
31 import qualified Text.JSON as J
32
33 -- | The JobStatus data type. Note that this is ordered especially
34 -- such that greater\/lesser comparison on values of this type makes
35 -- sense.
36 data JobStatus = JobQueued
37                | JobWaitLock
38                | JobRunning
39                | JobSuccess
40                | JobCanceling
41                | JobCanceled
42                | JobError
43                | JobGone
44                  deriving (Eq, Enum, Ord, Bounded, Show)
45
46 instance JSON JobStatus where
47     showJSON js = showJSON w
48         where w = case js of
49                     JobQueued -> "queued"
50                     JobWaitLock -> "waiting"
51                     JobCanceling -> "canceling"
52                     JobRunning -> "running"
53                     JobCanceled -> "canceled"
54                     JobSuccess -> "success"
55                     JobError -> "error"
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 ("Unknown job status " ++ show s)