Coverage for melissa/scheduler/job.py: 78%
27 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-09-22 10:36 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-09-22 10:36 +0000
1#!/usr/bin/python3
3# Copyright (c) 2020-2022, Institut National de Recherche en Informatique et en Automatique (Inria)
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
9# * Redistributions of source code must retain the above copyright notice, this
10# list of conditions and the following disclaimer.
11#
12# * Redistributions in binary form must reproduce the above copyright notice,
13# this list of conditions and the following disclaimer in the documentation
14# and/or other materials provided with the distribution.
15#
16# * Neither the name of the copyright holder nor the names of its
17# contributors may be used to endorse or promote products derived from
18# this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31import enum
32from typing import Union
33Id = int
36@enum.unique
37class State(enum.IntEnum):
38 # do not re-order or re-assign the numeric values without some thought.
39 # the state machine must be able to detect obsolete state updates and
40 # relies on the ordering below (e.g., the job is known to be RUNNING but
41 # the batch scheduler query returned WAITING).
42 WAITING = 1
43 RUNNING = 2
44 # The job ran and the program terminated successfully.
45 TERMINATED = 3
46 # The job failed for reasons unrelated to program execution.
47 # The program may have never run.
48 ERROR = 4
49 # The job ran but the program terminated unsuccessfully.
50 FAILED = 5
52 def __str__(self) -> str:
53 return self.name
56class Job:
57 def id(self) -> Union[str, int]:
58 raise NotImplementedError("Job.id() not implemented")
60 def unique_id(self) -> Union[str, int]:
61 raise NotImplementedError("Job.unique_id() not implemented")
63 def state(self) -> State:
64 raise NotImplementedError("Job.state() not implemented")
66 def __eq__(self, other: object) -> bool:
67 if isinstance(other, Job):
68 return self.unique_id() == other.unique_id()
69 if isinstance(other, Id):
70 return self.unique_id() == other
71 assert False
72 return NotImplemented
74 def __repr__(self) -> str:
75 raise NotImplementedError("Job.__repr__() not implemented")