Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submission process improvements, cleanup #177

Merged
merged 20 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,9 @@ def compilation_pubsub_call(self, request, team, league_id, pk=None):
submission.save()

id = submission.id
# call to compile server
print('attempting call to compile server')
print('id:', id)
# Notify compile server through pubsub queue.
data = str(id)
data_bytestring = data.encode('utf-8')
print(type(data_bytestring))
pub(GCLOUD_PROJECT, GCLOUD_SUB_COMPILE_NAME, data_bytestring)

# indicate submission being queued
Expand Down Expand Up @@ -762,7 +759,7 @@ def compilation_update(self, request, team, league_id, pk=None):
# Only if this submission is newer than what's already been processed,
# update the submission history.
# (to prevent reverting to older submissions that took longer to process)
if submission.id > team_sub.last_1_id:
if team_sub.last_1_id is None or submission.id > team_sub.last_1_id:
team_sub.last_3_id = team_sub.last_2_id
team_sub.last_2_id = team_sub.last_1_id
team_sub.last_1_id = submission
Expand Down Expand Up @@ -837,20 +834,6 @@ def team_compilation_status(self, request, team, league_id, pk=None):
else:
return Response({'status': None}, status.HTTP_200_OK)

@action(methods=['get'], detail=True)
n8kim1 marked this conversation as resolved.
Show resolved Hide resolved
def team_compilation_id(self, request, team, league_id, pk=None):
if pk != str(team.id):
return Response({'message': "Not authenticated"}, status.HTTP_401_UNAUTHORIZED)

team_data = self.get_queryset().get(pk=pk)
comp_id = team_data.compiling_id
if comp_id is not None:
return Response({'compilation_id': comp_id}, status.HTTP_200_OK)
else:
# this is bad, replace with something thats actually None
# ^ TODO should address this
return Response({'compilation_id': -1}, status.HTTP_200_OK)


class ScrimmageViewSet(viewsets.GenericViewSet,
mixins.ListModelMixin,
Expand Down
8 changes: 7 additions & 1 deletion backend/docs/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Set the contents of this file into dev_settings_sensitive.py, as GOOGLE_APPLICAT
From Google Cloud console, "Compute Engine" -> “Instance Templates”. Click on an old backend template, and then click on “Create similar”. Change the name to something descriptive enough and conventional. ("bc21-backend-template", for example, works well. Also I’ve found that including the current date and time in the name can help keep things straight.) For machine type, we've found the `n1-standard-n1` to be cheap and work well, especially providing enough memory.

Check the checkbox of "Deploy a container image to this VM instance", and change the container image to the image name you've just written in the cloud build trigger.
Then, click "Advanced container options" to see a place to set environment variables. Find the variables set in `dev_settings_sensitive.py`, and set all of those keys/values here, too. (Here, these values should not be enclosed in quotes.) Note that these are un-editable; if you ever change environment variables, you'll have to make a new instance template. ("Create Similar" on the instance template's page is helpful here.)
Then, click "Advanced container options" to see a place to set environment variables. Find the variables set in `dev_settings_sensitive.py`, and set all of those keys/values here, too. (Here, these values should not be enclosed in quotes.) Note that these are un-editable; if you ever change environment variables, you'll have to make a new instance template. See the "Deploying new instance template" for more info on this.

(For now, keep the boot disk the same; it may be good to change it to a later version down the road. Be sure to test that the VMs still work, though.)

Expand Down Expand Up @@ -126,3 +126,9 @@ Make sure the CORS policy and Google Application credentials are all set up, as
Delete old instance groups: go to "Compute Engine" -> "Instance groups", check any old instance groups that are no longer in use, and click "delete".
Delete old instance template: go to "Compute Engine" -> "Instance templates", check any old templates that are no longer in use, and click "delete".
Delete old, unused backend services and buckets, if you're up to it, instructions in previous section. But this can be a pain and is certainly not necessary.

## Deploying new instance template
Sometimes you'll have to change your instance template (for example, if you change an environment variable). To do so:
Create a new instance template (if you're looking to make just small changes, "Create Similar" on the original instance template's page is helpful here).
Click on your already-present instance group in use, and on its page, click "Edit Group". Find the "instance template" dropdown and change to the newly created instance template.
Finally, click on "rolling restart/replace". Change operation from `Restart` to `Replace`, let maximum surge be 1 and **maximum unavailable be 0** (we don't want our server to go down). Wait for the spinning icons to become checkmarks.
27 changes: 9 additions & 18 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ class Api {

//----SUBMISSIONS----

// TODO clean up a lot of old comments, print statements
// TODO provide more explanatory comments
// TODO there's a better wayy to work with 'submitting' in cookies
// TODO 'submitting' could probably use a better name
// TODO review code in the submissions js
// TODO errors in these callbacks should also display messages in frontend

//uploads a new submission to the google cloud bucket
static newSubmission(submissionfile, callback){
// submissionfile.append('_method', 'PUT');
// get the url from the real api
// URLs which files are uploaded to are generated by the backend;
// call the backend api to get this link
$.post(`${URL}/api/${LEAGUE}/submission/`)
.done((data, status) => {
// Upload to the bucket
console.log("got URL")
Cookies.set('submission_id', data['submission_id']);
$.ajax({
Expand All @@ -41,23 +35,26 @@ class Api {
contentType: false
})
.done((data, status) => {
// After upload is done, need to queue for compilation.
// See corresponding method of backend/api/views.py for more explanation.
console.log(data, status)
$.post(`${URL}/api/${LEAGUE}/submission/` +Cookies.get('submission_id') + `/compilation_pubsub_call/`)
.done((data, status) => {
console.log("Definitely done!")
// console.log(data, status)
Cookies.set('submitting', 0)
Cookies.set('submission_upload_status', 1)
})
.fail((xhr, status, error) => {
console.log("Error in compilation update callback: ", xhr, status, error)
Cookies.set('submission_upload_status', 3)
})
})
.fail((xhr, status, error) => {
console.log("Error in put request of file to bucket: ", xhr, status, error)
Cookies.set('submission_upload_status', 3)
})
})
.fail((xhr, status, error) => {
console.log("Error in post request for upload: ", xhr, status, error)
Cookies.set('submission_upload_status', 3)
});

}
Expand Down Expand Up @@ -102,12 +99,6 @@ class Api {
});
}

static getCompilationID(callback) {
$.get(`${URL}/api/${LEAGUE}/teamsubmission/${Cookies.get("team_id")}/team_compilation_id/`).done((data, status) => {
return data['compilation_id']
});
}

// note that this is a submission, not a teamsubmission, thing
static getSubmissionStatus(callback) {
$.get(`${URL}/api/${LEAGUE}/submission/${Cookies.get("submission_id")}/get_status/`).done((data, status) => {
Expand Down
Loading