Conversation
|
This is pretty much done - I'm just having trouble with the: it's not actually time-skipping and I'm not sure why given that it's essentially following what's in the docs I've made the assertion following that statement to fail, just to make sure that this doesn't pass CI. |
src/SleepForDays/Activities.cs
Outdated
There was a problem hiding this comment.
Renamed class to Activities
| using Temporalio.Workflows; | ||
|
|
||
| [Workflow] | ||
| public class SleepForDaysWorkflow |
There was a problem hiding this comment.
Class name should match pre-extension part of file name (should probably change file name in this case)
There was a problem hiding this comment.
Renamed file to SleepForDaysWorkflow.workflow.cs, looks a bit odd.
There was a problem hiding this comment.
Yeah, though that same seemingly-odd name is present on similar files/workflows in this repo
There was a problem hiding this comment.
| isComplete = false; |
This is dangerous because it will overwrite a signal that comes before the workflow starts (and bool fields default to false anyways)
There was a problem hiding this comment.
Good point, didn't consider this. Don't think this is a real concern with this sample, but I get that this might not be a pattern we want to demonstrate to new users. Removed.
There was a problem hiding this comment.
| private bool isComplete; | |
| private bool complete; |
"is" prefix not usually needed in .NET
There was a problem hiding this comment.
Can be a bit confusing to users for the send-email subject to be what the workflow is doing next, but not a big deal
There was a problem hiding this comment.
There is an overload of WaitConditionAsync that accepts a timeout
There was a problem hiding this comment.
We considered this, but figured having a direct sleep more clearly showed the ability to wait for long periods of time.
There was a problem hiding this comment.
The concern here is that we usually encourage samples to look like a user should write them. It also depends on if we're making a simple sample like for the website or not. If so and we want a clear "sleep" for this sample, we should consider using workflow cancellation as the interrupt mechanism because, even though we may not recommend cancellation as control flow, it makes the sample much more legible to a first-time viewer.
There was a problem hiding this comment.
Yeah that's true. The intention is for this to be a reference for the web sample and the discussion on Slack leaned towards using the workflow function and stripping out the signal stuff if it's too complicated.
But imo I agree. I err on the side of no interrupt mechanism at all, would be the simplest to read for a new viewer. But we have some consensus on this already and some samples already merged. I don't think it's worth re-opening the discussion or being inconsistent with the other samples, especially given the scope.
There was a problem hiding this comment.
Won't hold up this PR on this FWIW, but when we get to the public site content, I think it may not look like a sample
There was a problem hiding this comment.
Yeah I think that's fair. Marketing team asked for PRs yesterday which I shared, with a little addendum that if they want simpler examples I can send them code snippets with the signal handling stuff removed. I don't think it's a bad thing that the actual sample has the signal handling, it's useful.
There was a problem hiding this comment.
| public async Task CompleteAsync() | |
| { | |
| isComplete = true; | |
| } | |
| public async Task CompleteAsync() => isComplete = true; |
Can shorten some of these one-liners if you want
| // Sleep for 90 days | ||
| await env.DelayAsync(TimeSpan.FromDays(90)); |
There was a problem hiding this comment.
Are you sure you're not time skipping before the workflow is even waiting for the number of days? You may be time skipping before the workflow even reaches the wait condition.
There was a problem hiding this comment.
I hadn't considered that. Is there a way to test for this? Maybe with a query?
There was a problem hiding this comment.
Yeah, it's a bit rough, but that's what we've done in other situations is waited for a workflow to reach a certain state. One way is to have the activity you're mocking let you know at least that part has been reached. But otherwise, yeah a loop until history has a timer event may be best here.
There was a problem hiding this comment.
Added a check that the timer exists before time-skipping. That fixed the time-skipping issue I mentioned at the beginning, seems like that was indeed the cause of the issue. Thanks!
There was a problem hiding this comment.
| await Task.WhenAny( | |
| await Workflow.WhenAnyAsync( |
Even though Task.WhenAny( technically works here in most cases, we encourage the safer wrapper
There was a problem hiding this comment.
Didn't realize there was a workflow wrapper, switched.
cretz
left a comment
There was a problem hiding this comment.
Also, make sure that this .csproj is added to the primary solution (sln) file. Can see what's there with dotnet sln list and can add with dotnet sln add. Also don't forget to add this sample to README list.
There was a problem hiding this comment.
Forgot to push that change, whoops.
Added to sln via dotnet sln add src/SleepForDays, seems to look right.
Added to README as well
|
Am I correct in thinking that Saw this failure in CI when I had the |
There was a problem hiding this comment.
The final assert can never be false. Would recommend only looping a certain number of times and sleeping a short bit between each fetch.
Actually, I just realized even in samples we have a AssertMore.EventuallyAsync helper, so you could probably just have:
await AssertMore.EventuallyAsync(async () =>
{
var history = await handle.FetchHistoryAsync();
Assert.Contains(history.Events, e => e.TimerStartedEventAttributes != null);
});(untested but the idea is there)
There was a problem hiding this comment.
Oh much nicer. I've also updated the activity execution count assertions. By the time the timer event for the sleep/delay is in history, we should have already executed the activity once. Skipping 90 more days should then give us 4 total executions not 3, which was erroneous. I wonder why that passed, if the timer existed in history before, then we still would have had to execute the activity, we still should have had 4 executions not 3.
Yes, though we should probably relax it one day for macOS since its translation layer can run x64 binaries |
cretz
left a comment
There was a problem hiding this comment.
Looks great, feel free to merge if/when CI passes
|
TYFR! |
added
sleep-for-dayssample