def test_housekeeping_with_xtrigger_satisfied(): """The housekeeping method makes sure only satisfied xtrigger function are kept.""" xtrigger_mgr = XtriggerManager(suite="sample_suite", user="******") xtrig = SubFuncContext(label="get_name", func_name="get_name", func_args=[], func_kwargs={}) xtrigger_mgr.add_trig("get_name", xtrig) xtrig.out = "[\"True\", {\"name\": \"Yossarian\"}]" tdef = TaskDef(name="foo", rtcfg=None, run_mode="live", start_point=1, spawn_ahead=False) tdef.xtrig_labels.add("get_name") start_point = ISO8601Point('20000101T0000+05') itask = TaskProxy(tdef=tdef, start_point=start_point) xtrigger_mgr.collate([itask]) # pretend the function has been activated xtrigger_mgr.active.append(xtrig.get_signature()) xtrigger_mgr.callback(xtrig) assert xtrigger_mgr.sat_xtrig xtrigger_mgr.housekeep() # here we still have the same number as before assert xtrigger_mgr.sat_xtrig # however, we have no xclock trigger satisfied assert not xtrigger_mgr.sat_xclock
def test_housekeeping_with_xtrigger_satisfied(xtrigger_mgr): """The housekeeping method makes sure only satisfied xtrigger function are kept.""" xtrigger_mgr.validate_xtrigger = lambda *a, **k: True # Ignore validation xtrig = SubFuncContext( label="get_name", func_name="get_name", func_args=[], func_kwargs={} ) xtrigger_mgr.add_trig("get_name", xtrig, 'fdir') xtrig.out = "[\"True\", {\"name\": \"Yossarian\"}]" tdef = TaskDef( name="foo", rtcfg=None, run_mode="live", start_point=1, initial_point=1 ) init() sequence = ISO8601Sequence('P1D', '2019') tdef.xtrig_labels[sequence] = ["get_name"] start_point = ISO8601Point('2019') itask = TaskProxy(tdef, start_point) # pretend the function has been activated xtrigger_mgr.active.append(xtrig.get_signature()) xtrigger_mgr.callback(xtrig) assert xtrigger_mgr.sat_xtrig xtrigger_mgr.housekeep([itask]) # here we still have the same number as before assert xtrigger_mgr.sat_xtrig
def test_callback(xtrigger_mgr): """Test callback.""" get_name = SubFuncContext(label="get_name", func_name="get_name", func_args=[], func_kwargs={}) get_name.out = "[\"True\", \"1\"]" xtrigger_mgr.active.append(get_name.get_signature()) xtrigger_mgr.callback(get_name) # this means that the xtrigger was satisfied assert xtrigger_mgr.sat_xtrig
def test_callback(): """Test callback.""" xtrigger_mgr = XtriggerManager(suite="sample_suite", user="******") get_name = SubFuncContext(label="get_name", func_name="get_name", func_args=[], func_kwargs={}) get_name.out = "[\"True\", \"1\"]" xtrigger_mgr.active.append(get_name.get_signature()) xtrigger_mgr.callback(get_name) # this means that the xtrigger was satisfied assert xtrigger_mgr.sat_xtrig
def test_callback_invalid_json(xtrigger_mgr): """Test callback with invalid JSON.""" get_name = SubFuncContext(label="get_name", func_name="get_name", func_args=[], func_kwargs={}) get_name.out = "{no_quotes: \"mom!\"}" xtrigger_mgr.active.append(get_name.get_signature()) xtrigger_mgr.callback(get_name) # this means that the xtrigger was not satisfied # TODO: this means site admins are only aware of this if they # look at the debug log. Is that OK? assert not xtrigger_mgr.sat_xtrig
def callback(self, ctx: SubFuncContext): """Callback for asynchronous xtrigger functions. Record satisfaction status and function results dict. Args: ctx (SubFuncContext): function context Raises: ValueError: if the context given is not active """ LOG.debug(ctx) sig = ctx.get_signature() self.active.remove(sig) try: satisfied, results = json.loads(ctx.out) except (ValueError, TypeError): return LOG.debug('%s: returned %s' % (sig, results)) if satisfied: self.pflag = True self.sat_xtrig[sig] = results
def callback(self, ctx: SubFuncContext): """Callback for asynchronous xtrigger functions. Record satisfaction status and function results dict. Args: ctx (SubFuncContext): function context Raises: ValueError: if the context given is not active """ LOG.debug(ctx) sig = ctx.get_signature() self.active.remove(sig) try: satisfied, results = json.loads(ctx.out) except (ValueError, TypeError): return LOG.debug('%s: returned %s', sig, results) if satisfied: self.data_store_mgr.delta_task_xtrigger(sig, True) LOG.info('xtrigger satisfied: %s = %s', ctx.label, sig) self.sat_xtrig[sig] = results