Skip to content

Commit

Permalink
add exception catch
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-alhuang committed May 2, 2024
1 parent b1318be commit 5ce2f5c
Showing 1 changed file with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,36 @@ private void createWorkers() {
this.flushWorker = Executors.newSingleThreadScheduledExecutor(flushThreadFactory);
this.flushWorker.scheduleWithFixedDelay(
() -> {
flush(false)
.exceptionally(
e -> {
String errorMessage =
String.format(
"Background flush task failed, client=%s, exception=%s, detail=%s,"
+ " trace=%s.",
this.owningClient.getName(),
e.getCause(),
e.getCause().getMessage(),
getStackTrace(e.getCause()));
logger.logError(errorMessage);
if (this.owningClient.getTelemetryService() != null) {
this.owningClient
.getTelemetryService()
.reportClientFailure(this.getClass().getSimpleName(), errorMessage);
}
return null;
});
try {
flush(false)
.exceptionally(
e -> {
String errorMessage =
String.format(
"Background flush task failed, client=%s, exception=%s, detail=%s,"
+ " trace=%s.",
this.owningClient.getName(),
e.getCause(),
e.getCause().getMessage(),
getStackTrace(e.getCause()));
logger.logError(errorMessage);
if (this.owningClient.getTelemetryService() != null) {
this.owningClient
.getTelemetryService()
.reportClientFailure(this.getClass().getSimpleName(), errorMessage);
}
return null;
});
} catch (Exception e) {
String errorMessage =
String.format(
"Failed to schedule a flush task, client=%s, exception=%s, detail=%s, trace=%s.",
this.owningClient.getName(),
e.getClass().getName(),
e.getMessage(),
getStackTrace(e));
logger.logError(errorMessage);
}
},
0,
this.owningClient.getParameterProvider().getBufferFlushCheckIntervalInMs(),
Expand Down

0 comments on commit 5ce2f5c

Please sign in to comment.