Azure / Azure/durabletask

Timer not firing

Open
#1,169 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.7k
Forks
335
Avg merge
2d 23h
Merged PRs (30d)
6

Description

In one of my orchestrations a timer gets based on a date specified in the orchestration input object. This date sometimes needs to be updated after the orchestration has started. I am currently trying to implement an event that cancels the existing timer and creates a new timer with the updated date.

I am able to cancel the existing timer successfully and also I am able to set a new timer but the new timer does not seem to be firing.

![image](https://github.com/user-attachments/assets/3631729a-f427-45d0-b0ae-eac4eac0ddcb)

my onEvent method in my orchestration finds the required event handler based on the input and then calls the HandleProcess method.

```c#
public override async void OnEvent(OrchestrationContext context, string eventName, string input)
{
IEventHandler eventHandler = await context.ScheduleTask(typeof(GetEventHandler), eventName);

EventHandlerInput eventInput = new EventHandlerInput(context, customState, input);
customState = eventHandler.HandleProcess(eventInput);
}
```

The date change event handler HandleProcess method cancels the current timer and schedules a new timer
```c#
public CustomOrchestrationState HandleProcess(T input)
{
EventHandlerInput customInput = (input as EventHandlerInput);

if (!customInput.CustomOrchestrationState.AllowActionDateChange)
{
//date change not allowed
throw new Exception();
}

DateTime newDate = new DateTime();

try
{
newDate = Convert.ToDateTime(customInput.EventInput);
}
catch (Exception ex)
{
//Invalid Date format
}

CancellationTokenSource newToken = new CancellationTokenSource();
customInput.OrchestrationContext.CreateTimer(newDate, customInput, newToken.Token);

customInput.CustomOrchestrationState.TimerCancelationToken?.Dispose();

CancelCurrentTimer(customInput.CustomOrchestrationState);

customInput.CustomOrchestrationState.ActionDate = newDate;
customInput.CustomOrchestrationState.TimerCancelationToken = newToken;

return customInput.CustomOrchestrationState;
}
```

In the SQL database I can see that the new timer is created but the orchestration seems to stay stuck when the new timer should have fired.

![image](https://github.com/user-attachments/assets/a47a3bc0-7168-47fd-a65e-f71a89eba101)

Is this behavior expected or is it a bug? Any suggestions on how I can debug this issue or any improvements I can implement to get this working.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.