From 78bf4f93011b969fdb66825379d11bd013986055 Mon Sep 17 00:00:00 2001 From: Thijs Alders Date: Tue, 16 Apr 2024 23:45:46 +0200 Subject: [PATCH] Ensure donations jobs will always run on the same single threaded scheduler. Bump version to 2.9.2. --- .../net/craftingstore/core/CraftingStore.java | 4 ++++ .../core/runner/DonationRunner.java | 4 ++++ .../core/scheduler/DonationChecker.java | 16 +++++++++++++--- pom.xml | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/net/craftingstore/core/CraftingStore.java b/core/src/main/java/net/craftingstore/core/CraftingStore.java index 3541b9f..f257109 100644 --- a/core/src/main/java/net/craftingstore/core/CraftingStore.java +++ b/core/src/main/java/net/craftingstore/core/CraftingStore.java @@ -141,4 +141,8 @@ public class CraftingStore { public Map getPendingDonations() { return pendingDonations; } + + public DonationRunner getDonationRunner() { + return donationRunner; + } } diff --git a/core/src/main/java/net/craftingstore/core/runner/DonationRunner.java b/core/src/main/java/net/craftingstore/core/runner/DonationRunner.java index ef3028d..f2dcd60 100644 --- a/core/src/main/java/net/craftingstore/core/runner/DonationRunner.java +++ b/core/src/main/java/net/craftingstore/core/runner/DonationRunner.java @@ -43,4 +43,8 @@ public class DonationRunner { } }); } + + public ExecutorService getExecutor() { + return executor; + } } diff --git a/core/src/main/java/net/craftingstore/core/scheduler/DonationChecker.java b/core/src/main/java/net/craftingstore/core/scheduler/DonationChecker.java index a96f52a..0bdf569 100644 --- a/core/src/main/java/net/craftingstore/core/scheduler/DonationChecker.java +++ b/core/src/main/java/net/craftingstore/core/scheduler/DonationChecker.java @@ -23,8 +23,8 @@ public class DonationChecker implements Runnable { return; } if (instance.getProviderSelector().isConnected()) { - // Only run this runnable every 25 minutes when we are connected to a websocket. - long target = System.currentTimeMillis() - (25 * 60 * 1000); + // Only run this runnable every 30 minutes when we are connected to a websocket. + long target = System.currentTimeMillis() - (30 * 60 * 1000); if (lastRun > target) { return; } @@ -37,7 +37,17 @@ public class DonationChecker implements Runnable { for (int i = 0; i < chunked.length; i++) { Donation[] chunk = chunked[i]; this.instance.getLogger().debug(String.format("Creating ExecuteDonationsJob for chunk %d/%d", i + 1, chunked.length)); - new ExecuteDonationsJob(instance, chunk); + this.instance.getDonationRunner().getExecutor().submit(() -> { + try { + new ExecuteDonationsJob(instance, chunk); + } catch (CraftingStoreApiException e) { + if (instance.getLogger().isDebugging()) { + e.printStackTrace(); + } else { + instance.getLogger().error("Failed to execute donation. If this issue persists, please contact support at https://craftingstore.net."); + } + } + }); } } catch (CraftingStoreApiException | InterruptedException | ExecutionException e) { if (instance.getLogger().isDebugging()) { diff --git a/pom.xml b/pom.xml index f1056ea..b293eae 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ ${craftingstore-version}-RELEASE - 2.9.1 + 2.9.2