Skip to content

Commit

Permalink
Merge pull request #594 from ShawnAbshire/sabshire-multi-tenancy-acti…
Browse files Browse the repository at this point in the history
…vatejobs

ActivateJobsCommand updated to set tenantIds.
  • Loading branch information
ChrisKujawa authored Feb 1, 2024
2 parents 99c9ae6 + 8ffaa88 commit fd27f56
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
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>
{
/// <summary>
/// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command.
/// </summary>
///
/// 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>
///
/// 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

0 comments on commit fd27f56

Please sign in to comment.