Orchestration will wait for all tasks to finish even Task.WhenAny is used
- Lingua principale
- C#
- Stelle
- 1.7k
- Fork
- 335
- Merge medio
- 2g 23h
- PR unite (30g)
- 6
Descrizione
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

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:
>
>
>
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia riproducendo l’orchestrazione con DummyOrchestration.RunTask e DummyActivity.ExecuteAsync usando le versioni dei pacchetti indicate. Traccia Task.WhenAny, l’annullamento di CreateTimer e il comportamento della coda degli elementi di lavoro. Il lavoro è completato quando l’orchestrazione raggiunge il suo stato terminale dopo il timeout senza attendere l’attività di lunga durata e il comportamento di annullamento previsto è documentato o testato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- backend, distributed-systems
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100