diff --git a/bin/run-jobs b/bin/run-jobs index 2b76a58fd87399a94bdd711e9f9624075d96a9de..f0460c569239d3aaca6d8de4262068046ab4578f 100755 --- a/bin/run-jobs +++ b/bin/run-jobs @@ -7,6 +7,7 @@ import argparse parser = argparse.ArgumentParser(description='Spustí joby ve frontě') parser.add_argument('-j', '--job', type=int, metavar='ID', help='Spustí konkrétní job') parser.add_argument('-r', '--restart', default=False, action='store_true', help='Znovu spustí dokončený job') +parser.add_argument('-w', '--wake', default=False, action='store_true', help='Probudí naplánované joby, jejichž čas přišel') args = parser.parse_args() @@ -15,9 +16,11 @@ init_standalone() if args.job is None: if args.restart: die("Přepínač --restart lze použít jen s --job") - mo.jobs.process_jobs() + mo.jobs.process_jobs(wake=args.wake) else: tj = mo.jobs.TheJob(args.job) if not tj.load(): die("Tento job neexistuje") + if args.wake: + tj.wake() tj.run(restart=args.restart) diff --git a/mo/jobs/__init__.py b/mo/jobs/__init__.py index b82ac5471ce539ab881e04e8359a015e558ae024..95d6cdb669cf43431cbc388d1bdd490eceb2714c 100644 --- a/mo/jobs/__init__.py +++ b/mo/jobs/__init__.py @@ -240,7 +240,7 @@ class TheJob: mo.email.send_job_done_email(job) -def process_jobs(min_priority: int = 0): +def process_jobs(min_priority: int = 0, wake: bool = True): sess = db.get_session() assert hasattr(mo, 'now'), 'mo.now není nastaveno' @@ -259,14 +259,15 @@ def process_jobs(min_priority: int = 0): tj.expire() # Probereme čekající joby, jejichž čas už přišel - to_wake = (sess.query(db.Job.job_id) - .filter(db.Job.state == db.JobState.waiting) - .filter(db.Job.waiting_until < mo.now) - .all()) - sess.rollback() - for job_id, in to_wake: - tj = TheJob(job_id) - tj.wake() + if wake: + to_wake = (sess.query(db.Job.job_id) + .filter(db.Job.state == db.JobState.waiting) + .filter(db.Job.waiting_until < mo.now) + .all()) + sess.rollback() + for job_id, in to_wake: + tj = TheJob(job_id) + tj.wake() # Probereme joby, které by měly běžet ready = (sess.query(db.Job.job_id)