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

Timer not firing #1169

Open
PauloDeJesus-JT opened this issue Oct 1, 2024 · 0 comments
Open

Timer not firing #1169

PauloDeJesus-JT opened this issue Oct 1, 2024 · 0 comments

Comments

@PauloDeJesus-JT
Copy link

PauloDeJesus-JT commented Oct 1, 2024

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

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

public override async void OnEvent(OrchestrationContext context, string eventName, string input)
{
    IEventHandler eventHandler = await context.ScheduleTask<IEventHandler>(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

public CustomOrchestrationState HandleProcess<T>(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

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.

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

No branches or pull requests

1 participant