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
31 import Text.JSON (readJSON, showJSON, JSON)
32 import qualified Text.JSON as J
34 data OpStatus = OP_STATUS_QUEUED
41 deriving (Eq, Enum, Bounded, Show)
43 instance JSON OpStatus where
44 showJSON os = showJSON w
46 OP_STATUS_QUEUED -> "queued"
47 OP_STATUS_WAITLOCK -> "waiting"
48 OP_STATUS_CANCELING -> "canceling"
49 OP_STATUS_RUNNING -> "running"
50 OP_STATUS_CANCELED -> "canceled"
51 OP_STATUS_SUCCESS -> "success"
52 OP_STATUS_ERROR -> "error"
53 readJSON s = case readJSON s of
54 J.Ok "queued" -> J.Ok OP_STATUS_QUEUED
55 J.Ok "waiting" -> J.Ok OP_STATUS_WAITLOCK
56 J.Ok "canceling" -> J.Ok OP_STATUS_CANCELING
57 J.Ok "running" -> J.Ok OP_STATUS_RUNNING
58 J.Ok "canceled" -> J.Ok OP_STATUS_CANCELED
59 J.Ok "success" -> J.Ok OP_STATUS_SUCCESS
60 J.Ok "error" -> J.Ok OP_STATUS_ERROR
61 _ -> J.Error ("Unknown opcode status " ++ show s)
63 -- | The JobStatus data type. Note that this is ordered especially
64 -- such that greater\/lesser comparison on values of this type makes
66 data JobStatus = JOB_STATUS_QUEUED
70 | JOB_STATUS_CANCELING
73 deriving (Eq, Enum, Ord, Bounded, Show)
75 instance JSON JobStatus where
76 showJSON js = showJSON w
78 JOB_STATUS_QUEUED -> "queued"
79 JOB_STATUS_WAITLOCK -> "waiting"
80 JOB_STATUS_CANCELING -> "canceling"
81 JOB_STATUS_RUNNING -> "running"
82 JOB_STATUS_CANCELED -> "canceled"
83 JOB_STATUS_SUCCESS -> "success"
84 JOB_STATUS_ERROR -> "error"
85 readJSON s = case readJSON s of
86 J.Ok "queued" -> J.Ok JOB_STATUS_QUEUED
87 J.Ok "waiting" -> J.Ok JOB_STATUS_WAITLOCK
88 J.Ok "canceling" -> J.Ok JOB_STATUS_CANCELING
89 J.Ok "running" -> J.Ok JOB_STATUS_RUNNING
90 J.Ok "success" -> J.Ok JOB_STATUS_SUCCESS
91 J.Ok "canceled" -> J.Ok JOB_STATUS_CANCELED
92 J.Ok "error" -> J.Ok JOB_STATUS_ERROR
93 _ -> J.Error ("Unknown job status " ++ show s)