root / Ganeti / Jobs.hs @ 8ed71b67
History | View | Annotate | Download (2.2 kB)
1 | 13b6cb3f | Iustin Pop | {-| Implementation of the job information. |
---|---|---|---|
2 | 13b6cb3f | Iustin Pop | |
3 | 13b6cb3f | Iustin Pop | -} |
4 | 13b6cb3f | Iustin Pop | |
5 | 13b6cb3f | Iustin Pop | {- |
6 | 13b6cb3f | Iustin Pop | |
7 | 13b6cb3f | Iustin Pop | Copyright (C) 2009 Google Inc. |
8 | 13b6cb3f | Iustin Pop | |
9 | 13b6cb3f | Iustin Pop | This program is free software; you can redistribute it and/or modify |
10 | 13b6cb3f | Iustin Pop | it under the terms of the GNU General Public License as published by |
11 | 13b6cb3f | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
12 | 13b6cb3f | Iustin Pop | (at your option) any later version. |
13 | 13b6cb3f | Iustin Pop | |
14 | 13b6cb3f | Iustin Pop | This program is distributed in the hope that it will be useful, but |
15 | 13b6cb3f | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | 13b6cb3f | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | 13b6cb3f | Iustin Pop | General Public License for more details. |
18 | 13b6cb3f | Iustin Pop | |
19 | 13b6cb3f | Iustin Pop | You should have received a copy of the GNU General Public License |
20 | 13b6cb3f | Iustin Pop | along with this program; if not, write to the Free Software |
21 | 13b6cb3f | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | 13b6cb3f | Iustin Pop | 02110-1301, USA. |
23 | 13b6cb3f | Iustin Pop | |
24 | 13b6cb3f | Iustin Pop | -} |
25 | 13b6cb3f | Iustin Pop | |
26 | 13b6cb3f | Iustin Pop | module Ganeti.Jobs |
27 | 13b6cb3f | Iustin Pop | ( JobStatus(..) |
28 | 13b6cb3f | Iustin Pop | ) where |
29 | 13b6cb3f | Iustin Pop | |
30 | 13b6cb3f | Iustin Pop | import Text.JSON (readJSON, showJSON, JSON) |
31 | 13b6cb3f | Iustin Pop | import qualified Text.JSON as J |
32 | 13b6cb3f | Iustin Pop | |
33 | 13b6cb3f | Iustin Pop | -- | The JobStatus data type. Note that this is ordered especially |
34 | c4ef235b | Iustin Pop | -- such that greater\/lesser comparison on values of this type makes |
35 | 13b6cb3f | Iustin Pop | -- sense. |
36 | 13b6cb3f | Iustin Pop | data JobStatus = JobQueued |
37 | 13b6cb3f | Iustin Pop | | JobWaitLock |
38 | 13b6cb3f | Iustin Pop | | JobRunning |
39 | 13b6cb3f | Iustin Pop | | JobSuccess |
40 | 13b6cb3f | Iustin Pop | | JobCanceling |
41 | 13b6cb3f | Iustin Pop | | JobCanceled |
42 | 13b6cb3f | Iustin Pop | | JobError |
43 | 13b6cb3f | Iustin Pop | | JobGone |
44 | 13b6cb3f | Iustin Pop | deriving (Eq, Enum, Ord, Bounded, Show) |
45 | 13b6cb3f | Iustin Pop | |
46 | 13b6cb3f | Iustin Pop | instance JSON JobStatus where |
47 | 13b6cb3f | Iustin Pop | showJSON js = showJSON w |
48 | 13b6cb3f | Iustin Pop | where w = case js of |
49 | 13b6cb3f | Iustin Pop | JobQueued -> "queued" |
50 | 13b6cb3f | Iustin Pop | JobWaitLock -> "waiting" |
51 | 13b6cb3f | Iustin Pop | JobCanceling -> "canceling" |
52 | 13b6cb3f | Iustin Pop | JobRunning -> "running" |
53 | 13b6cb3f | Iustin Pop | JobCanceled -> "canceled" |
54 | 13b6cb3f | Iustin Pop | JobSuccess -> "success" |
55 | 13b6cb3f | Iustin Pop | JobError -> "error" |
56 | 13b6cb3f | Iustin Pop | JobGone -> "gone" -- Fake status |
57 | 13b6cb3f | Iustin Pop | readJSON s = case readJSON s of |
58 | 13b6cb3f | Iustin Pop | J.Ok "queued" -> J.Ok JobQueued |
59 | 13b6cb3f | Iustin Pop | J.Ok "waiting" -> J.Ok JobWaitLock |
60 | 13b6cb3f | Iustin Pop | J.Ok "canceling" -> J.Ok JobCanceling |
61 | 13b6cb3f | Iustin Pop | J.Ok "running" -> J.Ok JobRunning |
62 | 13b6cb3f | Iustin Pop | J.Ok "success" -> J.Ok JobSuccess |
63 | 13b6cb3f | Iustin Pop | J.Ok "canceled" -> J.Ok JobCanceled |
64 | 13b6cb3f | Iustin Pop | J.Ok "error" -> J.Ok JobError |
65 | 13b6cb3f | Iustin Pop | _ -> J.Error ("Unkown job status " ++ show s) |