forked from syntaxbullet/AuroraBot-discord
feat: Add post-update dependency installation, refactor restart logic, and update completion messages.
This commit is contained in:
@@ -11,6 +11,7 @@ export interface RestartContext {
|
||||
userId: string;
|
||||
timestamp: number;
|
||||
runMigrations: boolean;
|
||||
installDependencies: boolean;
|
||||
}
|
||||
|
||||
export class UpdateService {
|
||||
@@ -50,9 +51,11 @@ export class UpdateService {
|
||||
return stdout;
|
||||
}
|
||||
|
||||
static async scheduleRestart(context: RestartContext): Promise<void> {
|
||||
static async prepareRestartContext(context: RestartContext): Promise<void> {
|
||||
await writeFile(this.CONTEXT_FILE, JSON.stringify(context));
|
||||
}
|
||||
|
||||
static async triggerRestart(): Promise<void> {
|
||||
// Use custom restart command if available, otherwise fallback to touch
|
||||
if (process.env.RESTART_COMMAND) {
|
||||
// We run this without awaiting because it might kill the process immediately
|
||||
@@ -81,7 +84,25 @@ export class UpdateService {
|
||||
if (channel && channel.isSendable() && channel instanceof TextChannel) {
|
||||
let migrationOutput = "";
|
||||
let migrationSuccess = true;
|
||||
let installOutput = "";
|
||||
let installSuccess = true;
|
||||
|
||||
// 1. Install Dependencies if needed (Post-Restart)
|
||||
if (context.installDependencies) {
|
||||
try {
|
||||
await channel.send({
|
||||
embeds: [createSuccessEmbed("Installing dependencies...", "Post-Update Action")]
|
||||
});
|
||||
const { stdout } = await execAsync("bun install");
|
||||
installOutput = stdout;
|
||||
} catch (err: any) {
|
||||
installSuccess = false;
|
||||
installOutput = err.message;
|
||||
console.error("Dependency Install Failed:", err);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Run Migrations
|
||||
if (context.runMigrations) {
|
||||
try {
|
||||
// Use drizzle-kit migrate
|
||||
@@ -98,8 +119,12 @@ export class UpdateService {
|
||||
await channel.send({
|
||||
embeds: [
|
||||
createSuccessEmbed(
|
||||
`System updated successfully.${context.runMigrations ? `\n\n**Migration Output:**\n\`\`\`\n${migrationOutput.substring(0, 1000)}\n\`\`\`` : ""}`,
|
||||
migrationSuccess ? "Update Complete" : "Update Complete (Migration Failed)"
|
||||
`System updated successfully.
|
||||
${context.installDependencies ? `**Dependencies:** ${installSuccess ? "✅ Installed" : "❌ Failed"}\n` : ""}
|
||||
${context.runMigrations ? `**Migrations:** ${migrationSuccess ? "✅ Applied" : "❌ Failed"}\n` : ""}
|
||||
${installOutput ? `\n**Install Output:**\n\`\`\`\n${installOutput.substring(0, 500)}\n\`\`\`` : ""}
|
||||
${migrationOutput ? `\n**Migration Output:**\n\`\`\`\n${migrationOutput.substring(0, 500)}\n\`\`\`` : ""}`,
|
||||
(migrationSuccess && installSuccess) ? "Update Complete" : "Update Completed with Errors"
|
||||
)
|
||||
]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user