Package coprs :: Package views :: Package backend_ns :: Module backend_general
[hide private]
[frames] | no frames]

Source Code for Module coprs.views.backend_ns.backend_general

  1  import flask 
  2  import sys 
  3  import time 
  4   
  5  from coprs import db 
  6  from coprs.logic import actions_logic 
  7  from coprs.logic import builds_logic 
  8   
  9  from coprs.views import misc 
 10  from coprs.views.backend_ns import backend_ns 
 11  from whoosh.index import LockError 
12 13 14 @backend_ns.route("/waiting/") 15 @misc.backend_authenticated 16 -def waiting():
17 """ 18 Return list of waiting actions and builds. 19 """ 20 21 # models.Actions 22 actions_list = [action.to_dict( 23 options={"__columns_except__": ["result", "message", "ended_on"]}) 24 for action in actions_logic.ActionsLogic.get_waiting() 25 ] 26 27 # tasks represented by models.BuildChroot with some other stuff 28 builds_list = [ 29 { 30 "task_id": str(task.build.id)+"-"+task.mock_chroot.name, 31 "build_id": task.build.id, 32 "project_owner": task.build.copr.owner.name, 33 "project_name": task.build.copr.name, 34 "submitter": task.build.user.name, 35 "pkgs": task.build.pkgs, 36 "chroot": task.mock_chroot.name, 37 "buildroot_pkgs": task.build.copr.buildroot_pkgs(task.mock_chroot), 38 "repos": task.build.repos, 39 "memory_reqs": task.build.memory_reqs, 40 "timeout": task.build.timeout 41 } 42 for task in builds_logic.BuildsLogic.get_build_task_queue() 43 ] 44 45 return flask.jsonify({"actions": actions_list, "builds": builds_list})
46
47 48 @backend_ns.route("/update/", methods=["POST", "PUT"]) 49 @misc.backend_authenticated 50 -def update():
51 result = {} 52 53 for typ, logic_cls in [("actions", actions_logic.ActionsLogic), 54 ("builds", builds_logic.BuildsLogic)]: 55 56 if typ not in flask.request.json: 57 continue 58 59 to_update = {} 60 for obj in flask.request.json[typ]: 61 to_update[obj["id"]] = obj 62 63 existing = {} 64 for obj in logic_cls.get_by_ids(to_update.keys()).all(): 65 existing[obj.id] = obj 66 67 non_existing_ids = list(set(to_update.keys()) - set(existing.keys())) 68 69 for i, obj in existing.items(): 70 logic_cls.update_state_from_dict(obj, to_update[i]) 71 72 i = 5 73 exc_info = None 74 while i > 0: 75 try: 76 db.session.commit() 77 i = -100 78 except LockError: 79 i -= 1 80 exc_info = sys.exc_info()[2] 81 time.sleep(5) 82 if i != -100: 83 raise LockError, None, exc_info 84 85 result.update({"updated_{0}_ids".format(typ): list(existing.keys()), 86 "non_existing_{0}_ids".format(typ): non_existing_ids}) 87 88 return flask.jsonify(result)
89
90 91 @backend_ns.route("/starting_build/", methods=["POST", "PUT"]) 92 @misc.backend_authenticated 93 -def starting_build():
94 """ 95 Check if the build is not cancelled and set it to running state 96 """ 97 98 result = {"can_start": False} 99 100 if "build_id" in flask.request.json and "chroot" in flask.request.json: 101 build = builds_logic.BuildsLogic.get_by_id(flask.request.json["build_id"]) 102 103 if build and not build.canceled: 104 builds_logic.BuildsLogic.update_state_from_dict(build, { 105 "chroot": flask.request.json["chroot"], 106 "status": 6}) # starting 107 db.session.commit() 108 result["can_start"] = True 109 110 return flask.jsonify(result)
111