feat: 新增延迟
This commit is contained in:
parent
d5c2b069bb
commit
131b0da71d
@ -42,6 +42,8 @@ public class RtkClusterService implements ApplicationRunner {
|
||||
|
||||
@Value("${rtkrcv.workdir:/opt/rtk}")
|
||||
private String rtkWorkDir;
|
||||
@Value("${rtk.start.delaySeconds:30}")
|
||||
private int startDelaySec;
|
||||
@Value("${rtkrcv.bin:rtkrcv}")
|
||||
private String rtkBinary;
|
||||
|
||||
@ -66,6 +68,14 @@ public class RtkClusterService implements ApplicationRunner {
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (startDelaySec > 0) {
|
||||
try {
|
||||
LOGGER.info("RtkClusterService delayed start {}s to wait for 9902/9903", startDelaySec);
|
||||
Thread.sleep(startDelaySec * 1000L);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
// Load all profiles and bootstrap endpoints and sessions.
|
||||
List<RtkrcvProfile> profiles = profileMapper.selectList(null);
|
||||
if (profiles == null || profiles.isEmpty()) {
|
||||
|
||||
@ -34,6 +34,10 @@ public class RtkrcvConfigService {
|
||||
|
||||
@Value("${rtkrcv.workdir:/opt/rtk}")
|
||||
private String defaultWorkDir;
|
||||
@Value("${rtk.start.delaySeconds:30}")
|
||||
private int startDelaySec;
|
||||
private final long beanInitAt = System.currentTimeMillis();
|
||||
private volatile boolean delayDone = false;
|
||||
|
||||
@Autowired(required = false)
|
||||
private RtkrcvGroupMapper groupMapper;
|
||||
@ -56,6 +60,7 @@ public class RtkrcvConfigService {
|
||||
* The output filename will be `rtkrcv_{deviceId}.conf` under the provided outputDir.
|
||||
*/
|
||||
public Path generateConfig(RtkrcvProfile profile, Path outputDir) throws IOException {
|
||||
ensureStartupDelay();
|
||||
if (profile == null) throw new IllegalArgumentException("profile must not be null");
|
||||
if (profile.getDeviceId() == null || profile.getDeviceId().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("profile.deviceId must not be empty");
|
||||
@ -112,6 +117,25 @@ public class RtkrcvConfigService {
|
||||
return out;
|
||||
}
|
||||
|
||||
private void ensureStartupDelay() {
|
||||
if (delayDone) return;
|
||||
synchronized (this) {
|
||||
if (delayDone) return;
|
||||
long target = beanInitAt + (startDelaySec * 1000L);
|
||||
long now = System.currentTimeMillis();
|
||||
long wait = target - now;
|
||||
if (wait > 0) {
|
||||
try {
|
||||
LOGGER.info("RtkrcvConfigService delaying {} ms to wait for 9902/9903", wait);
|
||||
Thread.sleep(wait);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
delayDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> loadGroupConfig(RtkrcvProfile profile) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user