refactor(auth): Use the @SneakyThrows annotation to handle interrupt exceptions

This commit is contained in:
Sol 2025-06-05 10:08:05 +08:00
parent 0fc6e1b160
commit cda688618f

View file

@ -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");
}
}
}