Skip to content

Commit

Permalink
Fix : Cancel notification with notif manager
Browse files Browse the repository at this point in the history
  • Loading branch information
foucblg committed Dec 3, 2024
1 parent 296e7aa commit d8ec151
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/modules/cinema/endpoints_cinema.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ async def create_session(
action_module="cinema",
)

await scheduler.cancel_job(job_id=f"cinema_weekly_{sunday}")
await notification_tool.cancel_notification(
scheduler=scheduler,
job_id=f"cinema_weekly_{sunday}",
)

await notification_tool.send_notification_to_topic(
custom_topic=CustomTopic(topic=Topic.cinema),
Expand Down
13 changes: 9 additions & 4 deletions app/modules/loan/endpoints_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ async def return_loan(
db: AsyncSession = Depends(get_db),
user: models_core.CoreUser = Depends(is_user_a_member),
scheduler: Scheduler = Depends(get_scheduler),
notification_tool: NotificationTool = Depends(get_notification_tool),
):
"""
Mark a loan as returned. This will update items availability.
Expand Down Expand Up @@ -872,7 +873,10 @@ async def return_loan(
returned=True,
returned_date=datetime.now(UTC),
)
await scheduler.cancel_job(f"loan_end_{loan.id}")
await notification_tool.cancel_notification(
scheduler=scheduler,
job_id=f"loan_end_{loan.id}",
)


@module.router.post(
Expand Down Expand Up @@ -927,9 +931,10 @@ async def extend_loan(
loan_update=loan_update,
db=db,
)
# TODO

await scheduler.cancel_job(f"loan_end_{loan.id}")
await notification_tool.cancel_notification(
scheduler=scheduler,
job_id=f"loan_end_{loan.id}",
)

message = Message(
title="📦 Prêt prolongé",
Expand Down
7 changes: 7 additions & 0 deletions app/utils/communication/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,10 @@ async def send_future_notification_to_topic_time_defer(
job_id=job_id,
defer_seconds=defer_seconds,
)

async def cancel_notification(
self,
scheduler: Scheduler,
job_id: str,
):
await scheduler.cancel_job(job_id=job_id)

0 comments on commit d8ec151

Please sign in to comment.