-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add retry mechanism and configurable interval for update checks #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,12 +22,15 @@ | |||||||||||
| @Singleton | ||||||||||||
| public final class UpdateService implements Runnable { | ||||||||||||
| private static final Logger LOGGER = LoggerFactory.getLogger(UpdateService.class); | ||||||||||||
| private static final long UPDATE_CHECK_INTERVAL_TICKS = Long.getLong("ARCR_UPDATE_SERVICE_SCHEDULE", 20 * 60 * 60 * 3L); // 3 hours | ||||||||||||
| private static final int MAX_RETRY_COUNT = Integer.getInteger("ARCR_UPDATE_SERVICE_MAX_RETRY", 5); | ||||||||||||
| private static final String DOWNLOAD_URL = "https://hangar.papermc.io/OneLiteFeather/AntiRedstoneClock-Remastered/versions/%s"; | ||||||||||||
| private final HttpClient hangarClient = HttpClient.newBuilder().build(); | ||||||||||||
| private final Version localVersion; | ||||||||||||
| private final SchedulerService schedulerService; | ||||||||||||
| private Version remoteVersion; | ||||||||||||
| private ScheduledTask scheduler; | ||||||||||||
| private int retryCount = 0; | ||||||||||||
|
|
||||||||||||
| @Inject | ||||||||||||
| public UpdateService(AntiRedstoneClockRemastered antiRedstoneClockRemastered, SchedulerService schedulerService) { | ||||||||||||
|
|
@@ -38,6 +41,12 @@ public UpdateService(AntiRedstoneClockRemastered antiRedstoneClockRemastered, Sc | |||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public void run() { | ||||||||||||
| if (retryCount >= MAX_RETRY_COUNT) { | ||||||||||||
| LOGGER.error("Max retry count reached for update check, stopping further attempts"); | ||||||||||||
| LOGGER.error("Please check your internet connection or https://hangar.papermc.io/ status."); | ||||||||||||
|
|
||||||||||||
|
||||||||||||
| if (this.scheduler != null) { | |
| this.scheduler.cancel(); | |
| } |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successful update checks (status code 200) that don't find a newer version don't reset the retry count. This means if the service experiences 4 failures followed by repeated successful checks that find no updates, it will stop working after one more failure. Consider resetting retryCount = 0 when a successful response is received (status code 200) to reset the failure counter.
| } | |
| } | |
| retryCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
retryCountfield is accessed from the asynchronous scheduled task without synchronization. Multiple scheduled tasks could potentially execute concurrently, leading to race conditions when reading and incrementingretryCount. Consider usingAtomicIntegerinstead ofintfor thread-safe operations.