Skip to content

Commit

Permalink
Feat : removing scheduler time defer
Browse files Browse the repository at this point in the history
  • Loading branch information
foucblg committed Dec 3, 2024
1 parent 863f81e commit 897e049
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 73 deletions.
10 changes: 5 additions & 5 deletions app/core/notification/endpoints_notification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta

from fastapi import APIRouter, Body, Depends, HTTPException, Path
from sqlalchemy.ext.asyncio import AsyncSession
Expand Down Expand Up @@ -302,10 +302,10 @@ async def send_future_notification(
content="Ceci est un test de notification future",
action_module="test",
)
await notification_tool.send_future_notification_to_users_time_defer(
await notification_tool.send_notification_to_users(
user_ids=[user.id],
message=message,
defer_seconds=10,
defer_date=datetime.now(UTC) + timedelta(seconds=10),
job_id="test25",
scheduler=scheduler,
)
Expand All @@ -330,10 +330,10 @@ async def send_future_notification_topic(
content="Ceci est un test de notification future topic",
action_module="test",
)
await notification_tool.send_future_notification_to_topic_time_defer(
await notification_tool.send_notification_to_topic(
custom_topic=CustomTopic.from_str("test"),
message=message,
defer_seconds=10,
defer_date=datetime.now(UTC) + timedelta(seconds=10),
job_id="test26",
scheduler=scheduler,
)
Expand Down
15 changes: 0 additions & 15 deletions app/types/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,6 @@ async def close(self):
# If the worker was started, we close it
pass

async def queue_job_time_defer(
self,
job_function: Callable[..., Coroutine[Any, Any, Any]],
job_id: str,
defer_seconds: float,
**kwargs,
):
"""
Queue a job to execute job_function in defer_seconds amount of seconds
job_id will allow to abort if needed
"""
scheduler_logger.debug(
f"Job {job_id} queued in OfflineScheduler with defer {defer_seconds} seconds",
)

async def queue_job_defer_to(
self,
job_function: Callable[..., Coroutine[Any, Any, Any]],
Expand Down
55 changes: 2 additions & 53 deletions app/utils/communication/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,7 @@ async def send_notification_to_users(
defer_date: datetime | None = None,
job_id: str | None = None,
):
if defer_seconds is not None and scheduler is not None and job_id is not None:
await self.send_future_notification_to_users_time_defer(
user_ids=user_ids,
message=message,
scheduler=scheduler,
defer_seconds=defer_seconds,
job_id=job_id,
)
elif defer_date is not None and scheduler is not None and job_id is not None:
if defer_date is not None and scheduler is not None and job_id is not None:
await self.send_future_notification_to_users_defer_to(
user_ids=user_ids,
message=message,
Expand All @@ -361,23 +353,6 @@ async def send_notification_to_users(
db=self.db,
)

async def send_future_notification_to_users_time_defer(
self,
user_ids: list[str],
message: Message,
scheduler: Scheduler,
defer_seconds: int,
job_id: str,
):
await scheduler.queue_job_time_defer(
self.notification_manager.send_notification_to_users,
user_ids=user_ids,
message=message,
db=None,
job_id=job_id,
defer_seconds=defer_seconds,
)

async def send_future_notification_to_users_defer_to(
self,
user_ids: list[str],
Expand Down Expand Up @@ -410,19 +385,10 @@ async def send_notification_to_topic(
custom_topic: CustomTopic,
message: Message,
scheduler: Scheduler | None = None,
defer_seconds: int | None = None,
defer_date: datetime | None = None,
job_id: str | None = None,
):
if defer_seconds is not None and scheduler is not None and job_id is not None:
await self.send_future_notification_to_topic_time_defer(
custom_topic=custom_topic,
message=message,
scheduler=scheduler,
defer_seconds=defer_seconds,
job_id=job_id,
)
elif defer_date is not None and scheduler is not None and job_id is not None:
if defer_date is not None and scheduler is not None and job_id is not None:
await self.send_future_notification_to_topic_defer_to(
custom_topic=custom_topic,
message=message,
Expand Down Expand Up @@ -455,23 +421,6 @@ async def send_future_notification_to_topic_defer_to(
defer_date=defer_date,
)

async def send_future_notification_to_topic_time_defer(
self,
custom_topic: CustomTopic,
message: Message,
scheduler: Scheduler,
defer_seconds: int,
job_id: str,
):
await scheduler.queue_job_time_defer(
self.notification_manager.send_notification_to_topic,
custom_topic=custom_topic,
message=message,
db=None,
job_id=job_id,
defer_seconds=defer_seconds,
)

async def cancel_notification(
self,
scheduler: Scheduler,
Expand Down

0 comments on commit 897e049

Please sign in to comment.