@@ -34,28 +34,37 @@ def push_repo():
3434 raise ApiError (message = "Error in cloning the repo" , status_code = 400 ,
3535 details = "Error cloning the repo due to invalid repo URL" )
3636 parsed_url = GitHelper .parse_git_url (repo .repo )
37+ # if the key is already present, status API could give stale data
38+ # resetting the keys' values mitigates the issue
39+ reset_if_exists (parsed_url .name )
3740
38- cloned_repo = clone_repo (parsed_url , repo )
39-
40- logger .info ("starting upload of repo=" + repo .repo + " (local dir=" + cloned_repo .working_dir )
41- executor .submit (upload_repo , cloned_repo , parsed_url .repo )
42-
41+ executor .submit (clone_repo , parsed_url .name , parsed_url .url , repo .branch )
4342 return jsonify ({"status_key" : parsed_url .repo }), 202
4443
4544
46- def clone_repo (parsed_url , repo ):
45+ def clone_repo (repo_name , repo_url , branch ):
4746 try :
48- MessageHelper .publish (parsed_url .repo , json .dumps ({"current_status" : "Cloning repo " + repo .repo + "" }))
49- logger .info ("Cloning repo=" + repo .repo + " and branch=" + repo .branch )
47+
48+ MessageHelper .publish (repo_name + "-clone" ,
49+ json .dumps (dict (current_status = "cloning" , details = "Cloning repo " + repo_name + "" )))
50+ logger .info ("Cloning repo=" + repo_url + " and branch=" + branch )
5051
51- cloned_repo = GitHelper .clone (repo_url = repo . repo , branch = repo . branch ,
52+ cloned_repo = GitHelper .clone (repo_url = repo_url , branch = branch ,
5253 clone_dir = expanduser ("~" ) + "/temp/" + FileHelper .get_random_name (10 ))
5354 except BaseException as e :
54- logger .error ("Cloning of repo=" + repo . repo + " with branch=" + repo . branch + " failed due to error=" + str (e ))
55+ logger .error ("Cloning of repo=" + repo_url + " with branch=" + branch + " failed due to error=" + str (e ))
5556 # return jsonify({"error": "Error cloning " + repo.repo + " with branch due to " + str(e)}), 500
56- raise ApiError (message = "Error in cloning " + parsed_url .repo , status_code = 503 ,
57- details = "Error cloning " + repo .repo + " with branch " + repo .branch + " due to " + str (e ))
58- return cloned_repo
57+ MessageHelper .publish (repo_name + "-clone" ,
58+ json .dumps (dict (current_status = "error" ,
59+ details = "Cloning repo " + repo_name + " with branch=" + branch +
60+ "failed due to error=" + str (e ))))
61+ return
62+
63+ MessageHelper .publish (repo_name + "-clone" ,
64+ json .dumps (dict (current_status = "success" ,
65+ details = "Cloning of repo=" + repo_url + " with branch=" +
66+ branch + " is successful" )))
67+ upload_repo (cloned_repo , repo_name )
5968
6069
6170def create_repo_object (data ):
@@ -90,27 +99,38 @@ def info():
9099@swag_from (get_docs_path_for ('status_api.yaml' ))
91100@api_blueprint .route ('/status' , methods = ['POST' ])
92101def status ():
93- status_data = get_upload_data ()
94-
95- status_message = Status (current_status = status_data ['current_status' ],
102+ status_data , clone_data = get_upload_data ()
103+ current_status = get_current_status (clone_data , status_data )
104+ logger .debug ("current status=" + current_status )
105+ status_message = Status (clone_status = clone_data .get ('current_status' , "" ),
106+ current_status = current_status ,
96107 file_type = status_data .get ('type_uploading' , "" ),
97108 last_uploaded_file = status_data .get ('last_file_uploaded' ),
98109 total_files_uploaded = status_data .get ('total_files_uploaded' ))
99110 return jsonify (
100111 dict (status = status_message .current_status ,
112+ clone_status = status_message .clone_status ,
101113 currently_uploading = status_message .processing_file_type ,
102114 last_uploaded_file = status_message .last_uploaded_file ,
103115 total_files_uploaded = status_message .total_files_uploaded )), 200
104116
105117
118+ def get_current_status (clone_data , status_data ):
119+ logger .debug ('upload status data=' + json .dumps (status_data ))
120+ logger .debug ('clone status data=' + json .dumps (clone_data ))
121+ return status_data .get ('current_status' ) if status_data .get ('current_status' , "" ) != "" else clone_data [
122+ 'current_status' ]
123+
124+
106125def get_upload_data ():
107126 request_data = get_request_data ()
108- if not 'status_key' in request_data .keys ():
127+ if 'status_key' not in request_data .keys ():
109128 raise ApiError (message = "Incorrect status key" , status_code = 400 ,
110129 details = "The request did not contain key named status_key " )
111130
112131 status_data = json .loads (broker .get (request_data .get ('status_key' )))
113- return status_data
132+ clone_data = json .loads (broker .get (request_data .get ('status_key' ) + "-clone" ))
133+ return status_data , clone_data
114134
115135
116136def get_request_data ():
@@ -122,10 +142,15 @@ def get_request_data():
122142 return request_data
123143
124144
145+ def reset_if_exists (repo_name ):
146+ MessageHelper .publish (repo_name + "-clone" , json .dumps (dict (current_status = '' )))
147+ MessageHelper .publish (repo_name , json .dumps (dict (current_status = '' )))
148+
149+
125150@swag_from (get_docs_path_for ('progress_update_api_all.yaml' ))
126151@api_blueprint .route ('/progress-update/all' , methods = ['POST' ])
127152def progress_update ():
128- status_data = get_upload_data ()
153+ status_data , clone_data = get_upload_data ()
129154 # status_progress: UploadStatus = upload_status_from_dict(status_data)
130155 if status_data ["server" ] and status_data ["server" ]["response_code" ] and not 200 <= int (status_data ["server" ][
131156 "response_code" ]) <= 400 :
@@ -161,7 +186,7 @@ def progress_update():
161186@swag_from (get_docs_path_for ('progress_update_api_modules.yaml' ))
162187@api_blueprint .route ('/progress-update/modules' , methods = ['POST' ])
163188def progress_update_modules ():
164- status_data = get_upload_data ()
189+ status_data , clone_data = get_upload_data ()
165190 if status_data ["server" ] and status_data ["server" ]["response_code" ] and not 200 <= int (status_data ["server" ][
166191 "response_code" ]) <= 400 :
167192 return jsonify (
@@ -186,7 +211,7 @@ def progress_update_modules():
186211@swag_from (get_docs_path_for ('progress_update_api_assemblies.yaml' ))
187212@api_blueprint .route ('/progress-update/assemblies' , methods = ['POST' ])
188213def progress_update_assemblies ():
189- status_data = get_upload_data ()
214+ status_data , clone_data = get_upload_data ()
190215
191216 if status_data ["server" ] and status_data ["server" ]["response_code" ] and not 200 <= int (status_data ["server" ][
192217 "response_code" ]) <= 400 :
@@ -214,7 +239,7 @@ def progress_update_assemblies():
214239@swag_from (get_docs_path_for ('progress_update_api_resources.yaml' ))
215240@api_blueprint .route ('/progress-update/resources' , methods = ['POST' ])
216241def progress_update_resources ():
217- status_data = get_upload_data ()
242+ status_data , clone_data = get_upload_data ()
218243 if status_data ["server" ] and status_data ["server" ]["response_code" ] and not 200 <= int (status_data ["server" ][
219244 "response_code" ]) <= 400 :
220245 return jsonify (
0 commit comments