renamed toast.js to jobs.js and moved Job related calls to jobs.py form files.py AND get job.py to allow job_mgr msgs to go to F/E via a POST of /checkforjobs (picked up in templates/base.html). move files also calls new CheckForJobs() to pick up when move job finishes without needing a page reload
This commit is contained in:
52
job.py
52
job.py
@@ -1,16 +1,15 @@
|
||||
from wtforms import SubmitField, StringField, FloatField, HiddenField, validators, Form
|
||||
from flask_wtf import FlaskForm
|
||||
from flask import request, render_template, redirect
|
||||
from flask import request, render_template, redirect, make_response, jsonify, url_for
|
||||
from settings import Settings
|
||||
from main import db, app, ma
|
||||
from sqlalchemy import Sequence, func
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from status import st, Status
|
||||
from datetime import datetime, timedelta
|
||||
from flask_login import login_required, current_user
|
||||
import pytz
|
||||
import socket
|
||||
from shared import PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT, NEWEST_LOG_LIMIT, OLDEST_LOG_LIMIT
|
||||
from shared import PA, PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT, NEWEST_LOG_LIMIT, OLDEST_LOG_LIMIT
|
||||
from flask_login import login_required, current_user
|
||||
from sqlalchemy.dialects.postgresql import INTERVAL
|
||||
from sqlalchemy.sql.functions import concat
|
||||
@@ -63,6 +62,38 @@ class Job(db.Model):
|
||||
def __repr__(self):
|
||||
return "<id: {}, start_time: {}, last_update: {}, name: {}, state: {}, num_files: {}, current_file_num: {}, current_file: {}, pa_job_state: {}, wait_for: {}, extra: {}, logs: {}>".format(self.id, self.start_time, self.last_update, self.name, self.state, self.num_files, self.current_file_num, self.current_file, self.pa_job_state, self.wait_for, self.extra, self.logs)
|
||||
|
||||
################################################################################
|
||||
# Class describing PA_JobManager_Message and in the DB (via sqlalchemy)
|
||||
# the job manager can send a message back to the front end (this code) via the
|
||||
# DB. has to be about a specific job_id and is success/danger, etc. (alert)
|
||||
# and a message
|
||||
################################################################################
|
||||
class PA_JobManager_Message(db.Model):
|
||||
__tablename__ = "pa_job_manager_fe_message"
|
||||
id = db.Column(db.Integer, db.Sequence('pa_job_manager_fe_message_id_seq'), primary_key=True )
|
||||
job_id = db.Column(db.Integer, db.ForeignKey('job.id') )
|
||||
alert = db.Column(db.String)
|
||||
message = db.Column(db.String)
|
||||
job = db.relationship ("Job" )
|
||||
def __repr__(self):
|
||||
return f"<id: {self.id}, job_id: {self.job_id}, alert: {self.alert}, message: {self.message}, job: {self.job}"
|
||||
|
||||
|
||||
################################################################################
|
||||
# GetJM_Message: used in html to display any message for this front-end
|
||||
################################################################################
|
||||
def GetJM_Message():
|
||||
msg=PA_JobManager_Message.query.first()
|
||||
return msg
|
||||
|
||||
################################################################################
|
||||
# ClearJM_Message: used in html to clear any message just displayed
|
||||
################################################################################
|
||||
def ClearJM_Message(id):
|
||||
print("ClearJM_Message called")
|
||||
PA_JobManager_Message.query.filter(PA_JobManager_Message.id==id).delete()
|
||||
db.session.commit()
|
||||
return
|
||||
|
||||
################################################################################
|
||||
# Used in main html to show a red badge of # jobs to draw attention there are
|
||||
@@ -269,6 +300,21 @@ def joblog_search():
|
||||
return ret
|
||||
|
||||
|
||||
###############################################################################
|
||||
# / -> POST -> looks for pa_job_manager status to F/E jobs and sends json of
|
||||
# them back to F/E (called form internal/js/jobs.js:CheckForJobs()
|
||||
################################################################################
|
||||
@app.route("/checkforjobs", methods=["POST"])
|
||||
@login_required
|
||||
def CheckForJobs():
|
||||
num=GetNumActiveJobs()
|
||||
sts=[]
|
||||
print("CheckForJobs called" )
|
||||
for msg in PA_JobManager_Message.query.all():
|
||||
print("there is a PA_J_MGR status message" )
|
||||
u='<a class="link-light" href="' + url_for('joblog', id=msg.job_id) + '">Job # ' + str(msg.job_id) + '</a>: '
|
||||
sts.append( { 'message': u+msg.message, 'alert': msg.alert } )
|
||||
return make_response( jsonify( num_active_jobs=num, sts=sts ) )
|
||||
|
||||
###############################################################################
|
||||
# This func creates a new filter in jinja2 to format the time from the db in a
|
||||
|
||||
Reference in New Issue
Block a user