Skip to content

Commit 9d546d3

Browse files
authored
Add a maximum page size and use the count instead of the list (#10443)
* Add a maximum page size and use the count instead of the list * Fix typo
1 parent 33cd51f commit 9d546d3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

airbyte-workers/src/main/java/io/airbyte/workers/temporal/TemporalClient.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import io.airbyte.workers.temporal.scheduling.state.WorkflowState;
3232
import io.airbyte.workers.temporal.spec.SpecWorkflow;
3333
import io.airbyte.workers.temporal.sync.SyncWorkflow;
34-
import io.temporal.api.workflow.v1.WorkflowExecutionInfo;
3534
import io.temporal.api.workflowservice.v1.ListOpenWorkflowExecutionsRequest;
3635
import io.temporal.api.workflowservice.v1.ListOpenWorkflowExecutionsResponse;
3736
import io.temporal.client.BatchRequest;
@@ -40,7 +39,6 @@
4039
import java.io.IOException;
4140
import java.nio.file.Path;
4241
import java.util.HashSet;
43-
import java.util.List;
4442
import java.util.Optional;
4543
import java.util.Set;
4644
import java.util.UUID;
@@ -65,6 +63,8 @@ public class TemporalClient {
6563
*/
6664
private static final int DELAY_BETWEEN_QUERY_MS = 10;
6765

66+
private static final int MAXIMUM_SEARCH_PAGE_SIZE = 50;
67+
6868
public static TemporalClient production(final String temporalHost, final Path workspaceRoot, final Configs configs) {
6969
final WorkflowServiceStubs temporalService = TemporalUtils.createTemporalService(temporalHost);
7070
return new TemporalClient(WorkflowClient.newInstance(temporalService), workspaceRoot, temporalService, configs);
@@ -454,14 +454,15 @@ public boolean isWorkflowRunning(final String workflowName) {
454454
ListOpenWorkflowExecutionsRequest openWorkflowExecutionsRequest =
455455
ListOpenWorkflowExecutionsRequest.newBuilder()
456456
.setNamespace(client.getOptions().getNamespace())
457+
.setMaximumPageSize(MAXIMUM_SEARCH_PAGE_SIZE)
457458
.build();
458459
do {
459460
final ListOpenWorkflowExecutionsResponse listOpenWorkflowExecutionsRequest =
460461
service.blockingStub().listOpenWorkflowExecutions(openWorkflowExecutionsRequest);
461-
final List<WorkflowExecutionInfo> workflowExecutionInfos = listOpenWorkflowExecutionsRequest.getExecutionsList().stream()
462+
final long matchingWorkflowCount = listOpenWorkflowExecutionsRequest.getExecutionsList().stream()
462463
.filter((workflowExecutionInfo -> workflowExecutionInfo.getExecution().getWorkflowId().equals(workflowName)))
463-
.collect(Collectors.toList());
464-
if (!workflowExecutionInfos.isEmpty()) {
464+
.count();
465+
if (matchingWorkflowCount != 0) {
465466
return true;
466467
}
467468
token = listOpenWorkflowExecutionsRequest.getNextPageToken();
@@ -470,6 +471,7 @@ public boolean isWorkflowRunning(final String workflowName) {
470471
ListOpenWorkflowExecutionsRequest.newBuilder()
471472
.setNamespace(client.getOptions().getNamespace())
472473
.setNextPageToken(token)
474+
.setMaximumPageSize(MAXIMUM_SEARCH_PAGE_SIZE)
473475
.build();
474476

475477
} while (token != null && token.size() > 0);

0 commit comments

Comments
 (0)