Skip to content

Commit

Permalink
perf: job-gateway从ESB获取JWT公钥增加重试 TencentBlueKing#786
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed Nov 14, 2022
1 parent a35b8e7 commit bf5c2e7
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,27 @@ public EsbJwtServiceImpl(EsbJwtPublicKeyService esbJwtPublicKeyService) {

private void getPublicKeyOrRetryInBackground() {
boolean publicKeyGotten = tryToGetAndCachePublicKeyOnce();
if (!publicKeyGotten) {
Thread esbPublicKeyGetter = new Thread(() -> {
boolean keyGotten;
int retryCount = 0;
int sleepMillsOnce = 5000;
// 最多重试一整天
int maxRetryCount = 24 * 3600 / 5;
do {
log.warn("esbJwtPublicKey not gotten, retry {} after 5s", ++retryCount);
ThreadUtils.sleep(sleepMillsOnce);
keyGotten = tryToGetAndCachePublicKeyOnce();
} while (!keyGotten && retryCount <= maxRetryCount);
if (!keyGotten) {
log.error("esbJwtPublicKey not gotten after {} retry, plz check esb", maxRetryCount);
}
});
esbPublicKeyGetter.setDaemon(true);
esbPublicKeyGetter.setName("esbPublicKeyGetter");
esbPublicKeyGetter.start();
if (publicKeyGotten) {
return;
}
Thread esbPublicKeyGetter = new Thread(() -> {
boolean keyGotten;
int retryCount = 0;
int sleepMillsOnce = 5000;
// 最多重试3天
int maxRetryCount = 3 * 24 * 3600 / 5;
do {
log.warn("esbJwtPublicKey not gotten, retry {} after 5s", ++retryCount);
ThreadUtils.sleep(sleepMillsOnce);
keyGotten = tryToGetAndCachePublicKeyOnce();
} while (!keyGotten && retryCount <= maxRetryCount);
if (!keyGotten) {
log.error("esbJwtPublicKey not gotten after {} retry (3 days), plz check esb", maxRetryCount);
}
});
esbPublicKeyGetter.setDaemon(true);
esbPublicKeyGetter.setName("esbPublicKeyGetter");
esbPublicKeyGetter.start();
}

private boolean tryToGetAndCachePublicKeyOnce() {
Expand Down

0 comments on commit bf5c2e7

Please sign in to comment.