diff --git a/src/DurableTask.Core/DurableTask.Core.csproj b/src/DurableTask.Core/DurableTask.Core.csproj index 39716bbc9..4bedc92a8 100644 --- a/src/DurableTask.Core/DurableTask.Core.csproj +++ b/src/DurableTask.Core/DurableTask.Core.csproj @@ -17,7 +17,7 @@ 3 - 0 + 1 0 $(MajorVersion).$(MinorVersion).$(PatchVersion) $(VersionPrefix).0 diff --git a/src/DurableTask.Core/TaskActivityDispatcher.cs b/src/DurableTask.Core/TaskActivityDispatcher.cs index 1c22c307f..bdafffdd5 100644 --- a/src/DurableTask.Core/TaskActivityDispatcher.cs +++ b/src/DurableTask.Core/TaskActivityDispatcher.cs @@ -184,7 +184,11 @@ await this.dispatchPipeline.RunAsync(dispatchContext, async _ => throw new TypeMissingException($"TaskActivity {scheduledEvent.Name} version {scheduledEvent.Version} was not found"); } - var context = new TaskContext(taskMessage.OrchestrationInstance); + var context = new TaskContext( + taskMessage.OrchestrationInstance, + scheduledEvent.Name, + scheduledEvent.Version, + scheduledEvent.EventId); context.ErrorPropagationMode = this.errorPropagationMode; HistoryEvent? responseEvent; diff --git a/src/DurableTask.Core/TaskContext.cs b/src/DurableTask.Core/TaskContext.cs index f959ef12c..d8152976c 100644 --- a/src/DurableTask.Core/TaskContext.cs +++ b/src/DurableTask.Core/TaskContext.cs @@ -10,7 +10,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // ---------------------------------------------------------------------------------- - +#nullable enable namespace DurableTask.Core { /// @@ -23,8 +23,19 @@ public class TaskContext /// /// public TaskContext(OrchestrationInstance orchestrationInstance) + : this(orchestrationInstance, string.Empty, null, -1) + { + } + + /// + /// Creates a new TaskContext with the supplied OrchestrationInstance and taskId + /// + public TaskContext(OrchestrationInstance orchestrationInstance, string name, string? version, int taskId) { OrchestrationInstance = orchestrationInstance; + Name = name; + Version = version; + TaskId = taskId; } /// @@ -32,6 +43,21 @@ public TaskContext(OrchestrationInstance orchestrationInstance) /// public OrchestrationInstance OrchestrationInstance { get; private set; } + /// + /// Gets the name of the task + /// + public string Name { get; } + + /// + /// Gets the version of the task, if any. + /// + public string? Version { get; } + + /// + /// Gets the ID of the task, which is a sequential number unique to the orchestration instance. + /// + public int TaskId { get; } + /// /// Gets or sets a value indicating how to propagate unhandled exception metadata. /// diff --git a/src/DurableTask.Core/TaskOrchestrationContext.cs b/src/DurableTask.Core/TaskOrchestrationContext.cs index 8a48cbe93..7908eeb07 100644 --- a/src/DurableTask.Core/TaskOrchestrationContext.cs +++ b/src/DurableTask.Core/TaskOrchestrationContext.cs @@ -245,6 +245,13 @@ public override Task CreateTimer(DateTime fireAt, T state) public override async Task CreateTimer(DateTime fireAt, T state, CancellationToken cancelToken) { + if (state is CancellationToken) + { + throw new ArgumentException( + "The state parameter cannot be a CancellationToken. Did you mean to use a different overload?", + paramName: nameof(state)); + } + int id = this.idCounter++; var createTimerOrchestratorAction = new CreateTimerOrchestratorAction { diff --git a/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs b/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs index 1c505cc2f..6b5593b25 100644 --- a/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs +++ b/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs @@ -3148,7 +3148,7 @@ public override async Task RunTask(OrchestrationContext context, TimeSpa using (var cts = new CancellationTokenSource()) { Task approvalTask = this.GetWaitForApprovalTask(); - Task timeoutTask = context.CreateTimer(deadline, cts.Token); + Task timeoutTask = context.CreateTimer(deadline, true, cts.Token); if (shouldFail) {