diff --git a/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Enum/TaskRunResultStatus.cs b/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Enum/TaskRunResultStatus.cs new file mode 100644 index 000000000..e2c8bf3ac --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Enum/TaskRunResultStatus.cs @@ -0,0 +1,12 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Scheduler.Enum; + +public enum TaskRunResultStatus +{ + Success = 3, + Failure = 4, + TimeoutSuccess = 6, + Ignore = 9 +} diff --git a/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Request/NotifySchedulerTaskRunResultRequest.cs b/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Request/NotifySchedulerTaskRunResultRequest.cs new file mode 100644 index 000000000..cf9414fd9 --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Request/NotifySchedulerTaskRunResultRequest.cs @@ -0,0 +1,11 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Scheduler.Request; + +public class NotifySchedulerTaskRunResultRequest: SchedulerTaskRequestBase +{ + public TaskRunResultStatus Status { get; set; } + + public string? Message { get; set; } +} diff --git a/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Service/ISchedulerTaskService.cs b/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Service/ISchedulerTaskService.cs index 9831d336e..92bed9e86 100644 --- a/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Service/ISchedulerTaskService.cs +++ b/src/BuildingBlocks/StackSdks/Masa.BuildingBlocks.StackSdks.Scheduler/Service/ISchedulerTaskService.cs @@ -8,4 +8,6 @@ public interface ISchedulerTaskService Task StopAsync(SchedulerTaskRequestBase request); Task StartAsync(SchedulerTaskRequestBase request); + + Task NotifyRunResultAsync(NotifySchedulerTaskRunResultRequest request); } diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Scheduler/Services/SchedulerTaskService.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Scheduler/Services/SchedulerTaskService.cs index 0a05a0e3f..aafbde0df 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Scheduler/Services/SchedulerTaskService.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Scheduler/Services/SchedulerTaskService.cs @@ -34,4 +34,10 @@ public async Task StartAsync(SchedulerTaskRequestBase request) await _caller.PutAsync(requestUri, requestData); return true; } + + public async Task NotifyRunResultAsync(NotifySchedulerTaskRunResultRequest request) + { + var requestUri = $"{API}/notifyRunResultBySdk"; + await _caller.PostAsync(requestUri, request); + } } diff --git a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Scheduler.Tests/SchedulerTaskServiceTest.cs b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Scheduler.Tests/SchedulerTaskServiceTest.cs index f5309c28d..16fa07848 100644 --- a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Scheduler.Tests/SchedulerTaskServiceTest.cs +++ b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Scheduler.Tests/SchedulerTaskServiceTest.cs @@ -45,4 +45,22 @@ public async Task TestStartSchedulerTaskAsync() caller.Verify(provider => provider.PutAsync(requestUri, It.IsAny(), true, default), Times.Once); Assert.IsTrue(result); } + + [TestMethod] + public async Task TestNotifyRunResultAsync() + { + var request = new NotifySchedulerTaskRunResultRequest() + { + TaskId = Guid.NewGuid(), + Status = BuildingBlocks.StackSdks.Scheduler.Enum.TaskRunResultStatus.Success, + OperatorId = Guid.NewGuid() + }; + + var requestUri = $"{API}/notifyRunResultBySdk"; + var caller = new Mock(); + caller.Setup(provider => provider.PostAsync(requestUri, It.IsAny(), true, default)).Verifiable(); + var schedulerClient = new SchedulerClient(caller.Object); + await schedulerClient.SchedulerTaskService.NotifyRunResultAsync(request); + caller.Verify(provider => provider.PostAsync(requestUri, It.IsAny(), true, default), Times.Once); + } }