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

Backend feature: restart task #205

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions karton/core/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,29 @@ def consume_routed_task(self, identity: str, timeout: int = 5) -> Optional[Task]
queue, data = item
return self.get_task(data)

def restart_task(self, task: Task) -> Task:
"""
Requeues consumed task back to the consumer queue.

New task is created with new uid and can be consumed by any active replica.

Original task is marked as finished.

:param task: Task to be restarted
:return: Restarted task object
"""
new_task = task.fork_task()
# Preserve orig_uid to point at unrouted task
new_task.orig_uid = task.orig_uid
new_task.status = TaskState.SPAWNED

p = self.make_pipeline()
self.register_task(new_task, pipe=p)
self.produce_routed_task(new_task.headers["receiver"], new_task, pipe=p)
self.set_task_status(task, status=TaskState.FINISHED, pipe=p)
p.execute()
return new_task

@staticmethod
def _log_channel(logger_name: Optional[str], level: Optional[str]) -> str:
return ".".join(
Expand Down