Skip to content
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

Added schedule_id label to the task. #320

Merged
merged 1 commit into from
Apr 27, 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
9 changes: 9 additions & 0 deletions docs/guide/scheduling-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,12 @@ Or it can be done manually, by calling `delete_schedule` on schedule source prov
```python
await redis_source.delete_schedule(schedule.schedule_id)
```

Also, you can get schedule_id from the tasks's labels.

```python
@broker.task
async def my_task(context: Context = TaskiqDepends()) -> None:
schedule_id = context.message.labels.get("schedule_id")
print("Schedule ID:", schedule_id)
```
3 changes: 2 additions & 1 deletion taskiq/cli/scheduler/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ async def run_scheduler_loop(scheduler: TaskiqScheduler) -> None:
task_delay = get_task_delay(task)
except ValueError:
logger.warning(
"Cannot parse cron: %s for task: %s",
"Cannot parse cron: %s for task: %s, schedule_id: %s",
task.cron,
task.task_name,
task.schedule_id,
)
continue
if task_delay is not None:
Expand Down
4 changes: 3 additions & 1 deletion taskiq/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ async def on_ready(self, source: "ScheduleSource", task: ScheduledTask) -> None:
except ScheduledTaskCancelledError:
logger.info("Scheduled task %s has been cancelled.", task.task_name)
else:
await AsyncKicker(task.task_name, self.broker, task.labels).kiq(
await AsyncKicker(task.task_name, self.broker, task.labels).with_labels(
schedule_id=task.schedule_id,
).kiq(
*task.args,
**task.kwargs,
)
Expand Down
Loading