dapr / python-sdk

Dapr SDK for Python
Apache License 2.0
230 stars 128 forks source link

[Workflow] DaprWorkflowContext create_timer method should accept a timedelta #625

Closed cgillum closed 11 months ago

cgillum commented 1 year ago

Describe the proposal

In DaprWorkflowContext the create_timer method is defined as follows:

def create_timer(self, fire_at: datetime) -> task.Task:

However, it would be more convenient to also support timedelta as a parameter type. Note that the undelrying Durable Task SDK already supports this:

def create_timer(self, fire_at: Union[datetime, timedelta]) -> Task:

The workaround is that developers must do the following:

ctx.create_timer(ctx.current_utc_datetime + SOME_TIME_DELTA)

This workaround is problematic because it can tempt users to violate code constraint rules if they accidentally use datetime.now(), which is non-deterministic, instead of ctx.current_utc_datetime.

Ideally, users could simply write the following:

ctx.create_timer(SOME_TIME_DELTA)