This commit is contained in:
2025-04-21 21:54:30 +02:00
parent fb19f7a125
commit 77fb68a5e3
11 changed files with 134 additions and 119 deletions

View File

@@ -1,6 +1,6 @@
from .sync import ScheduleSyncActivity
from .sync import syncronize
__all__ = [
"ScheduleSyncActivity",
"syncronize",
]

View File

@@ -1,16 +1,14 @@
from temporalio import activity
from applications.common.repositories.streamers import StreamerConfigRepository
from applications.schedule_sync.synchronizer import syncronize
from applications.schedule_sync.synchronizer import syncronize as syncronize_internal
class ScheduleSyncActivity:
@classmethod
@activity.defn
async def syncronize(cls, twitch_id: int):
streamer = await StreamerConfigRepository.get_by_twitch_id(twitch_id)
@activity.defn
async def syncronize(twitch_id: int):
streamer = await StreamerConfigRepository.get_by_twitch_id(twitch_id)
if streamer.integrations.discord is None:
return
if streamer.integrations.discord is None:
return
await syncronize(streamer.twitch, streamer.integrations.discord.guild_id)
await syncronize_internal(streamer.twitch, streamer.integrations.discord.guild_id)

View File

@@ -4,10 +4,8 @@ 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 ScheduleSyncActivity
TASK_QUEUE = "main"
from applications.schedule_sync.activities import syncronize
from applications.temporal_worker.queues import MAIN_QUEUE
@workflow.defn
@@ -19,7 +17,7 @@ class ScheduleSyncWorkflow:
action=ScheduleActionStartWorkflow(
cls.run,
id="ScheduleSyncWorkflow",
task_queue=TASK_QUEUE,
task_queue=MAIN_QUEUE,
),
spec=ScheduleSpec(
intervals=[ScheduleIntervalSpec(every=timedelta(minutes=5))]
@@ -35,7 +33,7 @@ class ScheduleSyncWorkflow:
if streamer.integrations.discord is None:
continue
await workflow.execute_activity_method(
ScheduleSyncActivity.syncronize,
await workflow.execute_activity(
syncronize,
streamer.twitch.id
)