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

Publish annotation tasks to an authority queue #9402

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

marcospri
Copy link
Member

@marcospri marcospri commented Mar 14, 2025

Based on a per authority configuration publish new annotation messages that contain mentions to a queue.

The motivation for this is to support mention notification for LMS users.

See the design document over: https://docs.google.com/document/d/1tOTw-9bqCgM1bp0h2QsjsGKl0mtGh2lnpdv5oHYIj8E

Testing

  • Copy this line into your local h/.devdata.env

https://github.com/hypothesis/devdata/pull/116/files#diff-fe2be50e5855174f3ad7a3348f4381308c4b70bacd6eb95fa47342f448ad1728R3

https://hypothesis.instructure.com/courses/125/assignments/873

  • Check the logs over in H
Task h.tasks.annotations.publish_annotation_event_for_authority[09a46197-c446-4935-b97a-5b0358023594] succeeded in 0.04227317601907998s: None
  • Check the logs over LMS
lms.tasks.annotations.annotation_event[a33182a4-dcd5-4906-85c0-87adcfe0e285] Task lms.tasks.annotations.annotation_event[a33182a4-dcd5-4906-85c0-87adcfe0e285] succeeded in 0.0006408469926100224s: None

@marcospri marcospri marked this pull request as draft March 14, 2025 10:27
task_name: str


class AnnotationAuthorityQueueService:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we wouldn't need a separate service for this, but as this is going to be only used by LMS for now it isolates it from the rest of the codebase.



@subscriber(AnnotationEvent)
def publish_annotation_event_for_authority(event):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, we do another level of indirection here, the subscriber creates a celery task, that way if this LMS only feature creates any problems the annotations will be created fine.

@celery.task
def publish_annotation_event_for_authority(event_action, annotation_id):
"""Optionally publish an annotation event to the authority's message queue."""
celery.request.find_service(AnnotationAuthorityQueueService).publish(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The celery task just calls the service method, not much to see here.

if not authority_queue_config:
return

if event_action != "create" or not annotation.mentions:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This limits the amount of messages created by this to... just us testing for now.

self, config_json: str | None
) -> dict[str, AuthorityQueueConfiguration]:
"""Parse the authority queue config JSON string into dictionary by authority name."""
if not config_json:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being careful, if no config, broken config or any other issue, we just log and continue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only checked once on the server instantiation.

@marcospri marcospri force-pushed the publisha-annotation-messages branch 2 times, most recently from 374d257 to d040991 Compare March 17, 2025 09:57
@marcospri marcospri requested a review from mtomilov March 17, 2025 10:13
@marcospri marcospri marked this pull request as ready for review March 17, 2025 10:13
Copy link
Contributor

@mtomilov mtomilov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

Based on a per authority configuration publish new annotation messages that containt mentions to a queue.

The motivation for this is to support mention notification for LMS users.
@marcospri marcospri force-pushed the publisha-annotation-messages branch from d040991 to ee713cc Compare March 18, 2025 14:25
@marcospri marcospri merged commit 58efb86 into main Mar 19, 2025
11 checks passed
@marcospri marcospri deleted the publisha-annotation-messages branch March 19, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants