Skip to content

Commit

Permalink
Avoid duplication of task execution (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
Temik26 authored Apr 26, 2024
1 parent a744988 commit bfcc7d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/framework_integrations/taskiq-with-aiogram.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bot = Bot(token="TOKEN")
@dp.startup()
async def setup_taskiq(bot: Bot, *_args, **_kwargs):
# Here we check if it's a clien-side,
# Becuase otherwise you're going to
# Because otherwise you're going to
# create infinite loop of startup events.
if not broker.is_worker_process:
logging.info("Setting up taskiq")
Expand Down
7 changes: 3 additions & 4 deletions taskiq/cli/scheduler/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ async def run_scheduler_loop(scheduler: TaskiqScheduler) -> None:
running_schedules = set()
while True:
# We use this method to correctly sleep for one minute.
next_minute = datetime.now().replace(second=0, microsecond=0) + timedelta(
minutes=1,
)
scheduled_tasks = await get_all_schedules(scheduler)
for source, task_list in scheduled_tasks.items():
for task in task_list:
Expand All @@ -165,7 +162,9 @@ async def run_scheduler_loop(scheduler: TaskiqScheduler) -> None:
)
running_schedules.add(send_task)
send_task.add_done_callback(running_schedules.discard)

next_minute = datetime.now().replace(second=0, microsecond=0) + timedelta(
minutes=1,
)
delay = next_minute - datetime.now()
await asyncio.sleep(delay.total_seconds())

Expand Down

0 comments on commit bfcc7d2

Please sign in to comment.