Skip to content

Conversation

@jakejscott
Copy link
Contributor

What was changed

Add an updatable timer sample

  1. Closes Sample request: Updatable timer #96 and Sample request: Updateable timer #59

  2. How was this tested:
    Tested this manually by running it a few times.

  3. Any docs updates needed?
    Updated the main readme

@jakejscott jakejscott requested a review from a team as a code owner November 30, 2025 02:09
Copy link
Member

Choose a reason for hiding this comment

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

Looks great! One request - can we add a test for this workflow? I know we don't technically have them for all samples, but we do for most. May be able to leverage time skipping and even check history events if you'd like. Let us know if we can help w/ the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome will do!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cretz Added tests, let me know if there's anything you'd change, thanks!

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, only thing really needed IMO is to add an event check on the test that does the update. Everything else optional.

(MyWorkflow wf) => wf.RunAsync(wakeUpTime),
new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker.Options.TaskQueue!));

await AssertMore.EventuallyAsync(async () =>
Copy link
Member

Choose a reason for hiding this comment

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

Would move this to after GetResultAsync and not have it be an EventuallyAsync but rather just check the history inline

Comment on lines 70 to 71
// Sleep for 30 days
await env.DelayAsync(TimeSpan.FromDays(30));
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed, GetResultAsync automatically skips time

var wakeUpTime2 = await handle.QueryAsync(workflow => workflow.GetWakeUpTime);
Assert.Equal(inAnHour, wakeUpTime2, precision: TimeSpan.FromSeconds(5));

await handle.GetResultAsync();
Copy link
Member

Choose a reason for hiding this comment

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

Would suggest checking history after this one, including confirming that a timer canceled event is present for that first timer


namespace TemporalioSamples.UpdatableTimer;

public class UpdatableTimer(DateTimeOffset wakeUpTime)
Copy link
Member

Choose a reason for hiding this comment

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

Optional neat improvement, support providing a summary for the timer that appears in the UI (there is a WaitConditionAsync overload that accepts options now which includes a summary)

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! There is some kind of hang with the CI process. We are investigating.

[Fact]
public async Task SimpleRun_Succeeds()
{
await using var env = await WorkflowEnvironment.StartLocalAsync();
Copy link
Member

Choose a reason for hiding this comment

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

Technically "start local" is a tad heavy so we prefer reusing it in tests by having classes extend WorkflowEnvironmentTestBase and use a unique task queue (though not all tests seem to have done that). But I didn't catch it before and it's not a big deal.

var handle = await env.Client.StartWorkflowAsync(
(MyWorkflow wf) => wf.RunAsync(wakeUpTime),
new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker.Options.TaskQueue!));
await handle.GetResultAsync();
Copy link
Member

Choose a reason for hiding this comment

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

Ok, I see the problem. This hangs in CI for 30 days heh, may want start time skipping instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No probs, have updated to use skipping.

@cretz
Copy link
Member

cretz commented Dec 4, 2025

There is a slight .NET whitespace formatting issue that showed up in CI for another sample, I am going to fix in your branch then merge.

@cretz cretz merged commit 0dc8fc9 into temporalio:main Dec 4, 2025
10 of 11 checks passed
@jakejscott jakejscott deleted the updatable-timer branch December 4, 2025 21:06
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.

Sample request: Updatable timer

2 participants