summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-07-26 16:06:03 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-07-29 10:42:02 +0100
commitb632e471f1ca4764c15534006294f7dc0b842b69 (patch)
tree0b7a1782b8e7054ba2bfb05aeeedb6f0c1e26dd6
parent0f074dd37524047cb53214be5c0f10436d3abb1d (diff)
downloadbuildstream-b632e471f1ca4764c15534006294f7dc0b842b69.tar.gz
context: Move scheduler actions to an Enum
Also add helpers for the cli to be able to represent 'FastEnum' directly
-rw-r--r--src/buildstream/_context.py4
-rw-r--r--src/buildstream/_frontend/app.py7
-rw-r--r--src/buildstream/_frontend/cli.py17
-rw-r--r--src/buildstream/types.py16
4 files changed, 38 insertions, 6 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index c18f9426d..4d68ef222 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -29,6 +29,7 @@ from ._platform import Platform
from ._artifactcache import ArtifactCache
from ._sourcecache import SourceCache
from ._cas import CASCache, CASQuota, CASCacheUsage
+from .types import _SchedulerErrorAction
from ._workspaces import Workspaces, WorkspaceProjectCache
from .node import Node
from .sandbox import SandboxRemote
@@ -323,8 +324,7 @@ class Context():
'on-error', 'fetchers', 'builders',
'pushers', 'network-retries'
])
- self.sched_error_action = _node_get_option_str(
- scheduler, 'on-error', ['continue', 'quit', 'terminate'])
+ self.sched_error_action = scheduler.get_enum('on-error', _SchedulerErrorAction)
self.sched_fetchers = scheduler.get_int('fetchers')
self.sched_builders = scheduler.get_int('builders')
self.sched_pushers = scheduler.get_int('pushers')
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py
index 76d3b8dde..379ed4b7f 100644
--- a/src/buildstream/_frontend/app.py
+++ b/src/buildstream/_frontend/app.py
@@ -37,6 +37,7 @@ from .._exceptions import BstError, StreamError, LoadError, LoadErrorReason, App
from .._message import Message, MessageType, unconditional_messages
from .._stream import Stream
from .._versions import BST_FORMAT_VERSION
+from ..types import _SchedulerErrorAction
from .. import node
# Import frontend assets
@@ -597,11 +598,11 @@ class App():
# Handle non interactive mode setting of what to do when a job fails.
if not self._interactive_failures:
- if self.context.sched_error_action == 'terminate':
+ if self.context.sched_error_action == _SchedulerErrorAction.TERMINATE:
self.stream.terminate()
- elif self.context.sched_error_action == 'quit':
+ elif self.context.sched_error_action == _SchedulerErrorAction.QUIT:
self.stream.quit()
- elif self.context.sched_error_action == 'continue':
+ elif self.context.sched_error_action == _SchedulerErrorAction.CONTINUE:
pass
return
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 12b9439cf..5de02918f 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -10,10 +10,25 @@ from .. import _yaml
from .._exceptions import BstError, LoadError, AppError
from .._versions import BST_FORMAT_VERSION
from .complete import main_bashcomplete, complete_path, CompleteUnhandled
+from ..types import _SchedulerErrorAction
from ..utils import _get_compression, UtilError
##################################################################
+# Helper classes and methods for Click #
+##################################################################
+
+class FastEnumType(click.Choice):
+
+ def __init__(self, enum):
+ self._enum = enum
+ super().__init__(enum.values())
+
+ def convert(self, value, param, ctx):
+ return self._enum(super().convert(value, param, ctx))
+
+
+##################################################################
# Override of click's main entry point #
##################################################################
@@ -234,7 +249,7 @@ def print_version(ctx, param, value):
type=click.Path(file_okay=False, readable=True),
help="Project directory (default: current directory)")
@click.option('--on-error', default=None,
- type=click.Choice(['continue', 'quit', 'terminate']),
+ type=FastEnumType(_SchedulerErrorAction),
help="What to do when an error is encountered")
@click.option('--fetchers', type=click.INT, default=None,
help="Maximum simultaneous download tasks")
diff --git a/src/buildstream/types.py b/src/buildstream/types.py
index ff4a3cc57..08e2b0d08 100644
--- a/src/buildstream/types.py
+++ b/src/buildstream/types.py
@@ -192,3 +192,19 @@ class _KeyStrength(FastEnum):
# Includes names of direct build dependencies but does not include
# cache keys of dependencies.
WEAK = 2
+
+
+# _SchedulerErrorAction()
+#
+# Actions the scheduler can take on error
+#
+class _SchedulerErrorAction(FastEnum):
+
+ # Continue building the rest of the tree
+ CONTINUE = "continue"
+
+ # finish ongoing work and quit
+ QUIT = "quit"
+
+ # Abort immediately
+ TERMINATE = "terminate"