From 5c840273c2348aefbda55b2bde859da8e439bda1 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Tue, 19 Jan 2021 23:33:08 +1100 Subject: [PATCH] added hidden route to wake up the job manager --- job.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/job.py b/job.py index 281ae85..edf256a 100644 --- a/job.py +++ b/job.py @@ -47,6 +47,17 @@ def GetNumActiveJobs(): ret = db.engine.execute("select count(1) from job where pa_job_state != 'Completed'").first() return ret.count +def WakePAJobManager(): + try: + print("Waking up PA Job Manager") + s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT)) + s.close() + except Exception as e: + st.SetAlert("danger") + st.SetMessage("Failed to connect to job manager, has it crashed? Exception was:{}".format(e)) + return + ############################################################################### # NewJob takes a name (which will be matched in pa_job_manager.py to run # the appropriate job - which will update the Job() until complete @@ -58,14 +69,7 @@ def NewJob(name, num_passes="1", num_files="0", wait_for=None ): db.session.add(job) db.session.commit() - try: - print("Waking up PA Job Manager") - s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT)) - s.close() - except Exception as e: - st.SetAlert("danger") - st.SetMessage("Failed to connect to job manager, has it crashed? Exception was:{}".format(e)) + WakePAJobManager() return job ################################################################################ @@ -93,6 +97,14 @@ def joblog(id): duration= duration-timedelta(microseconds=duration.microseconds) return render_template("joblog.html", job=joblog, logs=logs, duration=duration, page_title=page_title) +############################################################################### +# /job/ -> GET -> shows status/history of jobs +################################################################################ +@app.route("/wakeup", methods=["GET"]) +def wake_wrapper(): + WakePAJobManager() + return render_template("base.html") + ############################################################################### # This func creates a new filter in jinja2 to format the time from the db in a # way that is more readable (converted to local tz too)