Skip to content

Commit e5111c5

Browse files
committed
Optimize publish log retry logic
1 parent 0be6360 commit e5111c5

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ public final class ChronosLogHandler {
839839

840840
final AtomicInteger sequenceNumber = new AtomicInteger();
841841

842-
final static int MAX_RETRIES = 1;
842+
final static int MAX_RETRIES = 2;
843843

844844

845845
public ChronosLogHandler( final ChronosJob job ) {
@@ -859,6 +859,14 @@ public void publish( String message ) {
859859
pendingMessages.add( executor.submit( () -> {
860860
int attempt = 0;
861861
while ( attempt < MAX_RETRIES ) {
862+
if ( attempt > 0 ) {
863+
try {
864+
TimeUnit.MILLISECONDS.sleep( 500 );
865+
} catch ( InterruptedException e ) {
866+
Thread.currentThread().interrupt();
867+
return;
868+
}
869+
}
862870
try {
863871
parameters.clear();
864872
parameters.put( "recordSequenceNumber", sequenceNumber.incrementAndGet() );
@@ -879,12 +887,6 @@ public void publish( String message ) {
879887
log.debug( "Exception while publishing log records. Attempt {}: {}", attempt + 1, MAX_RETRIES + 1, ex );
880888
}
881889
attempt++;
882-
try {
883-
TimeUnit.MILLISECONDS.sleep( 500 );
884-
} catch ( InterruptedException e ) {
885-
Thread.currentThread().interrupt();
886-
return;
887-
}
888890
}
889891
log.warn( "Failed to publish log after {} attempts", MAX_RETRIES + 1 );
890892
} ) );

0 commit comments

Comments
 (0)