Skip to content

Improve TimerTask#122

Open
andystaples wants to merge 6 commits intomicrosoft:mainfrom
andystaples:andystaples/add-task-cancellation
Open

Improve TimerTask#122
andystaples wants to merge 6 commits intomicrosoft:mainfrom
andystaples:andystaples/add-task-cancellation

Conversation

@andystaples
Copy link
Contributor

Adds the following to improve TimerTask:

  1. Adds support for task cancellation, enabling patterns like:
    def orchestrator(ctx: task.OrchestrationContext, _):
        approval: task.Task[bool] = ctx.wait_for_external_event('Approval')
        timeout = ctx.create_timer(timedelta(seconds=3))
        winner = yield task.when_any([approval, timeout])
        if winner == approval:
            # Explicitly cancel the timer so it does not linger
            timeout.cancel()
            return "approved"
        else:
            return "timed out"
  1. Adds support for LongTimers with configurable max_timer_interval, so that backends with limits on timer duration can be used

Resolves #95
Resolves #101

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Durable Task Python SDK’s timer functionality by adding (1) task cancellation support for timers/external-event waits and (2) long-timer chunking to accommodate backends with maximum timer duration limits (resolving #95 and #101).

Changes:

  • Introduces CancellableTask/TaskCanceledError and wires cancellation into timer + external event tasks.
  • Adds LongTimerTask and updates orchestration execution to chunk long timers based on a maximum interval (default 3 days).
  • Expands orchestration executor tests to cover long-timer chunking, cancellation after when_any, and long retry timers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
durabletask/worker.py Implements long-timer chunk scheduling in the runtime context and executor; adds a maximum_timer_interval configuration knob.
durabletask/task.py Adds cancellable task primitives and long-timer task implementation.
tests/durabletask/test_orchestration_executor.py Adds unit tests for long-timer chunking/cancellation and retry behavior with long timers.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for long timers Provide an API to cancel a Task

2 participants