Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit dd04bd18526ecb599da914b6d02c4afead15a29c
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Fri Jul 18 14:12:05 2014 +0200
Starting state implemented, cancelling fixed
---------------------------------------------------------------
backend/backend/callback.py | 26 ++++++++++++++++++++
backend/backend/dispatcher.py | 21 +++++++++++++++-
.../coprs/views/backend_ns/backend_general.py | 19 ++++++++++++--
3 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/backend/backend/callback.py b/backend/backend/callback.py
index 0502188..d2312fe 100644
--- a/backend/backend/callback.py
+++ b/backend/backend/callback.py
@@ -34,3 +34,29 @@ class FrontendCallback(object):
return False
else:
return True
+
+
+ def build_starting(self, data):
+ headers = {"content-type": "application/json"}
+ url = "{0}/starting_build/".format(self.frontend_url)
+ auth = ("user", self.frontend_auth)
+
+ self.msg = None
+ r = None
+ try:
+ r = requests.post(url, data=json.dumps(data), auth=auth,
+ headers=headers)
+ if r.status_code != 200 or "canceled" not in r.json():
+ self.msg = "Failed to submit to frontend: {0}: {1}".format(
+ r.status_code, r.text)
+ raise requests.RequestException(self.msg)
+
+ except requests.RequestException, e:
+ self.msg = "Post request failed: {0}".format(e)
+ raise
+
+ return r.json()["canceled"]
+
+
+
+
diff --git a/backend/backend/dispatcher.py b/backend/backend/dispatcher.py
index f812379..310070b 100644
--- a/backend/backend/dispatcher.py
+++ b/backend/backend/dispatcher.py
@@ -7,6 +7,7 @@ import Queue
import json
import subprocess
import multiprocessing
+import requests
import ansible
import ansible.utils
@@ -416,6 +417,23 @@ class Worker(multiprocessing.Process):
os.unlink(job.jobfile)
+ # maybe we move this to the callback?
+ def build_starting(self, job):
+ # FIXME very bad name....
+ """ Is the build canceled? If not, set it as Starting and return
True
+ """
+ data = {"build_id": job.build_id,
+ "chroot": job.chroot}
+
+ result = None
+ try:
+ result = self.frontend_callback.build_starting(data)
+ except requests.RequestException, e:
+ raise errors.CoprWorkerError(
+ "Could not communicate to front end to submit results")
+
+ return result
+
def pkg_built_before(self, pkgs, chroot, destdir):
"""
@@ -462,7 +480,8 @@ class Worker(multiprocessing.Process):
# Checking whether the build is not cancelled
- # TODO
+ if self.build_starting(job):
+ continue
diff --git a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
index cb5839b..dd7e8c1 100644
--- a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
+++ b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
@@ -90,13 +90,26 @@ def update():
return flask.jsonify(result)
-(a)backend_ns.route("/starting_build/<build_id>/",
methods=["POST", "PUT"])
+(a)backend_ns.route("/starting_build/", methods=["POST",
"PUT"])
@misc.backend_authenticated
-def start_build(build_id):
+def starting_build():
"""
Check if the build is not cancelled and set it to running state
"""
- pass
+
+ result = {"canceled": True}
+
+ if "build_id" in flask.request.json and "chroot" in
flask.request.json:
+ build =
builds_logic.BuildsLogic.get_by_id(flask.request.json["build_id"])
+
+ if build and not build.cancelled:
+ builds_logic.BuildsLogic.update_state_from_dict(build, {
+ "chroot":
flask.request.json["chroot"],
+ "status": 6}) # starting
+ db.session.commit()
+ result["canceled"] = False
+
+ return flask.jsonify(result)