Azure / Azure/durabletask

Orchestration will wait for all tasks to finish even Task.WhenAny is used

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

Description

I found that Task.WhenAny did not work with orchestration properly, the status of orchestration only become completed where all the scheduled tasks are finished.

My orchestration goes like:
```
public enum OperationState
{
Successful,

Failed,

InProgess,

Timeout
}

public class DummyOrchestration : TaskOrchestration
{
public override async Task RunTask(OrchestrationContext context, string input)
{
using (var timeoutCts = new CancellationTokenSource())
{
Task user = context.ScheduleTask(typeof(DummyActivity), input);
Task timer = context.CreateTimer(context.CurrentUtcDateTime.AddSeconds(60), OperationState.Timeout, timeoutCts.Token);

var resultTask = await Task.WhenAny(user, timer);
if(resultTask == user)
{
timeoutCts.Cancel();
}

Console.WriteLine($"{DateTimeOffset.Now}: Orchestration finished with {resultTask.Result}");
return resultTask.Result;
}
}
}
```

And my activity goes like:

```
public sealed class DummyActivity : AsyncTaskActivity
{
protected override async Task ExecuteAsync(TaskContext context, string input)
{
Console.WriteLine($"{DateTimeOffset.Now}: Dummy {input} recevied, will finished in one day!");

// Simulate some long running actions
await Task.Delay(TimeSpan.FromDays(1));

return OperationState.Successful;
}
}
```
From the console log, I could see that the orchestration RunTask code actually finished, but it behaves like the long running DummyActivity prevent its status to becoming completed and I could see there are 1 message in the workitem queue.

> 7/5/2020 7:22:38 PM +08:00: Dummy input1 recevied, will finished in one day!
> 7/5/2020 7:24:00 PM +08:00: Orchestration finished with Timeout

![image](https://user-images.githubusercontent.com/61817681/86531766-a18fa780-bef6-11ea-907d-6b7d3213066d.png)

From the [issue](https://github.com/Azure/durabletask/issues/155), I know for timer task, I could use an cancellation token to cancel any pending timers, but how can I cancel a long running TaskActivity?

Package information:

>
>
>

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.