Uniformisation of API for graph and node contexts (recv -> write), removing publication of LoopbackBag as this is not stable with current BEGIN/END implementation.
This commit is contained in:
0
bonobo/config/features.py
Normal file
0
bonobo/config/features.py
Normal file
@ -43,7 +43,7 @@ class GraphExecutionContext:
|
||||
def __iter__(self):
|
||||
yield from self.nodes
|
||||
|
||||
def recv(self, *messages):
|
||||
def write(self, *messages):
|
||||
"""Push a list of messages in the inputs of this graph's inputs, matching the output of special node "BEGIN" in
|
||||
our graph."""
|
||||
|
||||
@ -56,12 +56,12 @@ class GraphExecutionContext:
|
||||
for node in self.nodes:
|
||||
node.start()
|
||||
|
||||
def loop(self):
|
||||
# todo use strategy
|
||||
for node in self.nodes:
|
||||
node.loop()
|
||||
|
||||
def stop(self):
|
||||
# todo use strategy
|
||||
for node in self.nodes:
|
||||
node.stop()
|
||||
|
||||
def loop(self):
|
||||
# todo use strategy
|
||||
for node in self.nodes:
|
||||
node.loop()
|
||||
|
||||
@ -2,7 +2,7 @@ import traceback
|
||||
from queue import Empty
|
||||
from time import sleep
|
||||
|
||||
from bonobo.constants import INHERIT_INPUT, NOT_MODIFIED, BEGIN, END
|
||||
from bonobo.constants import INHERIT_INPUT, NOT_MODIFIED
|
||||
from bonobo.errors import InactiveReadableError, UnrecoverableError
|
||||
from bonobo.execution.base import LoopingExecutionContext
|
||||
from bonobo.structs.bags import Bag
|
||||
|
||||
@ -21,7 +21,7 @@ class ExecutorStrategy(Strategy):
|
||||
|
||||
def execute(self, graph, *args, plugins=None, services=None, **kwargs):
|
||||
context = self.create_graph_execution_context(graph, plugins=plugins, services=services)
|
||||
context.recv(BEGIN, Bag(), END)
|
||||
context.write(BEGIN, Bag(), END)
|
||||
|
||||
executor = self.create_executor()
|
||||
|
||||
@ -57,7 +57,7 @@ class ExecutorStrategy(Strategy):
|
||||
futures.append(executor.submit(_runner))
|
||||
|
||||
while context.alive:
|
||||
time.sleep(0.2)
|
||||
time.sleep(0.1)
|
||||
|
||||
for plugin_context in context.plugins:
|
||||
plugin_context.shutdown()
|
||||
|
||||
@ -6,7 +6,7 @@ from bonobo.structs.bags import Bag
|
||||
class NaiveStrategy(Strategy):
|
||||
def execute(self, graph, *args, plugins=None, **kwargs):
|
||||
context = self.create_graph_execution_context(graph, plugins=plugins)
|
||||
context.recv(BEGIN, Bag(), END)
|
||||
context.write(BEGIN, Bag(), END)
|
||||
|
||||
# TODO: how to run plugins in "naive" mode ?
|
||||
context.start()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from bonobo.structs.bags import Bag, ErrorBag, LoopbackBag
|
||||
from bonobo.structs.bags import Bag, ErrorBag
|
||||
from bonobo.structs.graphs import Graph
|
||||
from bonobo.structs.tokens import Token
|
||||
|
||||
@ -6,6 +6,5 @@ __all__ = [
|
||||
'Bag',
|
||||
'ErrorBag',
|
||||
'Graph',
|
||||
'LoopbackBag',
|
||||
'Token',
|
||||
]
|
||||
|
||||
@ -45,7 +45,7 @@ class Bag:
|
||||
def args(self):
|
||||
if self._parent is None:
|
||||
return self._args
|
||||
return (*self._parent.args, *self._args,)
|
||||
return (*self._parent.args, *self._args, )
|
||||
|
||||
@property
|
||||
def kwargs(self):
|
||||
@ -93,7 +93,7 @@ class Bag:
|
||||
|
||||
@classmethod
|
||||
def inherit(cls, *args, **kwargs):
|
||||
return cls(*args, _flags=(INHERIT_INPUT,), **kwargs)
|
||||
return cls(*args, _flags=(INHERIT_INPUT, ), **kwargs)
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, Bag) and other.args == self.args and other.kwargs == self.kwargs
|
||||
@ -109,7 +109,7 @@ class Bag:
|
||||
|
||||
|
||||
class LoopbackBag(Bag):
|
||||
default_flags = (LOOPBACK,)
|
||||
default_flags = (LOOPBACK, )
|
||||
|
||||
|
||||
class ErrorBag(Bag):
|
||||
|
||||
@ -103,8 +103,8 @@ def test_version(runner, capsys):
|
||||
def test_run_with_env(runner, capsys):
|
||||
runner(
|
||||
'run', '--quiet',
|
||||
get_examples_path('env_vars/get_passed_env.py'), '--env', 'ENV_TEST_NUMBER=123',
|
||||
'--env', 'ENV_TEST_USER=cwandrews', '--env', "ENV_TEST_STRING='my_test_string'"
|
||||
get_examples_path('env_vars/get_passed_env.py'), '--env', 'ENV_TEST_NUMBER=123', '--env',
|
||||
'ENV_TEST_USER=cwandrews', '--env', "ENV_TEST_STRING='my_test_string'"
|
||||
)
|
||||
out, err = capsys.readouterr()
|
||||
out = out.split('\n')
|
||||
|
||||
@ -62,7 +62,7 @@ def test_simple_execution_context():
|
||||
assert not ctx.started
|
||||
assert not ctx.stopped
|
||||
|
||||
ctx.recv(BEGIN, Bag(), END)
|
||||
ctx.write(BEGIN, Bag(), END)
|
||||
|
||||
assert not ctx.alive
|
||||
assert not ctx.started
|
||||
|
||||
Reference in New Issue
Block a user