mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[mod] merge duplicated jobs on startup
This commit is contained in:
parent
247bcb41b5
commit
0278214b4f
1 changed files with 23 additions and 0 deletions
23
run.py
23
run.py
|
@ -104,6 +104,28 @@ def reset_busy_workers():
|
||||||
Worker.update(state="available").execute()
|
Worker.update(state="available").execute()
|
||||||
|
|
||||||
|
|
||||||
|
def merge_jobs_on_startup():
|
||||||
|
task_logger.info(f"looks for jobs to merge on startup")
|
||||||
|
|
||||||
|
query = Job.select().where(Job.state == "scheduled").order_by(Job.name, -Job.id)
|
||||||
|
|
||||||
|
name_to_jobs = defaultdict(list)
|
||||||
|
|
||||||
|
for job in query:
|
||||||
|
name_to_jobs[job.name].append(job)
|
||||||
|
|
||||||
|
for jobs in name_to_jobs.values():
|
||||||
|
# keep oldest job
|
||||||
|
|
||||||
|
if jobs[:-1]:
|
||||||
|
task_logger.info(f"Merging {jobs[0].name} jobs...")
|
||||||
|
|
||||||
|
for to_delete in jobs[:-1]:
|
||||||
|
to_delete.delete_instance()
|
||||||
|
|
||||||
|
task_logger.info(f"* delete {to_delete.name} [{to_delete.id}]")
|
||||||
|
|
||||||
|
|
||||||
def set_random_day_for_monthy_job():
|
def set_random_day_for_monthy_job():
|
||||||
for repo in Repo.select().where((Repo.random_job_day == None)):
|
for repo in Repo.select().where((Repo.random_job_day == None)):
|
||||||
repo.random_job_day = random.randint(1, 28)
|
repo.random_job_day = random.randint(1, 28)
|
||||||
|
@ -552,6 +574,7 @@ def main(path_to_analyseCI, ssl=False, keyfile_path="/etc/yunohost/certs/ci-apps
|
||||||
|
|
||||||
reset_pending_jobs()
|
reset_pending_jobs()
|
||||||
reset_busy_workers()
|
reset_busy_workers()
|
||||||
|
merge_jobs_on_startup()
|
||||||
|
|
||||||
set_random_day_for_monthy_job()
|
set_random_day_for_monthy_job()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue