-
Notifications
You must be signed in to change notification settings - Fork 0
fix: removal of lifecycle enabled from notif service #131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e4e55e
fix: removal of lifecycle enabled from notif service
HardMax71 b30e513
fix: notif service and moved scheduler to separate component
HardMax71 399d2ef
fix: misc
HardMax71 030be15
fix: misc
HardMax71 6a10911
fix: revert
HardMax71 43cdc10
fix: error type for exec failed is now newer nullable
HardMax71 32e41ca
fix: ci race of cert generator
HardMax71 f2da711
fix: wrong topic subscription for notif service
HardMax71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import logging | ||
|
|
||
| from app.db.repositories.notification_repository import NotificationRepository | ||
| from app.services.notification_service import NotificationService | ||
|
|
||
|
|
||
| class NotificationScheduler: | ||
| """Stateless scheduler service that processes due notifications. | ||
|
|
||
| APScheduler manages the timer (interval trigger) in the DI provider. | ||
| This class contains only the business logic for finding and delivering | ||
| due notifications — no loops, no lifecycle, no state. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| notification_repository: NotificationRepository, | ||
| notification_service: NotificationService, | ||
| logger: logging.Logger, | ||
| ) -> None: | ||
| self.repository = notification_repository | ||
| self.service = notification_service | ||
| self.logger = logger | ||
|
|
||
| async def process_due_notifications(self, batch_size: int = 50) -> int: | ||
| """Find and deliver all notifications whose scheduled_for <= now. | ||
|
|
||
| Called by APScheduler on a fixed interval. Each invocation is | ||
| a single-shot batch: query DB for due items, deliver each, return. | ||
|
|
||
| Returns the number of notifications successfully delivered. | ||
| """ | ||
| due = await self.repository.find_due_notifications(limit=batch_size) | ||
| if not due: | ||
| return 0 | ||
|
|
||
| self.logger.info(f"Found {len(due)} due scheduled notifications") | ||
|
|
||
| delivered = 0 | ||
| for notification in due: | ||
| try: | ||
| if await self.service._deliver_notification(notification): | ||
| delivered += 1 | ||
| except Exception as e: | ||
| self.logger.error( | ||
| f"Failed to deliver scheduled notification {notification.notification_id}: {e}", | ||
| exc_info=True, | ||
| ) | ||
|
|
||
| self.logger.info(f"Delivered {delivered}/{len(due)} scheduled notifications") | ||
HardMax71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return delivered | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.