refactor: Reorganize admin update flow to prepare restart context before update and explicitly trigger restart.
This commit is contained in:
@@ -64,47 +64,37 @@ export const update = createCommand({
|
||||
|
||||
if (confirmation.customId === "confirm_update") {
|
||||
await confirmation.update({
|
||||
embeds: [createInfoEmbed("⏳ Pulling latest changes...", "Update In Progress")],
|
||||
embeds: [createInfoEmbed("⏳ Preparing update...", "Update In Progress")],
|
||||
components: []
|
||||
});
|
||||
|
||||
// 1. Check dependencies before pulling to know if we need to install
|
||||
// Actually, we need to pull first to get the new package.json, then check diff?
|
||||
// UpdateService.checkDependencies uses git diff HEAD..origin/branch.
|
||||
// This works BEFORE we pull/reset.
|
||||
// 1. Check dependencies
|
||||
const needsDependencyInstall = await UpdateService.checkDependencies(branch);
|
||||
|
||||
// 2. Perform Update
|
||||
await UpdateService.performUpdate(branch);
|
||||
|
||||
let installLog = "";
|
||||
if (needsDependencyInstall) {
|
||||
await interaction.editReply({
|
||||
embeds: [createInfoEmbed("⏳ Installing dependencies...", "Update In Progress")]
|
||||
});
|
||||
try {
|
||||
installLog = await UpdateService.installDependencies();
|
||||
} catch (e: any) {
|
||||
if (!force) throw new Error(`Dependency installation failed: ${e.message}`);
|
||||
installLog = `Failed: ${e.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Schedule Restart
|
||||
await interaction.editReply({
|
||||
embeds: [createWarningEmbed(
|
||||
`Update applied successfully.\n${needsDependencyInstall ? `Dependencies installed.\n` : ""}Restarting system...`,
|
||||
"Restarting"
|
||||
)]
|
||||
});
|
||||
|
||||
await UpdateService.scheduleRestart({
|
||||
// 2. Prepare context BEFORE update, as update might kill the process (git reset on watched files)
|
||||
await UpdateService.prepareRestartContext({
|
||||
channelId: interaction.channelId,
|
||||
userId: interaction.user.id,
|
||||
timestamp: Date.now(),
|
||||
runMigrations: true
|
||||
runMigrations: true,
|
||||
installDependencies: needsDependencyInstall
|
||||
});
|
||||
|
||||
// 3. Update UI to "Restarting" state now, because we might not get a chance later
|
||||
await interaction.editReply({
|
||||
embeds: [createWarningEmbed(
|
||||
`Downloading and applying updates...\n${needsDependencyInstall ? `Expect a slightly longer startup for dependency installation.\n` : ""}The system will restart automatically.`,
|
||||
"Updating & Restarting"
|
||||
)]
|
||||
});
|
||||
|
||||
// 4. Perform Update (Danger Zone)
|
||||
await UpdateService.performUpdate(branch);
|
||||
|
||||
// 5. Trigger Restart (if we are still alive)
|
||||
// If git reset didn't kill us (e.g. no watched files changed), we assume we need to restart manually.
|
||||
await UpdateService.triggerRestart();
|
||||
|
||||
} else {
|
||||
await confirmation.update({
|
||||
embeds: [createInfoEmbed("Update cancelled.", "Cancelled")],
|
||||
|
||||
Reference in New Issue
Block a user