def system_spec(request): """Create trigger and request template from parameters.""" params: Tuple[Any, ...] = request.param trigger_args = params[0] req_template_args = params[1] return IntervalTrigger(**trigger_args), RequestTemplate(**req_template_args)
def test_no_namespace_job(self, system_spec): job_name = "test_no_namespace_job" job_wait = 30 template = RequestTemplate( system=system_spec["system"], system_version=system_spec["system_version"], instance_name=system_spec["instance_name"], command=system_spec["command"], parameters=system_spec["parameters"], comment=job_name + " Job", ) trigger = IntervalTrigger(seconds=job_wait) trigger.reschedule_on_finish = True job = Job( name=job_name, trigger_type="interval", trigger=trigger, request_template=template, status="RUNNING", coalesce=True, max_instances=1, ) job_response = self.easy_client.create_job(job) assert job_response is not None # Wait before checking plus a little extra time.sleep(job_wait + 15) found_jobs = self.easy_client.find_jobs(name=job_name) assert len(found_jobs) == 1 assert found_jobs[0] is not None assert found_jobs[0].success_count > 0 assert self.easy_client.remove_job(found_jobs[0].id)
def test_scheduler_kwargs_default(self): assert IntervalTrigger(timezone="utc").scheduler_kwargs == { "weeks": None, "days": None, "hours": None, "minutes": None, "seconds": None, "start_date": None, "end_date": None, "timezone": pytz.utc, "jitter": None, "reschedule_on_finish": None, }
def test_create_jobs_does_not_create_invalid_jobs(self): valid_job = BrewtilsJob( name="valid_job", trigger_type="interval", trigger=IntervalTrigger(hours=1), request_template=RequestTemplate( system="testsystem", system_version="1.2.3", instance_name="default", command="testcommand", ), ) invalid_job = BrewtilsJob(name="invalid_job") results = create_jobs([valid_job, invalid_job]) assert len(results["created"]) == 1 assert len(results["rejected"]) == 1 assert len(Job.objects.all()) == 1
def bg_interval_trigger(interval_trigger_dict, ts_dt): """An interval trigger as a model.""" dict_copy = copy.deepcopy(interval_trigger_dict) dict_copy['start_date'] = ts_dt dict_copy['end_date'] = ts_dt return IntervalTrigger(**dict_copy)
def __repr__(self): return BrewtilsIntervalTrigger.__repr__(self)