Improved logging in ManagedPeriodcWork
This commit is contained in:
parent
fc7291c3e8
commit
19617c14f8
|
@ -14,7 +14,7 @@ import org.whispersystems.textsecuregcm.util.Util;
|
||||||
|
|
||||||
public abstract class ManagedPeriodicWork implements Managed, Runnable {
|
public abstract class ManagedPeriodicWork implements Managed, Runnable {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ManagedPeriodicWork.class);
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
private final ManagedPeriodicWorkCache cache;
|
private final ManagedPeriodicWorkCache cache;
|
||||||
private final Duration workerTtl;
|
private final Duration workerTtl;
|
||||||
|
@ -58,7 +58,7 @@ public abstract class ManagedPeriodicWork implements Managed, Runnable {
|
||||||
execute();
|
execute();
|
||||||
sleepWhileRunning(runInterval);
|
sleepWhileRunning(runInterval);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
logger.warn("Error in crawl crawl", e);
|
logger.warn("Error in execution", e);
|
||||||
|
|
||||||
// wait a bit, in case the error is caused by external instability
|
// wait a bit, in case the error is caused by external instability
|
||||||
Util.sleep(10_000);
|
Util.sleep(10_000);
|
||||||
|
@ -78,16 +78,19 @@ public abstract class ManagedPeriodicWork implements Managed, Runnable {
|
||||||
try {
|
try {
|
||||||
final long startTimeMs = System.currentTimeMillis();
|
final long startTimeMs = System.currentTimeMillis();
|
||||||
|
|
||||||
|
logger.info("Starting execution");
|
||||||
doPeriodicWork();
|
doPeriodicWork();
|
||||||
|
logger.info("Execution complete");
|
||||||
|
|
||||||
final long endTimeMs = System.currentTimeMillis();
|
final long endTimeMs = System.currentTimeMillis();
|
||||||
final Duration sleepInterval = runInterval.minusMillis(endTimeMs - startTimeMs);
|
final Duration sleepInterval = runInterval.minusMillis(endTimeMs - startTimeMs);
|
||||||
if (sleepInterval.getSeconds() > 0) {
|
if (sleepInterval.getSeconds() > 0) {
|
||||||
|
logger.info("Sleeping for {}", sleepInterval);
|
||||||
sleepWhileRunning(sleepInterval);
|
sleepWhileRunning(sleepInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
logger.warn("Failed to process chunk", e);
|
logger.warn("Periodic work failed", e);
|
||||||
|
|
||||||
// wait a full interval for recovery
|
// wait a full interval for recovery
|
||||||
sleepWhileRunning(runInterval);
|
sleepWhileRunning(runInterval);
|
||||||
|
|
Loading…
Reference in New Issue