mirror of
https://github.com/BgaSol/sol-cloud
synced 2026-05-24 09:38:21 +00:00
refactor(auth): Use the @SneakyThrows annotation to handle interrupt exceptions
This commit is contained in:
parent
0fc6e1b160
commit
cda688618f
1 changed files with 7 additions and 11 deletions
|
|
@ -2,6 +2,7 @@ package com.bgasol.plugin.satoken.runner;
|
|||
|
||||
import cn.dev33.satoken.same.SaSameUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
|
|
@ -24,20 +25,15 @@ public class SaSameTokenRefreshTask {
|
|||
|
||||
private static final String LOCK_KEY = "same-token:refresh:lock";
|
||||
|
||||
@SneakyThrows
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void refreshToken() {
|
||||
RLock lock = redissonClient.getLock(LOCK_KEY);
|
||||
try {
|
||||
if (lock.tryLock(0, 5, TimeUnit.SECONDS)) {
|
||||
SaSameUtil.refreshToken();
|
||||
log.info("Token refresh token successful");
|
||||
} else {
|
||||
log.info("Lock not acquired");
|
||||
}
|
||||
// 不需要手动解锁 锁10秒后会自动释放
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("interrupt", e);
|
||||
if (lock.tryLock(0, 5, TimeUnit.SECONDS)) {
|
||||
SaSameUtil.refreshToken();
|
||||
log.info("Token refresh token successful");
|
||||
} else {
|
||||
log.info("Lock not acquired");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue