renamed importlog* to job* -- in db, python and html
This commit is contained in:
66
job.py
Normal file
66
job.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from wtforms import SubmitField, StringField, FloatField, HiddenField, validators, Form
|
||||
from flask_wtf import FlaskForm
|
||||
from flask import request, render_template, redirect
|
||||
from main import db, app, ma
|
||||
from sqlalchemy import Sequence
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from status import st, Status
|
||||
from datetime import datetime, timedelta
|
||||
import pytz
|
||||
|
||||
class Joblog(db.Model):
|
||||
id = db.Column(db.Integer, db.Sequence('ill_id_seq'), primary_key=True )
|
||||
job_id = db.Column(db.Integer, db.ForeignKey('job.id'), primary_key=True )
|
||||
log_date = db.Column(db.DateTime(timezone=True))
|
||||
log = db.Column(db.String)
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, job_id: {}, log: {}".format(self.id, self.job_id, self.log )
|
||||
|
||||
################################################################################
|
||||
# Class describing Action in the database, and via sqlalchemy, connected to the DB as well
|
||||
################################################################################
|
||||
class Job(db.Model):
|
||||
id = db.Column(db.Integer, db.Sequence('joblog_id_seq'), primary_key=True )
|
||||
start_time = db.Column(db.DateTime(timezone=True))
|
||||
last_update = db.Column(db.DateTime(timezone=True))
|
||||
state = db.Column(db.String)
|
||||
num_passes = db.Column(db.Integer)
|
||||
current_pass = db.Column(db.Integer)
|
||||
num_files = db.Column(db.Integer)
|
||||
current_file_num = db.Column(db.Integer)
|
||||
current_file = db.Column(db.String)
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, start_time: {}, last_update: {}, state: {}, num_passes: {}, current_passes: {}, num_files: {}, current_file_num: {}, current_file: {}>".format(self.id, self.start_time, self.last_update, self.state, self.num_passes, self.current_pass, self.num_files, self.num_files, self.current_file_num, self.current_file)
|
||||
|
||||
|
||||
################################################################################
|
||||
# /jobs -> show current settings
|
||||
################################################################################
|
||||
@app.route("/jobs", methods=["GET"])
|
||||
def jobs():
|
||||
page_title='Job actions'
|
||||
jobs = Job.query.all()
|
||||
return render_template("jobs.html", jobs=jobs, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
|
||||
###############################################################################
|
||||
# /job/<id> -> GET -> shows status/history of jobs
|
||||
################################################################################
|
||||
@app.route("/job/<id>", methods=["GET"])
|
||||
def joblog(id):
|
||||
page_title='Show Job Details'
|
||||
joblog = Job.query.get(id)
|
||||
logs=Joblog.query.filter(Joblog.job_id==id).all()
|
||||
duration=(datetime.now(pytz.utc)-joblog.start_time)
|
||||
duration= duration-timedelta(microseconds=duration.microseconds)
|
||||
return render_template("joblog.html", imp=joblog, logs=logs, duration=duration, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
###############################################################################
|
||||
# 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)
|
||||
################################################################################
|
||||
@app.template_filter('vicdate')
|
||||
def _jinja2_filter_datetime(date, fmt=None):
|
||||
return date.strftime("%d/%m/%Y %I:%M:%S %p")
|
||||
Reference in New Issue
Block a user