diff --git a/Client.UnitTests/ActivateJobTest.cs b/Client.UnitTests/ActivateJobTest.cs index 3d4ef607..e7a41611 100644 --- a/Client.UnitTests/ActivateJobTest.cs +++ b/Client.UnitTests/ActivateJobTest.cs @@ -163,5 +163,44 @@ public async Task ShouldSendRequestWithFetchVariablesListReceiveResponseAsExpect AssertJob(receivedJobs[1], 2); AssertJob(receivedJobs[2], 3); } + + [Test] + public async Task ShouldSendRequestWithTenantIdsListReceiveResponseAsExpected() + { + // given + var expectedRequest = new ActivateJobsRequest + { + Type = "foo", + Worker = "jobWorker", + Timeout = 10_000L, + MaxJobsToActivate = 1, + RequestTimeout = 5_000L, + TenantIds = { "1234", "5678" } + }; + + IList tenantIds = new List { "1234", "5678" }; + TestService.AddRequestHandler(typeof(ActivateJobsRequest), _ => CreateExpectedResponse()); + + // when + var response = await ZeebeClient.NewActivateJobsCommand() + .JobType("foo") + .MaxJobsToActivate(1) + .Timeout(TimeSpan.FromSeconds(10)) + .WorkerName("jobWorker") + .PollingTimeout(TimeSpan.FromSeconds(5)) + .TenantIds(tenantIds) + .Send(); + + // then + var actualRequest = TestService.Requests[typeof(ActivateJobsRequest)][0]; + Assert.AreEqual(expectedRequest, actualRequest); + + var receivedJobs = response.Jobs; + Assert.AreEqual(receivedJobs.Count, 3); + + AssertJob(receivedJobs[0], 1); + AssertJob(receivedJobs[1], 2); + AssertJob(receivedJobs[2], 3); + } } } diff --git a/Client/Api/Commands/IActivateJobsCommandStep1.cs b/Client/Api/Commands/IActivateJobsCommandStep1.cs index b757a993..80e4b138 100644 --- a/Client/Api/Commands/IActivateJobsCommandStep1.cs +++ b/Client/Api/Commands/IActivateJobsCommandStep1.cs @@ -28,7 +28,7 @@ public interface IActivateJobsCommandStep1 IActivateJobsCommandStep2 JobType(string jobType); } - public interface IActivateJobsCommandStep2 + public interface IActivateJobsCommandStep2 { /// /// Set the maximum of jobs to activate. If less jobs are available for activation the @@ -39,7 +39,7 @@ public interface IActivateJobsCommandStep2 IActivateJobsCommandStep3 MaxJobsToActivate(int maxJobsToActivate); } - public interface IActivateJobsCommandStep3 : IFinalCommandWithRetryStep + public interface IActivateJobsCommandStep3 : ITenantIdsCommandStep, IFinalCommandWithRetryStep { /// /// Set the time for how long a job is exclusively assigned for this subscription. diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs new file mode 100644 index 00000000..62fafe9c --- /dev/null +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +namespace Zeebe.Client.Api.Commands +{ + public interface ITenantIdsCommandStep + { + /// + /// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command. + /// + /// + /// This can be useful when requesting jobs for multiple tenants at once. Each of the activated + /// jobs will be owned by the tenant that owns the corresponding process instance. + /// the identifiers of the tenants to specify for this command, e.g. ["ACME", "OTHER"] + /// The builder for this command. Call to complete the command and send it + /// to the broker. + T TenantIds(IList tenantIds); + + /// + /// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command. + /// + /// + /// This can be useful when requesting jobs for multiple tenants at once. Each of the activated + /// jobs will be owned by the tenant that owns the corresponding process instance. + /// the identifiers of the tenants to specify for this command, e.g. ["ACME", "OTHER"] + /// The builder for this command. Call to complete the command and send it + /// to the broker. + T TenantIds(params string[] tenantIds); + } +} \ No newline at end of file diff --git a/Client/Impl/Commands/ActivateJobsCommand.cs b/Client/Impl/Commands/ActivateJobsCommand.cs index 3beaf005..6890aa64 100644 --- a/Client/Impl/Commands/ActivateJobsCommand.cs +++ b/Client/Impl/Commands/ActivateJobsCommand.cs @@ -65,6 +65,20 @@ public IActivateJobsCommandStep3 WorkerName(string workerName) return this; } + public IActivateJobsCommandStep3 TenantIds(IList tenantIds) + { + Request.TenantIds.AddRange(tenantIds); + + return this; + } + + public IActivateJobsCommandStep3 TenantIds(params string[] tenantIds) + { + Request.TenantIds.AddRange(tenantIds); + + return this; + } + public async Task Send(TimeSpan? timeout = null, CancellationToken token = default) { var activateJobsResponses = new Responses.ActivateJobsResponses();