status.py 1.6 KB
Newer Older
K
kuizhiqing 已提交
1
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2
#
K
kuizhiqing 已提交
3 4 5
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
6
#
K
kuizhiqing 已提交
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
K
kuizhiqing 已提交
9 10 11 12 13 14 15
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


16
class Status:
K
kuizhiqing 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    UNINIT = "uninit"
    READY = "ready"
    RUNNING = "running"
    FAILED = "failed"
    TERMINATING = "terminating"
    RESTARTING = "restarting"
    UNKNOWN = "unknown"
    COMPLETED = "completed"
    DONE = "done"  # should exit whatever status

    def __init__(self):
        self._current_status = None

    def current(self):
        return self._current_status

    def is_running(self):
        return self._current_status == self.RUNNING

    def is_restarting(self):
        return self._current_status == self.RESTARTING

    def is_done(self):
        if self._current_status in [self.DONE, self.COMPLETED, self.FAILED]:
            return True
        else:
            return False

    def run(self):
        self._current_status = self.RUNNING

    def fail(self):
        self._current_status = self.FAILED

    def complete(self):
        self._current_status = self.COMPLETED

    def restart(self):
        self._current_status = self.RESTARTING

    def done(self):
        self._current_status = self.DONE