Skip to content

Commit

Permalink
Merge pull request #199 from stanfordnmbl/main-client-info
Browse files Browse the repository at this point in the history
main: update client info
  • Loading branch information
carmichaelong authored Oct 15, 2024
2 parents ece13b8 + 21ec161 commit 1cd782a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
20 changes: 16 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import traceback
import logging
import glob
from datetime import datetime, timedelta
import numpy as np
from utilsAPI import getAPIURL, getWorkerType, getASInstance, unprotect_current_instance, get_number_of_pending_trials
from utilsAuth import getToken
from utils import (getDataDirectory, checkTime, checkResourceUsage,
sendStatusEmail, checkForTrialsWithStatus)
sendStatusEmail, checkForTrialsWithStatus,
getCommitHash, getHostname, postLocalClientInfo,
postProcessedDuration)

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -72,7 +75,7 @@
continue

if r.status_code == 404:
logging.info("...pulling " + workerType + " trials.")
logging.info("...pulling " + workerType + " trials from " + API_URL)
time.sleep(1)

# When using autoscaling, we will remove the instance scale-in protection if it hasn't
Expand Down Expand Up @@ -137,8 +140,17 @@
logging.info("processTrial({},{},trial_type={})".format(trial["session"], trial["id"], trial_type))

try:
# trigger reset of timer for last processed trial
processTrial(trial["session"], trial["id"], trial_type=trial_type, isDocker=isDocker)
# Post new client info to Trial and start timer for processing duration
postLocalClientInfo(trial_url)
process_start_time = datetime.now()

# trigger reset of timer for last processed trial
processTrial(trial["session"], trial["id"], trial_type=trial_type, isDocker=isDocker)

# End process duration timer and post duration to database
process_end_time = datetime.now()
postProcessedDuration(trial_url, process_end_time - process_start_time)

# note a result needs to be posted for the API to know we finished, but we are posting them
# automatically thru procesTrial now
r = requests.patch(trial_url, data={"status": "done"},
Expand Down
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ RUN pip3 install -r requirements.txt

COPY . /workspace/

ARG GIT_COMMIT_HASH
ENV GIT_COMMIT_HASH=${GIT_COMMIT_HASH}

CMD python3.8 app.py
4 changes: 3 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ else
MMPOSE_IMAGE_TAG := mmpose-dev
endif

# Get git commit hash info to pass it into container
GIT_COMMIT_HASH=$(shell git rev-parse --short HEAD)

.PHONY: build
build:
wget -c -O ../mmpose/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth https://mc-opencap-public.s3.us-west-2.amazonaws.com/mmpose_pth/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
wget -c -O ../mmpose/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth https://mc-opencap-public.s3.us-west-2.amazonaws.com/mmpose_pth/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth

docker build -t $(BASE_NAME)/$(REPO_NAME)/$(OPENCAP_IMAGE_TAG) .. -f Dockerfile
docker build --build-arg GIT_COMMIT_HASH=$(GIT_COMMIT_HASH) -t $(BASE_NAME)/$(REPO_NAME)/$(OPENCAP_IMAGE_TAG) .. -f Dockerfile
docker build -t $(BASE_NAME)/$(REPO_NAME)/$(OPENPOSE_IMAGE_TAG) .. -f openpose/Dockerfile
docker build -t $(BASE_NAME)/$(REPO_NAME)/$(MMPOSE_IMAGE_TAG) .. -f mmpose/Dockerfile

Expand Down
2 changes: 1 addition & 1 deletion docker/openpose/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ COPY openpose /openpose
COPY defaultOpenCapSettings.json /openpose
RUN pip3 install --upgrade pip
RUN pip3 install -r /openpose/requirements.txt
CMD python3.6 /openpose/loop_openpose.py
CMD python3.6 /openpose/loop_openpose.py
40 changes: 39 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,4 +1612,42 @@ def get_entry_with_largest_number(trialList):
except ValueError:
continue

return max_entry
return max_entry

# Get local client info and update

def getCommitHash():
"""Get the git commit hash stored in the environment variable
GIT_COMMIT_HASH. This is assumed to be set in the Docker build
step. If not set, returns Null (default value for os.getenv())
"""
return os.getenv('GIT_COMMIT_HASH')

def getHostname():
"""Get the hostname. For a docker container, this is the container ID."""
return socket.gethostname()

def postLocalClientInfo(trial_url):
"""Given a trial_url, updates the Trial fields for
'git_commit' and 'hostname'.
"""
data = {
"git_commit": getCommitHash(),
"hostname": getHostname()
}
r = requests.patch(trial_url, data=data,
headers = {"Authorization": "Token {}".format(API_TOKEN)})

return r

def postProcessedDuration(trial_url, duration):
"""Given a trial_url and duration (formed from difference in datetime
objects), updates the Trial field for 'processed_duration'.
"""
data = {
"processed_duration": duration
}
r = requests.patch(trial_url, data=data,
headers = {"Authorization": "Token {}".format(API_TOKEN)})

return r

0 comments on commit 1cd782a

Please sign in to comment.