def jobqueue_create(): if request.method == 'POST': jobqueue = JobQueue() jobqueue.name = request.form["name"] if request.form["parent"] != "": jobqueue.parent_jobqueue_id = request.form["parent"] if request.form["minimum_agents"] != "": jobqueue.minimum_agents = request.form["minimum_agents"] if request.form["maximum_agents"] != "": jobqueue.maximum_agents = request.form["maximum_agents"] if request.form["priority"] != "": jobqueue.priority = request.form["priority"] if request.form["weight"] != "": jobqueue.weight = request.form["weight"] db.session.add(jobqueue) db.session.flush() jobqueue.fullpath = jobqueue.path() db.session.add(jobqueue) db.session.commit() flash("Created new jobqueue \"%s\"." % jobqueue.name) return redirect(url_for("jobqueues_index_ui"), SEE_OTHER) else: jobqueues = JobQueue.query parent = request.args.get("parent", None) if parent: parent = int(parent) return render_template("pyfarm/user_interface/jobqueue_create.html", parent=parent, jobqueues=jobqueues)
def post(self): """ A ``POST`` to this endpoint will create a new job queue. .. http:post:: /api/v1/jobqueues/ HTTP/1.1 **Request** .. sourcecode:: http POST /api/v1/jobqueues/ HTTP/1.1 Accept: application/json { "name": "Test Queue" } **Response** .. sourcecode:: http HTTP/1.1 201 CREATED Content-Type: application/json { "weight": 10, "jobs": [], "minimum_agents": null, "priority": 5, "name": "Test Queue", "maximum_agents": null, "id": 1, "parent": null, "parent_jobqueue_id": null } :statuscode 201: a new job queue was created :statuscode 400: there was something wrong with the request (such as invalid columns being included) :statuscode 409: a job queue with that name already exists """ jobqueue = JobQueue.query.filter_by(name=g.json["name"]).first() if jobqueue: return (jsonify(error="Job queue %s already exists" % g.json["name"]), CONFLICT) jobqueue = JobQueue(**g.json) db.session.add(jobqueue) db.session.flush() jobqueue.fullpath = jobqueue.path() db.session.add(jobqueue) db.session.commit() jobqueue_data = jobqueue.to_dict() logger.info("Created job queue %s: %r", jobqueue.name, jobqueue_data) return jsonify(jobqueue_data), CREATED