ORLEANS0227: Run durable operations outside DurableTask.RunInline effects
| Property | Value |
|---|---|
| Severity | Error |
| Category | Usage |
| Code fix | None |
The delegate of a DurableTask.RunInline effect starts a durable task, with ScheduleAsync or Post, or checks a version, with DurableTask.GetVersion, DurableVersion.Get, or DurableVersion.IsAtLeast:
public async DurableTask<int> EnrollAsync(string student){ var seat = DurableTask.RunInline("seat", () => { var number = ++_enrolled.Value;
// The version check throws InvalidOperationException, which the effect records as its outcome. if (Welcomes.IsAtLeast(1)) { _ = GrainFactory.GetGrain<IStudentMail>(student).WelcomeAsync(student, number).WithId("welcome").Detached().Post(); }
return number; });
await Confirm(student, seat).WithId("confirm"); return seat;}Rule description
Section titled “Rule description”A replay returns an effect’s recorded outcome without running the effect. A durable operation in the effect would run in the first run only: the replay would miss it, and the identifiers of the body’s later operations would shift.
The runtime throws InvalidOperationException for a durable operation inside an effect, and the effect records the exception as its outcome. Changes which the effect made before the throw commit with the recorded exception. In the example, the version check throws after the seat count increments, the increment commits, and every run of the body, including every replay, receives the recorded exception from DurableTask.RunInline.
A DurableTask.RunInline call inside an effect runs as part of the enclosing effect, and its outcome is part of the enclosing effect’s outcome.
For effects, see Effects and steps.
How to fix violations
Section titled “How to fix violations”Run the operations in the body. Check versions and start tasks before or after the effect. Pass values into the effect through its closure, and return values from it:
public async DurableTask<int> EnrollAndWelcomeAsync(string student){ // The effect returns the seat, and the body checks the version and starts the welcome. var seat = DurableTask.RunInline("seat", () => ++_enrolled.Value); if (Welcomes.IsAtLeast(1)) { _ = GrainFactory.GetGrain<IStudentMail>(student).WelcomeAsync(student, seat).WithId("welcome").Detached().Post(); }
await Confirm(student, seat).WithId("confirm"); return seat;}When to suppress
Section titled “When to suppress”Keep the diagnostic enabled: a durable operation in an effect throws InvalidOperationException, which the effect records as its outcome.
