Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivateJobsCommand updated to set tenantIds. #594

39 changes: 39 additions & 0 deletions Client.UnitTests/ActivateJobTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> tenantIds = new List<string> { "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);
}
}
}
4 changes: 2 additions & 2 deletions Client/Api/Commands/IActivateJobsCommandStep1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IActivateJobsCommandStep1
IActivateJobsCommandStep2 JobType(string jobType);
}

public interface IActivateJobsCommandStep2
public interface IActivateJobsCommandStep2
{
/// <summary>
/// Set the maximum of jobs to activate. If less jobs are available for activation the
Expand All @@ -39,7 +39,7 @@ public interface IActivateJobsCommandStep2
IActivateJobsCommandStep3 MaxJobsToActivate(int maxJobsToActivate);
}

public interface IActivateJobsCommandStep3 : IFinalCommandWithRetryStep<IActivateJobsResponse>
public interface IActivateJobsCommandStep3 : ITenantIdsCommandStep<IActivateJobsCommandStep3>, IFinalCommandWithRetryStep<IActivateJobsResponse>
{
/// <summary>
/// Set the time for how long a job is exclusively assigned for this subscription.
Expand Down
29 changes: 29 additions & 0 deletions Client/Api/Commands/ITenantIdsCommandStep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;

namespace Zeebe.Client.Api.Commands
{
public interface ITenantIdsCommandStep<out T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 We could either add here a single AddTenant or extend the previous introduced interface

{
/// <summary>
/// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command.
/// </summary>
ChrisKujawa marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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.
/// <param name="tenantIds">the identifiers of the tenants to specify for this command, e.g. ["ACME", "OTHER"]</param>
/// <returns>The builder for this command. Call <see cref="IFinalCommandStep{T}.Send"/> to complete the command and send it
/// to the broker.</returns>
T TenantIds(IList<string> tenantIds);

/// <summary>
/// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command.
/// </summary>
ChrisKujawa marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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.
/// <param name="tenantIds">the identifiers of the tenants to specify for this command, e.g. ["ACME", "OTHER"]</param>
/// <returns>The builder for this command. Call <see cref="IFinalCommandStep{T}.Send"/> to complete the command and send it
/// to the broker.</returns>
T TenantIds(params string[] tenantIds);
}
}
14 changes: 14 additions & 0 deletions Client/Impl/Commands/ActivateJobsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ public IActivateJobsCommandStep3 WorkerName(string workerName)
return this;
}

public IActivateJobsCommandStep3 TenantIds(IList<string> tenantIds)
{
Request.TenantIds.AddRange(tenantIds);

return this;
}

public IActivateJobsCommandStep3 TenantIds(params string[] tenantIds)
{
Request.TenantIds.AddRange(tenantIds);

return this;
}

public async Task<IActivateJobsResponse> Send(TimeSpan? timeout = null, CancellationToken token = default)
{
var activateJobsResponses = new Responses.ActivateJobsResponses();
Expand Down
Loading