Skip to content

Commit

Permalink
Add new TaskOption overload for skipping input param (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
jviau authored Jan 25, 2023
1 parent abd41bd commit 448e92f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
1 change: 1 addition & 0 deletions samples/AzureFunctionsApp/AzureFunctionsApp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
Expand Down
3 changes: 2 additions & 1 deletion src/Abstractions/TaskActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public interface ITaskActivity
/// Because activities only guarantee at least once execution, it's recommended that activity logic be implemented as
/// idempotent whenever possible.
/// </para><para>
/// Activities are invoked by orchestrators using one of the <see cref="TaskOrchestrationContext.CallActivityAsync"/>
/// Activities are invoked by orchestrators using one of the
/// <see cref="TaskOrchestrationContext.CallActivityAsync(TaskName, object?, TaskOptions?)"/>
/// method overloads. Activities that derive from <see cref="TaskActivity{TInput, TOutput}"/> can also be invoked
/// using generated extension methods. To participate in code generation, an activity class must be decorated with the
/// <see cref="DurableTaskAttribute"/> attribute. The source generator will then generate a <c>CallMyActivityAsync()</c>
Expand Down
50 changes: 38 additions & 12 deletions src/Abstractions/TaskOrchestrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,30 @@ public abstract class TaskOrchestrationContext
/// <see cref="TaskFailedException.FailureDetails"/> property.
/// </exception>
public virtual Task CallActivityAsync(TaskName name, object? input = null, TaskOptions? options = null)
{
return this.CallActivityAsync<object>(name, input, options);
}
=> this.CallActivityAsync<object>(name, input, options);

/// <returns>
/// A task that completes when the activity completes or fails. The result of the task is the activity's return value.
/// </returns>
/// <inheritdoc cref="CallActivityAsync(TaskName, object?, TaskOptions?)"/>
public virtual Task CallActivityAsync(TaskName name, TaskOptions options)
=> this.CallActivityAsync(name, null, options);

/// <returns>
/// A task that completes when the activity completes or fails. The result of the task is the activity's return value.
/// </returns>
/// <inheritdoc cref="CallActivityAsync"/>
public abstract Task<T> CallActivityAsync<T>(TaskName name, object? input = null, TaskOptions? options = null);
/// <typeparam name="TResult">The type into which to deserialize the activity's output.</typeparam>
/// <inheritdoc cref="CallActivityAsync(TaskName, object?, TaskOptions?)"/>
public virtual Task<TResult> CallActivityAsync<TResult>(TaskName name, TaskOptions options)
=> this.CallActivityAsync<TResult>(name, null, options);

/// <returns>
/// A task that completes when the activity completes or fails. The result of the task is the activity's return value.
/// </returns>
/// <typeparam name="TResult">The type into which to deserialize the activity's output.</typeparam>
/// <inheritdoc cref="CallActivityAsync(TaskName, object?, TaskOptions?)"/>
public abstract Task<TResult> CallActivityAsync<TResult>(
TaskName name, object? input = null, TaskOptions? options = null);

/// <summary>
/// Creates a durable timer that expires after the specified delay.
Expand Down Expand Up @@ -247,13 +262,26 @@ public async Task<T> WaitForExternalEvent<T>(string eventName, TimeSpan timeout)
/// <summary>
/// Executes a named sub-orchestrator and returns the result.
/// </summary>
/// <typeparam name="TResult">
/// The type into which to deserialize the sub-orchestrator's output.
/// </typeparam>
/// <typeparam name="TResult">The type into which to deserialize the sub-orchestrator's output.</typeparam>
/// <inheritdoc cref="CallSubOrchestratorAsync(TaskName, object?, TaskOptions?)"/>
public abstract Task<TResult> CallSubOrchestratorAsync<TResult>(
TaskName orchestratorName, object? input = null, TaskOptions? options = null);

/// <summary>
/// Executes a named sub-orchestrator and returns the result.
/// </summary>
/// <typeparam name="TResult">The type into which to deserialize the sub-orchestrator's output.</typeparam>
/// <inheritdoc cref="CallSubOrchestratorAsync(TaskName, object?, TaskOptions?)"/>
public virtual Task<TResult> CallSubOrchestratorAsync<TResult>(TaskName orchestratorName, TaskOptions options)
=> this.CallSubOrchestratorAsync<TResult>(orchestratorName, null, options);

/// <summary>
/// Executes a named sub-orchestrator and returns the result.
/// </summary>
/// <inheritdoc cref="CallSubOrchestratorAsync(TaskName, object?, TaskOptions?)"/>
public virtual Task CallSubOrchestratorAsync(TaskName orchestratorName, TaskOptions options)
=> this.CallSubOrchestratorAsync(orchestratorName, null, options);

/// <summary>
/// Executes a named sub-orchestrator.
/// </summary>
Expand Down Expand Up @@ -296,11 +324,9 @@ public abstract Task<TResult> CallSubOrchestratorAsync<TResult>(
/// The sub-orchestration failed with an unhandled exception. The details of the failure can be found in the
/// <see cref="TaskFailedException.FailureDetails"/> property.
/// </exception>
public Task CallSubOrchestratorAsync(
public virtual Task CallSubOrchestratorAsync(
TaskName orchestratorName, object? input = null, TaskOptions? options = null)
{
return this.CallSubOrchestratorAsync<object>(orchestratorName, input, options);
}
=> this.CallSubOrchestratorAsync<object>(orchestratorName, input, options);

/// <summary>
/// Restarts the orchestration with a new input and clears its history.
Expand Down
3 changes: 2 additions & 1 deletion src/Abstractions/TaskOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public interface ITaskOrchestrator
/// </para>
/// <para>
/// Orchestrators can be scheduled using an external client (see Microsoft.DurableTask.Client). Orchestrators can
/// also invoke child orchestrators using the <see cref="TaskOrchestrationContext.CallSubOrchestratorAsync"/> method.
/// also invoke child orchestrators using the
/// <see cref="TaskOrchestrationContext.CallSubOrchestratorAsync(TaskName, object?, TaskOptions?)"/> method.
/// Orchestrators that derive from <see cref="TaskOrchestrator{TInput, TOutput}"/> can also be invoked using
/// generated extension methods. To participate in code generation, an orchestrator class must be decorated with the
/// <see cref="DurableTaskAttribute"/> attribute. The source generator will then generate a
Expand Down
5 changes: 5 additions & 0 deletions src/Client/Core/DurableTaskClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public virtual Task<string> ScheduleNewOrchestrationInstanceAsync(
TaskName orchestratorName, object? input, CancellationToken cancellation)
=> this.ScheduleNewOrchestrationInstanceAsync(orchestratorName, input, null, cancellation);

/// <inheritdoc cref="ScheduleNewOrchestrationInstanceAsync(TaskName, object, StartOrchestrationOptions, CancellationToken)"/>
public virtual Task<string> ScheduleNewOrchestrationInstanceAsync(
TaskName orchestratorName, StartOrchestrationOptions options, CancellationToken cancellation = default)
=> this.ScheduleNewOrchestrationInstanceAsync(orchestratorName, null, options, cancellation);

/// <summary>
/// Schedules a new orchestration instance for execution.
/// </summary>
Expand Down

0 comments on commit 448e92f

Please sign in to comment.