Skip to content
Snippets Groups Projects
Commit c51db5fa authored by Martin Mareš's avatar Martin Mareš
Browse files

run-jobs: Probouzení čekajících jobů jen na požádání

Jinak v testovacím prostředí spouštíme hromady jobů naplánovaných
na nějaké datum v dávné minulosti (ročník 42).
parent 297b0b21
Branches
No related tags found
1 merge request!136Joby naplánované na konkrétní čas
...@@ -7,6 +7,7 @@ import argparse ...@@ -7,6 +7,7 @@ import argparse
parser = argparse.ArgumentParser(description='Spustí joby ve frontě') 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('-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('-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() args = parser.parse_args()
...@@ -15,9 +16,11 @@ init_standalone() ...@@ -15,9 +16,11 @@ init_standalone()
if args.job is None: if args.job is None:
if args.restart: if args.restart:
die("Přepínač --restart lze použít jen s --job") die("Přepínač --restart lze použít jen s --job")
mo.jobs.process_jobs() mo.jobs.process_jobs(wake=args.wake)
else: else:
tj = mo.jobs.TheJob(args.job) tj = mo.jobs.TheJob(args.job)
if not tj.load(): if not tj.load():
die("Tento job neexistuje") die("Tento job neexistuje")
if args.wake:
tj.wake()
tj.run(restart=args.restart) tj.run(restart=args.restart)
...@@ -240,7 +240,7 @@ class TheJob: ...@@ -240,7 +240,7 @@ class TheJob:
mo.email.send_job_done_email(job) 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() sess = db.get_session()
assert hasattr(mo, 'now'), 'mo.now není nastaveno' assert hasattr(mo, 'now'), 'mo.now není nastaveno'
...@@ -259,6 +259,7 @@ def process_jobs(min_priority: int = 0): ...@@ -259,6 +259,7 @@ def process_jobs(min_priority: int = 0):
tj.expire() tj.expire()
# Probereme čekající joby, jejichž čas už přišel # Probereme čekající joby, jejichž čas už přišel
if wake:
to_wake = (sess.query(db.Job.job_id) to_wake = (sess.query(db.Job.job_id)
.filter(db.Job.state == db.JobState.waiting) .filter(db.Job.state == db.JobState.waiting)
.filter(db.Job.waiting_until < mo.now) .filter(db.Job.waiting_until < mo.now)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment