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

fix(client): Add delay within catch block in JobWorker.PollJobs to avoid server hogging. #217

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Client/Impl/Commands/ActivateJobsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using GatewayProtocol;
using Zeebe.Client.Api.Commands;
using Zeebe.Client.Api.Misc;
using Zeebe.Client.Api.Responses;
using static GatewayProtocol.Gateway;

Expand All @@ -13,9 +14,11 @@ internal class ActivateJobsCommand : IActivateJobsCommandStep1, IActivateJobsCom
{
private readonly JobActivator activator;
public ActivateJobsRequest Request { get; }
private readonly IAsyncRetryStrategy asyncRetryStrategy;

public ActivateJobsCommand(GatewayClient client)
public ActivateJobsCommand(GatewayClient client, IAsyncRetryStrategy asyncRetryStrategy)
{
this.asyncRetryStrategy = asyncRetryStrategy;
activator = new JobActivator(client);
Request = new ActivateJobsRequest();
}
Expand Down Expand Up @@ -72,9 +75,14 @@ public async Task<IActivateJobsResponse> Send(TimeSpan? timeout, CancellationTok
return await activator.SendActivateRequest(Request, timeout?.FromUtcNow(), cancellationToken);
}

public Task<IActivateJobsResponse> SendWithRetry(TimeSpan? timespan = null)
public async Task<IActivateJobsResponse> SendWithRetry(TimeSpan? timespan)
{
throw new NotImplementedException();
return await asyncRetryStrategy.DoWithRetry(() => Send(timespan));
}

public async Task<IActivateJobsResponse> SendWithRetry(TimeSpan? timespan, CancellationToken? cancellationToken)
{
return await asyncRetryStrategy.DoWithRetry(() => Send(timespan, cancellationToken));
}
}
}
2 changes: 1 addition & 1 deletion Client/Impl/Worker/JobWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private async Task PollJobs(ITargetBlock<IJob> input, CancellationToken cancella

try
{
var response = await activateJobsCommand.Send(null, cancellationToken);
var response = await activateJobsCommand.SendWithRetry(null, cancellationToken);
await HandleActivationResponse(input, response, jobCount);
}
catch (RpcException rpcException)
Expand Down
2 changes: 1 addition & 1 deletion Client/ZeebeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public IJobWorkerBuilderStep1 NewWorker()

public IActivateJobsCommandStep1 NewActivateJobsCommand()
{
return new ActivateJobsCommand(gatewayClient);
return new ActivateJobsCommand(gatewayClient, asyncRetryStrategy);
}

public ICompleteJobCommandStep1 NewCompleteJobCommand(long jobKey)
Expand Down