From 03039bbd099a0a1c2af0c5825d9f278cf2b8a15c Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 22 Apr 2025 13:51:21 +0200 Subject: [PATCH] Fix --- .../schedule_sync/activities/__init__.py | 3 ++- .../schedule_sync/activities/sync.py | 21 ++++++++++++++----- .../schedule_sync/workflows/sync.py | 20 ++++++------------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/applications/schedule_sync/activities/__init__.py b/src/applications/schedule_sync/activities/__init__.py index f8fa121..9deccb5 100644 --- a/src/applications/schedule_sync/activities/__init__.py +++ b/src/applications/schedule_sync/activities/__init__.py @@ -1,6 +1,7 @@ -from .sync import syncronize +from .sync import syncronize, syncronize_all __all__ = [ "syncronize", + "syncronize_all", ] diff --git a/src/applications/schedule_sync/activities/sync.py b/src/applications/schedule_sync/activities/sync.py index debed2e..b3120ee 100644 --- a/src/applications/schedule_sync/activities/sync.py +++ b/src/applications/schedule_sync/activities/sync.py @@ -6,13 +6,24 @@ from applications.schedule_sync.synchronizer import syncronize as syncronize_int @activity.defn async def syncronize(twitch_id: int): - streamer = await StreamerConfigRepository.get_by_twitch_id(twitch_id) - - if streamer.integrations.discord is None: - return - try: + streamer = await StreamerConfigRepository.get_by_twitch_id(twitch_id) + + if streamer.integrations.discord is None: + return + await syncronize_internal(streamer.twitch, streamer.integrations.discord.guild_id) except Exception as e: activity.logger.error(f"Error during synchronization: {e}") raise e + + +@activity.defn +async def syncronize_all(): + streamers = await StreamerConfigRepository().all() + + for streamer in streamers: + if streamer.integrations.discord is None: + continue + + await syncronize(streamer.twitch.id) diff --git a/src/applications/schedule_sync/workflows/sync.py b/src/applications/schedule_sync/workflows/sync.py index 62b0bf6..004612c 100644 --- a/src/applications/schedule_sync/workflows/sync.py +++ b/src/applications/schedule_sync/workflows/sync.py @@ -3,8 +3,7 @@ from datetime import timedelta from temporalio import workflow from temporalio.client import Schedule, ScheduleActionStartWorkflow, ScheduleSpec, ScheduleIntervalSpec -from applications.common.repositories.streamers import StreamerConfigRepository -from applications.schedule_sync.activities import syncronize +from applications.schedule_sync.activities import syncronize_all from applications.temporal_worker.queues import MAIN_QUEUE @@ -28,15 +27,8 @@ class ScheduleSyncWorkflow: @workflow.run async def run(self): - streamers = await StreamerConfigRepository().all() - - for streamer in streamers: - if streamer.integrations.discord is None: - continue - - await workflow.start_activity( - syncronize, - streamer.twitch.id, - task_queue=MAIN_QUEUE, - schedule_to_close_timeout=timedelta(minutes=5), - ) + await workflow.execute_activity( + syncronize_all, + task_queue=MAIN_QUEUE, + schedule_to_close_timeout=timedelta(minutes=5), + )