def __init__(self, flow, flow_detail, backend, options): self._flow = flow self._flow_detail = flow_detail self._backend = backend self._options = misc.safe_copy_dict(options) self._notifier = notifier.Notifier() self._atom_notifier = notifier.Notifier()
def __init__(self, flow, flow_detail, backend, options): self._flow = flow self._flow_detail = flow_detail self._backend = backend if not options: self._options = {} else: self._options = dict(options) self._notifier = notifier.Notifier() self._atom_notifier = notifier.Notifier()
def test_details_filter(self): call_counts = collections.defaultdict(list) def call_me_on(registered_state, state, details): call_counts[registered_state].append((state, details)) def when_red(details): return details.get('color') == 'red' notifier = nt.Notifier() call_me_on_success = functools.partial(call_me_on, states.SUCCESS) notifier.register(states.SUCCESS, call_me_on_success, details_filter=when_red) self.assertEqual(1, len(notifier)) self.assertTrue( notifier.is_registered(states.SUCCESS, call_me_on_success, details_filter=when_red)) notifier.notify(states.SUCCESS, {}) self.assertEqual(0, len(call_counts[states.SUCCESS])) notifier.notify(states.SUCCESS, {'color': 'red'}) self.assertEqual(1, len(call_counts[states.SUCCESS])) notifier.notify(states.SUCCESS, {'color': 'green'}) self.assertEqual(1, len(call_counts[states.SUCCESS]))
def test_selective_notify(self): call_counts = collections.defaultdict(list) def call_me_on(registered_state, state, details): call_counts[registered_state].append((state, details)) notifier = nt.Notifier() call_me_on_success = functools.partial(call_me_on, states.SUCCESS) notifier.register(states.SUCCESS, call_me_on_success) self.assertTrue( notifier.is_registered(states.SUCCESS, call_me_on_success)) call_me_on_any = functools.partial(call_me_on, nt.Notifier.ANY) notifier.register(nt.Notifier.ANY, call_me_on_any) self.assertTrue(notifier.is_registered(nt.Notifier.ANY, call_me_on_any)) self.assertEqual(2, len(notifier)) notifier.notify(states.SUCCESS, {}) self.assertEqual(1, len(call_counts[nt.Notifier.ANY])) self.assertEqual(1, len(call_counts[states.SUCCESS])) notifier.notify(states.FAILURE, {}) self.assertEqual(2, len(call_counts[nt.Notifier.ANY])) self.assertEqual(1, len(call_counts[states.SUCCESS])) self.assertEqual(2, len(call_counts))
def __init__(self, name, jobboard, persistence=None, engine=None, engine_options=None): self._name = name self._jobboard = jobboard self._engine = engine self._engine_options = misc.safe_copy_dict(engine_options) self._persistence = persistence self._lock = threading.RLock() self._notifier = notifier.Notifier()
def test_bad_notify(self): def call_me(state, details): pass notifier = nt.Notifier() self.assertRaises(KeyError, notifier.register, nt.Notifier.ANY, call_me, kwargs={'details': 5})
def test_notify_reset(self): def call_me(state, details): pass notifier = nt.Notifier() notifier.register(nt.Notifier.ANY, call_me) self.assertEqual(1, len(notifier)) notifier.reset() self.assertEqual(0, len(notifier))
def test_notify_called(self): call_collector = [] def call_me(state, details): call_collector.append((state, details)) notifier = nt.Notifier() notifier.register(nt.Notifier.ANY, call_me) notifier.notify(states.SUCCESS, {}) notifier.notify(states.SUCCESS, {}) self.assertEqual(2, len(call_collector)) self.assertEqual(1, len(notifier))
def test_notify_not_called(self): call_collector = [] def call_me(state, details): call_collector.append((state, details)) notifier = nt.Notifier() notifier.register(nt.Notifier.ANY, call_me) notifier.notify(nt.Notifier.ANY, {}) self.assertFalse(notifier.can_trigger_notification(nt.Notifier.ANY)) self.assertEqual(0, len(call_collector)) self.assertEqual(1, len(notifier))
def __init__(self, name, jobboard, persistence=None, engine=None, engine_options=None): self._name = name self._jobboard = jobboard self._engine = engine if not engine_options: self._engine_options = {} else: self._engine_options = engine_options.copy() self._persistence = persistence self._lock = threading.RLock() self._notifier = notifier.Notifier()
def test_notify_register_deregister(self): def call_me(state, details): pass class A(object): def call_me_too(self, state, details): pass notifier = nt.Notifier() notifier.register(nt.Notifier.ANY, call_me) a = A() notifier.register(nt.Notifier.ANY, a.call_me_too) self.assertEqual(2, len(notifier)) notifier.deregister(nt.Notifier.ANY, call_me) notifier.deregister(nt.Notifier.ANY, a.call_me_too) self.assertEqual(0, len(notifier))
def _make_runtime(self, flow, initial_state=None): compilation = compiler.PatternCompiler(flow).compile() flow_detail = pu.create_flow_detail(flow) store = storage.Storage(flow_detail) # This ensures the tasks exist in storage... for task in compilation.execution_graph: store.ensure_atom(task) if initial_state: store.set_flow_state(initial_state) task_notifier = notifier.Notifier() task_executor = executor.SerialTaskExecutor() retry_executor = executor.SerialRetryExecutor() task_executor.start() self.addCleanup(task_executor.stop) r = runtime.Runtime(compilation, store, task_notifier, task_executor, retry_executor) r.compile() return r
def _make_runtime(self, flow, initial_state=None): compilation = compiler.PatternCompiler(flow).compile() flow_detail = pu.create_flow_detail(flow) store = storage.Storage(flow_detail) nodes_iter = compilation.execution_graph.nodes_iter(data=True) for node, node_attrs in nodes_iter: if node_attrs['kind'] in ('task', 'retry'): store.ensure_atom(node) if initial_state: store.set_flow_state(initial_state) atom_notifier = notifier.Notifier() task_executor = executor.SerialTaskExecutor() retry_executor = executor.SerialRetryExecutor() task_executor.start() self.addCleanup(task_executor.stop) r = runtime.Runtime(compilation, store, atom_notifier, task_executor, retry_executor) r.compile() return r
def __init__(self, name, conf): super(NotifyingJobBoard, self).__init__(name, conf) self.notifier = notifier.Notifier()
def test_not_callable(self): notifier = nt.Notifier() self.assertRaises(ValueError, notifier.register, nt.Notifier.ANY, 2)