Ejemplo n.º 1
0
def action_run(action_name) -> Union[Response, str]:
    action = actions.get(action_name)
    if action is None:
        abort(404)
    action_form = create_action_form(action)(request.form)
    pt_form = PeriodicTaskForm(request.form)
    if request.method == "POST":
        if request.values.get("run") and action_form.validate():
            run_action.delay(action_name, action_form.to_cmdline_dict())
            flash("Action {0} started successfully.".format(action_name),
                  "success")
            return redirect(url_for("celery_tasks.index"))
        if request.values.get(
                "schedule") and action_form.validate() and pt_form.validate():
            pt = PeriodicTask()
            pt.task = "pyfaf.celery_tasks.run_action"
            pt.args = (action_name, action_form.to_cmdline_dict())
            # populate_obj() is a method of wtforms.form.Form.
            pt_form.populate_obj(pt)  # pylint: disable=no-member
            db.session.add(pt)
            db.session.commit()
            flash("Action {0} scheduled successfully.".format(action_name),
                  "success")
            return redirect(url_for("celery_tasks.index"))
    return render_template("celery_tasks/action_run.html",
                           action_name=action_name,
                           action_form=action_form,
                           schedule_form=pt_form)
Ejemplo n.º 2
0
def action_run(action_name):
    action = actions.get(action_name)
    if action is None:
        abort(404)
    action_form = create_action_form(action)(request.form)
    pt_form = PeriodicTaskForm(request.form)
    if request.method == "POST":
        if request.values.get("run") and action_form.validate():
            run_action.delay(action_name, action_form.to_cmdline_dict())
            flash("Action {0} started successfully.".format(action_name), "success")
            return redirect(url_for("celery_tasks.index"))
        if request.values.get("schedule") and action_form.validate() and pt_form.validate():
            pt = PeriodicTask()
            pt.task = "pyfaf.celery_tasks.run_action"
            pt.args = (action_name, action_form.to_cmdline_dict())
            pt_form.populate_obj(pt)
            db.session.add(pt)
            db.session.commit()
            flash("Action {0} scheduled successfully.".format(action_name), "success")
            return redirect(url_for("celery_tasks.index"))
    return render_template(
        "celery_tasks/action_run.html", action_name=action_name, action_form=action_form, schedule_form=pt_form
    )