Skip to content

Commit

Permalink
separate download and override as two api calls. THE CODE is not read…
Browse files Browse the repository at this point in the history
…y yet
  • Loading branch information
htwangtw committed Dec 11, 2023
1 parent d5da63e commit 2ac16f3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
23 changes: 9 additions & 14 deletions api/neurolibre_celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,15 @@ def preview_download_data(self, repo_url, commit_hash, comment_id, issue_id, rev
data_requirement_path = os.path.join(repo_path,'binder','data_requirement.json')
with open(data_requirement_path) as json_file:
project_name = json.load(json_file).get('projectName', False)
if os.path.exists(os.path.join("/DATA", project_name)):
self.update_state(state=states.FAILURE, meta={'exc_type':"NeuroLibre celery exception",'exc_message': "Custom",'message': f"Data already exists in /DATA/{project_name}."})
gh_template_respond(github_client,"failure",task_title,reviewRepository,issue_id,task_id,comment_id,
f"Data already exists in /DATA/{project_name}."
)
else:
# download data with repo2data
repo2data = Repo2Data(data_requirement_path, server=True)
data_path = repo2data.install()
# update status
self.update_state(state=states.SUCCESS, meta={'message': f"Data downloaded to {data_path}."})
gh_template_respond(github_client,"received",task_title,reviewRepository,issue_id,task_id,comment_id,
f"Data downloaded to {data_path}."
)
# download data with repo2data
repo2data = Repo2Data(data_requirement_path, server=True)
data_path = repo2data.install()

# update status
self.update_state(state=states.SUCCESS, meta={'message': f"Data downloaded to {data_path}."})
gh_template_respond(github_client,"received",task_title,reviewRepository,issue_id,task_id,comment_id,
f"Data downloaded to {data_path}."
)

@celery_app.task(bind=True)
def rsync_data_task(self, comment_id, issue_id, project_name, reviewRepository):
Expand Down
34 changes: 34 additions & 0 deletions api/neurolibre_preview_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,40 @@ def api_download_data(user, repo_url, commit_hash):
response = make_response(jsonify("Celery could not start the task."),500)
return response

@app.route('/api/book/data', methods=['POST'])
@htpasswd.required
@doc(description='Endpoint for overriding data on preview server.', tags=['Data'])
def api_override_data(user, repo_url, commit_hash):
"""
This endpoint is to overried downloaded data from GitHub (technical screening) requests.
"""
GH_BOT=os.getenv('GH_BOT')
github_client = Github(GH_BOT)
issue_id = id

task_title = "Override data for preview."
comment_id = gh_template_respond(github_client,"pending",task_title,reviewRepository,issue_id)

celery_payload = dict(repo_url=repo_url,
commit_hash=commit_hash,
rate_limit=build_rate_limit,
binder_name=binderName,
domain_name = domainName,
comment_id=comment_id,
issue_id=issue_id,
review_repository=reviewRepository,
task_title=task_title)

task_result = preview_download_data.apply_async(args=[celery_payload])

if task_result.task_id is not None:
gh_template_respond(github_client,"received",task_title,reviewRepository,issue_id,task_result.task_id,comment_id, "")
response = make_response(jsonify("Celery task assigned successfully."),200)
else:
# If not successfully assigned, fail the status immediately and return 500
gh_template_respond(github_client,"failure",task_title,reviewRepository,issue_id,task_result.task_id,comment_id, "Internal server error: NeuroLibre background task manager could not receive the request.")
response = make_response(jsonify("Celery could not start the task."),500)
return response

@app.route('/api/book/build', methods=['POST'])
@htpasswd.required
Expand Down

0 comments on commit 2ac16f3

Please sign in to comment.