def bg_job(job_dict, ts_dt, bg_request_template, bg_date_trigger): """A job as a model.""" dict_copy = copy.deepcopy(job_dict) dict_copy['next_run_time'] = ts_dt dict_copy['trigger'] = bg_date_trigger dict_copy['request_template'] = bg_request_template return Job(**dict_copy)
def bg_cron_job(cron_job_dict, bg_request_template, bg_cron_trigger, ts_dt): """A beer garden cron job""" dict_copy = copy.deepcopy(cron_job_dict) dict_copy['next_run_time'] = ts_dt dict_copy['trigger'] = bg_cron_trigger dict_copy['request_template'] = bg_request_template return Job(**dict_copy)
def bg_interval_job(interval_job_dict, bg_request_template, bg_interval_trigger, ts_dt): """A beer garden interval job""" dict_copy = copy.deepcopy(interval_job_dict) dict_copy["next_run_time"] = ts_dt dict_copy["trigger"] = bg_interval_trigger dict_copy["request_template"] = bg_request_template return Job(**dict_copy)
def simple_job(self): return Job( trigger_type="file", trigger=FileTrigger(pattern="do_not_care", path="./", callbacks={"on_created": True}), request_template=RequestTemplate( system="something_v3", system_version="3.0.0", instance_name="my_bg", namespace="file_testing", command="something_cool", ), name="my_simple_job", id=str(ObjectId()), )
def make_interval_job( idx: int, trigger: IntervalTrigger, request_template: RequestTemplate ) -> Job: """Create a Job from parameters.""" request_template_commented = copy.deepcopy(request_template) request_template_commented.comment = ( str.format(request_template.comment, str(idx)) + " Job" ) return Job( name=str.format(job_name_base, str(idx)), trigger_type="interval", trigger=trigger, request_template=request_template_commented, status="RUNNING", coalesce=True, max_instances=1, )
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 __repr__(self): return BrewtilsJob.__repr__(self)
def __str__(self): return BrewtilsJob.__str__(self)
def make_object(self, data): # this is necessary because everything here revolves around brewtils models return Job(**data)
def test_start_date_job(self, system_spec): job_name = "test_start_date_job" delay_start = 60 * 2 job_wait = 5 start_date = int(round((time.time() + delay_start) * 1000)) 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', output_type="STRING") trigger = CronTrigger(year="*", month="*", day="*", week="*", day_of_week="*", hour="*", minute="*", second=f"*/{job_wait}", start_date=start_date, end_date=None, jitter=None, timezone="UTC") trigger.reschedule_on_finish = True job = Job(name=job_name, trigger_type='cron', 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 # Verify it hasn't ran yet time.sleep(job_wait + 5) found_jobs = self.easy_client.find_jobs(name=job_name) if time.time() < start_date: assert found_jobs[0].success_count == 0 else: assert False # Verify that is can run time.sleep(delay_start + job_wait) 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 # Verify that the job doesn't get deleted time.sleep(job_wait) 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 > 1 assert self.easy_client.remove_job(found_jobs[0].id)
def bg_job_defns_list(job_dict_for_import): """A list of job definitions""" return [Job(**job_dict_for_import)]