Home | History | Annotate | Download | only in swarming
      1 # Copyright 2017 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 # TODO(borenet): This module was copied from build.git and heavily modified to
      7 # remove dependencies on other modules in build.git.  It belongs in a different
      8 # repo. Remove this once it has been moved.
      9 
     10 
     11 class State(object):
     12   """Copied from appengine/swarming/server/task_result.py.
     13 
     14   KEEP IN SYNC.
     15 
     16   Used to parse the 'state' value in task result.
     17   """
     18   RUNNING = 0x10    # 16
     19   PENDING = 0x20    # 32
     20   EXPIRED = 0x30    # 48
     21   TIMED_OUT = 0x40  # 64
     22   BOT_DIED = 0x50   # 80
     23   CANCELED = 0x60   # 96
     24   COMPLETED = 0x70  # 112
     25 
     26   STATES = (
     27       RUNNING, PENDING, EXPIRED, TIMED_OUT, BOT_DIED, CANCELED, COMPLETED)
     28   STATES_RUNNING = (RUNNING, PENDING)
     29   STATES_NOT_RUNNING = (EXPIRED, TIMED_OUT, BOT_DIED, CANCELED, COMPLETED)
     30   STATES_DONE = (TIMED_OUT, COMPLETED)
     31   STATES_ABANDONED = (EXPIRED, BOT_DIED, CANCELED)
     32 
     33   _NAMES = {
     34     RUNNING: 'Running',
     35     PENDING: 'Pending',
     36     EXPIRED: 'Expired',
     37     TIMED_OUT: 'Execution timed out',
     38     BOT_DIED: 'Bot died',
     39     CANCELED: 'User canceled',
     40     COMPLETED: 'Completed',
     41   }
     42 
     43   @classmethod
     44   def to_string(cls, state):
     45     """Returns a user-readable string representing a State."""
     46     return cls._NAMES[state]
     47