Skip to content

Commit

Permalink
Improve robustness of user inference
Browse files Browse the repository at this point in the history
  • Loading branch information
sersorrel committed Oct 16, 2024
1 parent c9b7ea3 commit b92d75d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/farmer/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pydantic import BaseModel, model_validator
from slack_bolt.async_app import AsyncApp
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler
from slack_sdk.errors import SlackApiError
from slack_sdk.models.blocks import RichTextBlock, RichTextSectionElement, RichTextElementParts, \
RichTextPreformattedElement, ContextBlock, PlainTextObject, HeaderBlock, MarkdownTextObject, SectionBlock, \
ButtonElement, DividerBlock, Block, RichTextListElement
Expand Down Expand Up @@ -162,6 +163,7 @@ async def message_jobs(message, say):
logging.info(f"recieved text '{rx}'")
user = extract_username(rx)
if not user:
# TODO: apparently `user_profile` can sometimes not be present (then should query `user` ID)
user = message["user_profile"]["name"]
# get jobs for user and say it back to them
jobs = (await rm.reporter.get_jobs(user=user)).result
Expand Down Expand Up @@ -398,8 +400,8 @@ async def send_job_complete_message(job: dict, *, username: str, job_id: str, co
return
try:
user = (await slack_bot.client.users_lookupByEmail(email=username + "@sanger.ac.uk"))["user"]
except KeyError:
logging.error("could not infer Slack user from %r (job %r)", username, job_id)
except SlackApiError:
logging.exception("could not infer Slack user from %r (job %r)", username, job_id)
return
array = f" (array length {count})" if count > 1 else ""
match state:
Expand Down

0 comments on commit b92d75d

Please sign in to comment.