Skip to content

Avoid duplication of task execution #319

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 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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