From 288e4769bc4e9fea337fa373803323f206827072 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Mon, 21 Apr 2025 18:03:24 +0200 Subject: [PATCH] Refactor --- .github/workflows/build_docker_image.yml | 12 ++++++------ .../{scheduler_sync => schedule_sync}/__init__.py | 0 .../comparators.py | 0 .../discord_events.py | 0 .../synchronizer.py | 2 +- .../{scheduler_sync => schedule_sync}/tasks.py | 2 +- .../twitch_events.py | 0 src/applications/stream_notifications/__init__.py | 7 ------- src/applications/twitch_webhook/__main__.py | 10 ++++++++++ .../messages_proc.py | 0 .../notification.py | 2 +- .../reward_redemption.py | 2 +- .../sent_notifications.py | 0 .../state.py | 0 .../tasks.py | 2 +- .../twitch/authorize.py | 0 .../twitch/token_storage.py | 0 .../twitch/webhook.py | 14 +++++--------- .../watcher.py | 2 +- 19 files changed, 27 insertions(+), 28 deletions(-) rename src/applications/{scheduler_sync => schedule_sync}/__init__.py (100%) rename src/applications/{scheduler_sync => schedule_sync}/comparators.py (100%) rename src/applications/{scheduler_sync => schedule_sync}/discord_events.py (100%) rename src/applications/{scheduler_sync => schedule_sync}/synchronizer.py (98%) rename src/applications/{scheduler_sync => schedule_sync}/tasks.py (89%) rename src/applications/{scheduler_sync => schedule_sync}/twitch_events.py (100%) delete mode 100644 src/applications/stream_notifications/__init__.py create mode 100644 src/applications/twitch_webhook/__main__.py rename src/applications/{stream_notifications => twitch_webhook}/messages_proc.py (100%) rename src/applications/{stream_notifications => twitch_webhook}/notification.py (98%) rename src/applications/{stream_notifications => twitch_webhook}/reward_redemption.py (94%) rename src/applications/{stream_notifications => twitch_webhook}/sent_notifications.py (100%) rename src/applications/{stream_notifications => twitch_webhook}/state.py (100%) rename src/applications/{stream_notifications => twitch_webhook}/tasks.py (96%) rename src/applications/{stream_notifications => twitch_webhook}/twitch/authorize.py (100%) rename src/applications/{stream_notifications => twitch_webhook}/twitch/token_storage.py (100%) rename src/applications/{stream_notifications => twitch_webhook}/twitch/webhook.py (93%) rename src/applications/{stream_notifications => twitch_webhook}/watcher.py (98%) diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml index 852b361..abc9227 100644 --- a/.github/workflows/build_docker_image.yml +++ b/.github/workflows/build_docker_image.yml @@ -49,14 +49,14 @@ jobs: with: url: ${{ secrets.WEBHOOK_URL }} - # - - # name: Invoke deployment hook (worker) - # uses: joelwmale/webhook-action@master - # with: - # url: ${{ secrets.WEBHOOK_URL_2 }} + - + name: Invoke deployment hook (twitch_webhook) + uses: joelwmale/webhook-action@master + with: + url: ${{ secrets.WEBHOOK_URL_2 }} # - - # name: Invoke deployment hook (scheduler) + # name: Invoke deployment hook (worker) # uses: joelwmale/webhook-action@master # with: # url: ${{ secrets.WEBHOOK_URL_3 }} diff --git a/src/applications/scheduler_sync/__init__.py b/src/applications/schedule_sync/__init__.py similarity index 100% rename from src/applications/scheduler_sync/__init__.py rename to src/applications/schedule_sync/__init__.py diff --git a/src/applications/scheduler_sync/comparators.py b/src/applications/schedule_sync/comparators.py similarity index 100% rename from src/applications/scheduler_sync/comparators.py rename to src/applications/schedule_sync/comparators.py diff --git a/src/applications/scheduler_sync/discord_events.py b/src/applications/schedule_sync/discord_events.py similarity index 100% rename from src/applications/scheduler_sync/discord_events.py rename to src/applications/schedule_sync/discord_events.py diff --git a/src/applications/scheduler_sync/synchronizer.py b/src/applications/schedule_sync/synchronizer.py similarity index 98% rename from src/applications/scheduler_sync/synchronizer.py rename to src/applications/schedule_sync/synchronizer.py index 80ef9f9..37ed12a 100644 --- a/src/applications/scheduler_sync/synchronizer.py +++ b/src/applications/schedule_sync/synchronizer.py @@ -1,7 +1,7 @@ import logging from datetime import datetime -from domain.streamers import TwitchConfig +from applications.common.domain.streamers import TwitchConfig from .twitch_events import get_twitch_events, TwitchEvent from .discord_events import ( diff --git a/src/applications/scheduler_sync/tasks.py b/src/applications/schedule_sync/tasks.py similarity index 89% rename from src/applications/scheduler_sync/tasks.py rename to src/applications/schedule_sync/tasks.py index cf2de7b..e8a8b85 100644 --- a/src/applications/scheduler_sync/tasks.py +++ b/src/applications/schedule_sync/tasks.py @@ -1,5 +1,5 @@ from core.broker import broker -from repositories.streamers import StreamerConfigRepository +from applications.common.repositories.streamers import StreamerConfigRepository from .synchronizer import syncronize diff --git a/src/applications/scheduler_sync/twitch_events.py b/src/applications/schedule_sync/twitch_events.py similarity index 100% rename from src/applications/scheduler_sync/twitch_events.py rename to src/applications/schedule_sync/twitch_events.py diff --git a/src/applications/stream_notifications/__init__.py b/src/applications/stream_notifications/__init__.py deleted file mode 100644 index c490889..0000000 --- a/src/applications/stream_notifications/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from .twitch.webhook import start_twitch_service - - -start = start_twitch_service - - -__all__ = ["start"] diff --git a/src/applications/twitch_webhook/__main__.py b/src/applications/twitch_webhook/__main__.py new file mode 100644 index 0000000..237d1f9 --- /dev/null +++ b/src/applications/twitch_webhook/__main__.py @@ -0,0 +1,10 @@ +from asyncio import run + +from .twitch.webhook import TwitchService + + +async def start_twitch_service() -> None: + await TwitchService.start() + + +run(start_twitch_service()) diff --git a/src/applications/stream_notifications/messages_proc.py b/src/applications/twitch_webhook/messages_proc.py similarity index 100% rename from src/applications/stream_notifications/messages_proc.py rename to src/applications/twitch_webhook/messages_proc.py diff --git a/src/applications/stream_notifications/notification.py b/src/applications/twitch_webhook/notification.py similarity index 98% rename from src/applications/stream_notifications/notification.py rename to src/applications/twitch_webhook/notification.py index a257faf..b2bc37c 100644 --- a/src/applications/stream_notifications/notification.py +++ b/src/applications/twitch_webhook/notification.py @@ -3,7 +3,7 @@ import logging from httpx import AsyncClient from core.config import config -from domain.streamers import StreamerConfig +from applications.common.domain.streamers import StreamerConfig from .state import State from .sent_notifications import SentNotification, SentNotificationType, SentResult diff --git a/src/applications/stream_notifications/reward_redemption.py b/src/applications/twitch_webhook/reward_redemption.py similarity index 94% rename from src/applications/stream_notifications/reward_redemption.py rename to src/applications/twitch_webhook/reward_redemption.py index c6aef4c..09314a4 100644 --- a/src/applications/stream_notifications/reward_redemption.py +++ b/src/applications/twitch_webhook/reward_redemption.py @@ -4,7 +4,7 @@ from pydantic import BaseModel from twitchAPI.object.eventsub import ChannelPointsCustomRewardRedemptionAddEvent -from repositories.streamers import StreamerConfigRepository +from applications.common.repositories.streamers import StreamerConfigRepository from .twitch.authorize import authorize diff --git a/src/applications/stream_notifications/sent_notifications.py b/src/applications/twitch_webhook/sent_notifications.py similarity index 100% rename from src/applications/stream_notifications/sent_notifications.py rename to src/applications/twitch_webhook/sent_notifications.py diff --git a/src/applications/stream_notifications/state.py b/src/applications/twitch_webhook/state.py similarity index 100% rename from src/applications/stream_notifications/state.py rename to src/applications/twitch_webhook/state.py diff --git a/src/applications/stream_notifications/tasks.py b/src/applications/twitch_webhook/tasks.py similarity index 96% rename from src/applications/stream_notifications/tasks.py rename to src/applications/twitch_webhook/tasks.py index e8a83a3..147b6dc 100644 --- a/src/applications/stream_notifications/tasks.py +++ b/src/applications/twitch_webhook/tasks.py @@ -3,7 +3,7 @@ from datetime import datetime, timezone from twitchAPI.helper import first from core.broker import broker -from repositories.streamers import StreamerConfigRepository +from applications.common.repositories.streamers import StreamerConfigRepository from .state import State, UpdateEvent, EventType from .watcher import StateWatcher diff --git a/src/applications/stream_notifications/twitch/authorize.py b/src/applications/twitch_webhook/twitch/authorize.py similarity index 100% rename from src/applications/stream_notifications/twitch/authorize.py rename to src/applications/twitch_webhook/twitch/authorize.py diff --git a/src/applications/stream_notifications/twitch/token_storage.py b/src/applications/twitch_webhook/twitch/token_storage.py similarity index 100% rename from src/applications/stream_notifications/twitch/token_storage.py rename to src/applications/twitch_webhook/twitch/token_storage.py diff --git a/src/applications/stream_notifications/twitch/webhook.py b/src/applications/twitch_webhook/twitch/webhook.py similarity index 93% rename from src/applications/stream_notifications/twitch/webhook.py rename to src/applications/twitch_webhook/twitch/webhook.py index 9aa2110..7c93391 100644 --- a/src/applications/stream_notifications/twitch/webhook.py +++ b/src/applications/twitch_webhook/twitch/webhook.py @@ -7,11 +7,11 @@ from twitchAPI.twitch import Twitch from twitchAPI.object.eventsub import StreamOnlineEvent, ChannelUpdateEvent, ChannelChatMessageEvent, ChannelPointsCustomRewardRedemptionAddEvent from twitchAPI.oauth import validate_token -from repositories.streamers import StreamerConfigRepository, StreamerConfig -from modules.stream_notifications.tasks import on_stream_state_change, on_stream_state_change_with_check, on_message, on_redemption_reward_add_task -from modules.stream_notifications.state import UpdateEvent, EventType -from modules.stream_notifications.messages_proc import MessageEvent -from modules.stream_notifications.reward_redemption import RewardRedemption +from applications.common.repositories.streamers import StreamerConfigRepository, StreamerConfig +from applications.twitch_webhook.tasks import on_stream_state_change, on_stream_state_change_with_check, on_message, on_redemption_reward_add_task +from applications.twitch_webhook.state import UpdateEvent, EventType +from applications.twitch_webhook.messages_proc import MessageEvent +from applications.twitch_webhook.reward_redemption import RewardRedemption from .authorize import authorize @@ -196,7 +196,3 @@ class TwitchService: ) logger.info("Twitch service stopped") - - -async def start_twitch_service() -> NoReturn: - await TwitchService.start() diff --git a/src/applications/stream_notifications/watcher.py b/src/applications/twitch_webhook/watcher.py similarity index 98% rename from src/applications/stream_notifications/watcher.py rename to src/applications/twitch_webhook/watcher.py index eed5d38..2f5eae1 100644 --- a/src/applications/stream_notifications/watcher.py +++ b/src/applications/twitch_webhook/watcher.py @@ -3,7 +3,7 @@ from datetime import datetime, timezone, timedelta from twitchAPI.helper import first from core.redis import redis_manager -from repositories.streamers import StreamerConfigRepository +from applications.common.repositories.streamers import StreamerConfigRepository from .state import State, StateManager, EventType from .sent_notifications import SentNotificationRepository, SentNotificationType