Last active
January 6, 2021 01:06
-
-
Save jgwerner/1119c63bbdb62e57c7a11f517def588f to your computer and use it in GitHub Desktop.
add-graders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Creates the shared grader notebook list by looping through a course array and then calls the | |
grader-setup-service microservice to create the grader notebook for the course if it doesn't exist. | |
All courses are created as deployments. To fetch a list of grader deployments that should be reflected | |
then run: | |
``` | |
kubectl get deployment -n <namespace> | |
``` | |
You can also get a list of services (since grader notebooks run as JupyterHub externally managed services: | |
``` | |
kubectl get svc -n <namespace> | |
``` | |
You may have to kill the deployments/services/pods before re adding them. With the command below you can | |
search for and kill the deployment in one fell swoop (replace course and namespace with your desired values | |
for the partial or full course name and the K8s cluster, respectively): | |
kubectl get deployment -n <namespace> --no-headers=true | awk '/grader-<course>/{print $1}' | xargs kubectl delete -n <namespace> deployment | |
""" | |
import asyncio | |
import json | |
import logging | |
import os | |
import requests | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.INFO) | |
# Populate the course list array with actual course names | |
graders = [ | |
"course-1", | |
"course-2", | |
"course-3", | |
] | |
ORG_NAME = API_TOKEN = os.environ.get('ORG_NAME') | |
GRADER_SERVICE_NAME = os.environ.get('GRADER_SERVICE_NAME') | |
GRADER_SERVICE_PORT = os.environ.get('GRADER_SERVICE_PORT') | |
GRADER_SERVICE_BASE_URL = f'http://{GRADER_SERVICE_NAME}:{GRADER_SERVICE_PORT}/services/{ORG_NAME}' | |
GRADER_SERVICE_COMMON_HEADERS = {'Content-Type': 'application/json'} | |
def add_grader(course_name: str, org: str) -> bool: | |
"""Add a grader notebook by course and orge names | |
Args: | |
course_name: a string that represents the course name | |
org_name: a string that represents the organization name | |
Returns: | |
True if successful, false otherwise | |
Raises: | |
json.JSONDecodeError if the response does not have a JSON body. | |
""" | |
url = f'{GRADER_SERVICE_BASE_URL}/{course_name}' | |
response = requests.post(url) | |
# if not response: | |
# raise ValueError('The setup course response body is empty') | |
return response.content | |
def main(): | |
for course in graders: | |
response = add_grader(course, 'flatiron') | |
logger.info(f'Reponse: {response}') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment