-
Notifications
You must be signed in to change notification settings - Fork 24
Improved Redeploy System #330
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc99346
Imrpoved Redeploy System
MoonTM-GIT dabdb31
Merge branch 'main' into moon/redeploy
MoonTM-GIT 48e8481
Update RedeployCommand
MoonTM-GIT 62364c9
Fix checkstyle
MoonTM-GIT 8d1e376
Added JDA#shutdown
MoonTM-GIT 6507aa8
Updated javadoc
MoonTM-GIT 2d0b215
Fix checkstyle
MoonTM-GIT 49eda39
Added link to #330 to SystemsConfig
MoonTM-GIT 431646f
Removed extra dot
MoonTM-GIT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,17 +7,20 @@ | |
| import net.dv8tion.jda.api.interactions.commands.build.Commands; | ||
| import net.javadiscord.javabot.Bot; | ||
| import net.javadiscord.javabot.util.Checks; | ||
| import net.javadiscord.javabot.util.ExceptionLogger; | ||
| import net.javadiscord.javabot.util.Responses; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * <h3>This class represents the /redeploy command.</h3> | ||
| * Command that lets staff-members redeploy the bot. | ||
| * <p> | ||
| * This only works if the way the bot is hosted is set up correctly, for example with a bash script that handles | ||
| * compilation and a service set up with that bash script running before the bot gets started. | ||
| * This only works if the way the bot is hosted is set up correctly with a bash script that handles | ||
| * compilation and a service set up that automatically restarts the Bot. | ||
| * <p> | ||
| * I have explained how we do it in https://github.com/Java-Discord/JavaBot/pull/195 | ||
| * I have explained how we do it in <a href="https://github.com/Java-Discord/JavaBot/pull/330">PR #330</a>. | ||
| */ | ||
| @Slf4j | ||
| public class RedeployCommand extends SlashCommand { | ||
|
|
@@ -39,8 +42,23 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { | |
| return; | ||
| } | ||
| log.warn("Redeploying... Requested by: " + event.getUser().getAsTag()); | ||
| event.reply("**Redeploying...** This may take some time.").queue(); | ||
| event.reply("Redeploying, this may take a few minutes.").queue(); | ||
| try { | ||
| Process p = new ProcessBuilder("/bin/sh", Bot.getConfig().getSystems().getRedeployScriptLocation()).start(); | ||
| p.waitFor(); | ||
| String result = new String(p.getInputStream().readAllBytes()); | ||
| if (result.contains("COMPILATION FAILED")) { | ||
| event.getHook().sendMessage("Compilation failed, redeploy canceled.").queue(); | ||
| log.warn("Redeploy canceled due to compilation error."); | ||
| return; | ||
| } else { | ||
| event.getHook().sendMessage("Compilation successful, restarting...").queue(); | ||
| } | ||
| } catch (InterruptedException | IOException e) { | ||
| ExceptionLogger.capture(e, getClass().getSimpleName()); | ||
| } | ||
| Bot.getMessageCache().synchronize(); | ||
| event.getJDA().shutdown(); | ||
| System.exit(0); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to move this to its own listener so that it is called when shutting down JDA completed. |
||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It might be better to use the exit code of the script for checking whether it was successful or not.
For example, there could be errors other than the Gradle script failing (e.g. with
git clone).For failing with any error,
set -ecould be used in the script in order to abort the script as soon as any command fails.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.
Yup, will do that soon™️