Skip to content

Commit

Permalink
Add an optional limit to init-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Oct 18, 2024
1 parent d05a0dd commit 4e61f6b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public void createNextPlaceholderBatch(Long upToKeyNumber) {
JiraIssueBulkResponse response = destinationJiraClient.create(bulk);
response.issues.stream().mapToLong(i -> JiraIssue.keyToLong(i.key)).max()
.ifPresent(currentIssueKeyNumber::set);
Log.infof(
"Created more sync placeholders for %s; Current latest Jira key number is %s while required key is %s",
projectName, currentIssueKeyNumber.get(), upToKeyNumber);
} while (currentIssueKeyNumber.get() < upToKeyNumber);
} finally {
lock.unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BooleanSupplier;

import org.hibernate.infra.replicate.jira.JiraConfig;
import org.hibernate.infra.replicate.jira.service.jira.client.JiraRestClient;
Expand Down Expand Up @@ -109,6 +111,10 @@ public void registerManagementRoutes(@Observes ManagementInterface mi) {
// TODO: we can remove this one once we figure out why POST management does not
// work correctly...
String project = rc.pathParam("project");
List<String> maxToSyncList = rc.queryParam("maxToSync");
AtomicInteger maxToSync = maxToSyncList.isEmpty()
? null
: new AtomicInteger(Integer.parseInt(maxToSyncList.get(0)) + 1);

HandlerProjectContext context = contextPerProject.get(project);

Expand All @@ -117,14 +123,14 @@ public void registerManagementRoutes(@Observes ManagementInterface mi) {
}

AtomicLong largestSyncedJiraIssueKeyNumber = new AtomicLong(context.getLargestSyncedJiraIssueKeyNumber());

BooleanSupplier continueSyncing = maxToSync == null ? () -> true : () -> maxToSync.decrementAndGet() > 0;
String identity = "Init Sync for project %s".formatted(project);
scheduler.newJob(identity).setConcurrentExecution(Scheduled.ConcurrentExecution.SKIP)
// every 10 seconds:
.setCron("0/10 * * * * ?").setTask(executionContext -> {
Optional<JiraIssue> issueToSync = context
.getNextIssueToSync(largestSyncedJiraIssueKeyNumber.get());
if (issueToSync.isEmpty()) {
if (issueToSync.isEmpty() || !continueSyncing.getAsBoolean()) {
scheduler.unscheduleJob(identity);
} else {
triggerSyncEvent(issueToSync.get(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.infra.replicate.jira.service.reporting.FailureCollector;
import org.hibernate.infra.replicate.jira.service.reporting.ReportingConfig;

import io.quarkus.logging.Log;
import jakarta.ws.rs.core.UriBuilder;

public abstract class JiraEventHandler implements Runnable {
Expand Down Expand Up @@ -158,6 +159,8 @@ public final void run() {
Thread.currentThread().interrupt();
} finally {
failureCollector.close();
Log.infof("Pending events in %s to process: %s", context.projectGroupName(),
context.pendingEventsInCurrentContext());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void warning(String details) {

@Override
public void warning(String details, Exception exception) {
Log.warn(details, exception);
Log.warnf(exception, details);
}

@Override
Expand All @@ -26,7 +26,7 @@ public void critical(String details) {

@Override
public void critical(String details, Exception exception) {
Log.error(details, exception);
Log.errorf(exception, details);
}

@Override
Expand Down

0 comments on commit 4e61f6b

Please sign in to comment.