From cc252135ab1473d773a58499ad9b32dba734bee9 Mon Sep 17 00:00:00 2001 From: Gerard Ryan Date: Tue, 18 Apr 2023 01:07:26 +0100 Subject: [PATCH] Handle poll interval and API token better - Token expires every hour, so a new token needs to be fetched every time, rather than just being able to get one at object initialization. - The "stalledDiscussionPollTimeMins" property set in the bf2-arch-bot.yml seemingly can't be used in the @Scheduled annotation, since it's not available early enough. --- .env | 1 + .../org/bf2/arch/bot/StalledDiscussionFlow.java | 13 ++++++++----- src/main/resources/application.properties | 5 ++++- src/test/resources/application.properties | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 9e739c8..ebc49e0 100644 --- a/.env +++ b/.env @@ -20,6 +20,7 @@ bot.enable.pr-review=false bot.enable.state-machine=false bot.enable.create-draft=true +BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION=86400s ## Stuff required by the github app framework diff --git a/src/main/java/org/bf2/arch/bot/StalledDiscussionFlow.java b/src/main/java/org/bf2/arch/bot/StalledDiscussionFlow.java index 9068989..2a47941 100644 --- a/src/main/java/org/bf2/arch/bot/StalledDiscussionFlow.java +++ b/src/main/java/org/bf2/arch/bot/StalledDiscussionFlow.java @@ -60,7 +60,10 @@ public class StalledDiscussionFlow { ArchBotConfig config; @Inject - void init(GitHubService service, GitHubConfigFileProvider configFileProvider) throws IOException { + GitHubService service; + + @Inject + void init(GitHubConfigFileProvider configFileProvider) throws IOException { if (!enabled) { LOG.debug("Ignoring init: disabled due to {}=false", ENABLE); } else if (installationId != null) { @@ -75,8 +78,6 @@ void init(GitHubService service, GitHubConfigFileProvider configFileProvider) th } } - - /** * When * every N hours @@ -97,7 +98,7 @@ void init(GitHubService service, GitHubConfigFileProvider configFileProvider) th * If the PR has been opened for > Y hours then "stalled-discussion" */ // TODO similar method as this, but for OVERDUE - @Scheduled(every="60s") + @Scheduled(every = "{BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION}") public void checkForStalledDiscussions() throws IOException { if (!enabled) { LOG.debug("Ignoring scheduled trigger: disabled due to {}=false", ENABLE); @@ -106,7 +107,9 @@ public void checkForStalledDiscussions() throws IOException { long now = System.currentTimeMillis(); long thresh = now - 24*40*60*1000L; LOG.info("Checking for stalled discussions"); - // TODO need a parameter for this installation id + + LOG.debug("Updating installation client to get new token (expires every 1h)"); + client = service.getInstallationClient(installationId); var results = client.searchIssues() .isOpen() diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d70cd82..9c5d6ae 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,4 @@ -quarkus.log.level=DEBUG \ No newline at end of file +quarkus.log.level=DEBUG +bot.enable.stalled-discussion=true +bot.enable.create-draft=true +BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION=86400s diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 960ad43..6f82249 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -27,4 +27,5 @@ FqD6xNtjmuaS5enErcCAMbZtzA7TNzvGaVO+xB/GfQ2QHS8/mrTesvQsTUZwC+ji\ E0/FAoGATJvuAfgy9uiKR7za7MigYVacE0u4aD1sF7v6D4AFqBOGquPQQhePSdz9\ G/UUwySoo+AQ+rd2EPhyexjqXBhRGe+EDGFVFivaQzTT8/5bt/VddbTcw2IpmXYj\ LW6V8BbcP5MRhd2JQSRh16nWwSQJ2BdpUZFwayEEQ6UcrMfqvA0=\ ------END RSA PRIVATE KEY----- \ No newline at end of file +-----END RSA PRIVATE KEY----- +BOT_STALLED_DISCUSSION_FLOW_POLL_DURATION=86400s