Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fix: Add try/except blocks to setup course hook (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwerner authored May 14, 2021
1 parent 907e6c5 commit 7842069
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/illumidesk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ COPY jupyterhub_config.py /srv/jupyterhub/
COPY wait-for-postgres.sh /srv/jupyterhub/
RUN chmod +rx wait-for-postgres.sh

RUN curl -O https://raw.githubusercontent.com/IllumiDesk/illumidesk-containers/main/jupyterhub/wait-for-postgres.sh \
&& chmod +rwx wait-for-postgres.sh

CMD ["./wait-for-postgres.sh", "jupyterhub", "--config", "/srv/jupyterhub/jupyterhub_config.py"]
27 changes: 20 additions & 7 deletions src/illumidesk/illumidesk/apis/jupyterhub_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ async def add_student_to_jupyterhub_group(
await self.create_group(group_name)
except HTTPClientError as e:
if e.code != 409:
self.log.error(
"Error creating student group %s with exception %s"
% (group_name, e)
)
await self._add_user_to_jupyterhub_group(student, group_name)
self.log.error("Error creating instructors group %e", e)
else:
try:
await self._add_user_to_jupyterhub_group(student, group_name)
except HTTPClientError as e:
if e.code != 409:
self.log.error(
"Error adding user %s to group %s with exception %s"
% (student, group_name, e)
)

async def add_instructor_to_jupyterhub_group(
self, course_id: str, instructor: str
Expand All @@ -199,8 +204,16 @@ async def add_instructor_to_jupyterhub_group(
await self.create_group(group_name)
except HTTPClientError as e:
if e.code != 409:
self.log.error("Error creating instructors group")
await self._add_user_to_jupyterhub_group(instructor, group_name)
self.log.error("Error creating instructors group %e", e)
else:
try:
await self._add_user_to_jupyterhub_group(instructor, group_name)
except HTTPClientError as e:
if e.code != 409:
self.log.error(
"Error adding user %s to group %s with exception %s"
% (instructor, group_name, e)
)

async def _add_user_to_jupyterhub_group(
self, username: str, group_name: str
Expand Down
25 changes: 20 additions & 5 deletions src/illumidesk/illumidesk/authenticators/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,29 @@ async def setup_course_hook(
nb_service.add_user_to_nbgrader_gradebook(username, lms_user_id)
# TODO: verify the logic to simplify groups creation and membership
if user_is_a_student(user_role):
# assign the user to 'nbgrader-<course_id>' group in jupyterhub and gradebook
await jupyterhub_api.add_student_to_jupyterhub_group(course_id, username)
try:
# assign the user to 'nbgrader-<course_id>' group in jupyterhub and gradebook
await jupyterhub_api.add_student_to_jupyterhub_group(course_id, username)
except Exception as e:
logger.error(
"An error when adding student username: %s to course_id: %s with exception %s",
(username, course_id, e),
)
elif user_is_an_instructor(user_role):
# assign the user in 'formgrade-<course_id>' group
await jupyterhub_api.add_instructor_to_jupyterhub_group(course_id, username)
try:
# assign the user in 'formgrade-<course_id>' group
await jupyterhub_api.add_instructor_to_jupyterhub_group(course_id, username)
except Exception as e:
logger.error(
"An error when adding instructor username: %s to course_id: %s with exception %s",
(username, course_id, e),
)

# launch the new grader-notebook as a service
new_setup = await register_new_service(org_name=ORG_NAME, course_id=course_id)
try:
new_setup = await register_new_service(org_name=ORG_NAME, course_id=course_id)
except Exception as e:
logger.error("Unable to launch the shared grader notebook with exception %s", e)

return authentication

Expand Down

0 comments on commit 7842069

Please sign in to comment.