From 23a5d2f31bcd8419dd5f09fc57855b37a5eac787 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 23 Sep 2018 10:34:21 +0200 Subject: [PATCH] [enh] avoid adding duplicated jobs --- run.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/run.py b/run.py index cbd17f8..705a0fb 100644 --- a/run.py +++ b/run.py @@ -135,8 +135,15 @@ def set_random_day_for_monthy_job(): async def create_job(app_id, app_list_name, repo, job_command_last_part): if isinstance(job_command_last_part, str): + job_name = f"{app_id} ({app_list_name})" + job_command_last_part + + # avoid scheduling twice + if Job.select().where(Job.name == job_name, Job.state == "scheduled").count() > 0: + task_logger.info(f"a job for '{job_name} is already scheduled, don't add another one") + return + job = Job.create( - name=f"{app_id} ({app_list_name})" + job_command_last_part, + name=job_name, url_or_path=repo.url, state="scheduled", ) @@ -148,8 +155,15 @@ async def create_job(app_id, app_list_name, repo, job_command_last_part): else: for i in job_command_last_part: + job_name = f"{app_id} ({app_list_name})" + i + + # avoid scheduling twice + if Job.select().where(Job.name == job_name, Job.state == "scheduled").count() > 0: + task_logger.info(f"a job for '{job_name} is already scheduled, don't add another one") + continue + job = Job.create( - name=f"{app_id} ({app_list_name})" + i, + name=job_name, url_or_path=repo.url, state="scheduled", )