automation: establish an automation framework
This commit is contained in:
parent
1b53bf451c
commit
8abe5d60fa
31 changed files with 586 additions and 274 deletions
70
app/portal/automation.py
Normal file
70
app/portal/automation.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
from datetime import datetime
|
||||
|
||||
from flask import render_template, flash, Response, Blueprint
|
||||
from flask_wtf import FlaskForm
|
||||
from sqlalchemy import exc
|
||||
from wtforms import SubmitField, BooleanField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
from app.extensions import db
|
||||
from app.models.automation import Automation
|
||||
from app.portal.util import view_lifecycle, response_404
|
||||
|
||||
bp = Blueprint("automation", __name__)
|
||||
|
||||
|
||||
class EditAutomationForm(FlaskForm):
|
||||
enabled = BooleanField('Enabled')
|
||||
submit = SubmitField('Save Changes')
|
||||
|
||||
|
||||
@bp.route("/list")
|
||||
def automation_list():
|
||||
automations = Automation.query.filter(
|
||||
Automation.destroyed == None).order_by(Automation.description).all()
|
||||
return render_template("list.html.j2",
|
||||
section="automation",
|
||||
title="Automation Jobs",
|
||||
item="automation",
|
||||
items=automations)
|
||||
|
||||
|
||||
@bp.route('/edit/<automation_id>', methods=['GET', 'POST'])
|
||||
def automation_edit(automation_id):
|
||||
automation = Automation.query.filter(Automation.id == automation_id).first()
|
||||
if automation is None:
|
||||
return Response(render_template("error.html.j2",
|
||||
section="automation",
|
||||
header="404 Automation Job Not Found",
|
||||
message="The requested automation job could not be found."),
|
||||
status=404)
|
||||
form = EditAutomationForm(enabled=automation.enabled)
|
||||
if form.validate_on_submit():
|
||||
automation.enabled = form.enabled.data
|
||||
automation.updated = datetime.utcnow()
|
||||
try:
|
||||
db.session.commit()
|
||||
flash("Saved changes to bridge configuration.", "success")
|
||||
except exc.SQLAlchemyError:
|
||||
flash("An error occurred saving the changes to the bridge configuration.", "danger")
|
||||
return render_template("automation.html.j2",
|
||||
section="automation",
|
||||
automation=automation, form=form)
|
||||
|
||||
|
||||
@bp.route("/kick/<automation_id>", methods=['GET', 'POST'])
|
||||
def automation_kick(automation_id: int):
|
||||
automation = Automation.query.filter(
|
||||
Automation.id == automation_id,
|
||||
Automation.destroyed == None).first()
|
||||
if automation is None:
|
||||
return response_404("The requested bridge configuration could not be found.")
|
||||
return view_lifecycle(
|
||||
header=f"Kick automation timer?",
|
||||
message=automation.description,
|
||||
success_view="portal.automation.automation_list",
|
||||
success_message="This automation job will next run within 1 minute.",
|
||||
section="automation",
|
||||
resource=automation,
|
||||
action="kick"
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue