root / Ganeti / Jobs.hs @ 7e98f782
History | View | Annotate | Download (2.2 kB)
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 = JOB_STATUS_QUEUED |
37 |
| JOB_STATUS_WAITLOCK |
38 |
| JOB_STATUS_RUNNING |
39 |
| JOB_STATUS_SUCCESS |
40 |
| JOB_STATUS_CANCELING |
41 |
| JOB_STATUS_CANCELED |
42 |
| JOB_STATUS_ERROR |
43 |
| JOB_STATUS_GONE |
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 |
JOB_STATUS_QUEUED -> "queued" |
50 |
JOB_STATUS_WAITLOCK -> "waiting" |
51 |
JOB_STATUS_CANCELING -> "canceling" |
52 |
JOB_STATUS_RUNNING -> "running" |
53 |
JOB_STATUS_CANCELED -> "canceled" |
54 |
JOB_STATUS_SUCCESS -> "success" |
55 |
JOB_STATUS_ERROR -> "error" |
56 |
JOB_STATUS_GONE -> "gone" -- Fake status |
57 |
readJSON s = case readJSON s of |
58 |
J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED |
59 |
J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK |
60 |
J.Ok "canceling" -> J.Ok JOB_STATUS_CANCELING |
61 |
J.Ok "running" -> J.Ok JOB_STATUS_RUNNING |
62 |
J.Ok "success" -> J.Ok JOB_STATUS_SUCCESS |
63 |
J.Ok "canceled" -> J.Ok JOB_STATUS_CANCELED |
64 |
J.Ok "error" -> J.Ok JOB_STATUS_ERROR |
65 |
_ -> J.Error ("Unknown job status " ++ show s) |