feat: Add post-update dependency installation, refactor restart logic, and update completion messages.

This commit is contained in:
syntaxbullet
2025-12-24 13:46:32 +01:00
parent 71de87d3da
commit 3f6da16f89

View File

@@ -11,6 +11,7 @@ export interface RestartContext {
userId: string; userId: string;
timestamp: number; timestamp: number;
runMigrations: boolean; runMigrations: boolean;
installDependencies: boolean;
} }
export class UpdateService { export class UpdateService {
@@ -50,9 +51,11 @@ export class UpdateService {
return stdout; return stdout;
} }
static async scheduleRestart(context: RestartContext): Promise<void> { static async prepareRestartContext(context: RestartContext): Promise<void> {
await writeFile(this.CONTEXT_FILE, JSON.stringify(context)); await writeFile(this.CONTEXT_FILE, JSON.stringify(context));
}
static async triggerRestart(): Promise<void> {
// Use custom restart command if available, otherwise fallback to touch // Use custom restart command if available, otherwise fallback to touch
if (process.env.RESTART_COMMAND) { if (process.env.RESTART_COMMAND) {
// We run this without awaiting because it might kill the process immediately // 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) { if (channel && channel.isSendable() && channel instanceof TextChannel) {
let migrationOutput = ""; let migrationOutput = "";
let migrationSuccess = true; 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) { if (context.runMigrations) {
try { try {
// Use drizzle-kit migrate // Use drizzle-kit migrate
@@ -98,8 +119,12 @@ export class UpdateService {
await channel.send({ await channel.send({
embeds: [ embeds: [
createSuccessEmbed( createSuccessEmbed(
`System updated successfully.${context.runMigrations ? `\n\n**Migration Output:**\n\`\`\`\n${migrationOutput.substring(0, 1000)}\n\`\`\`` : ""}`, `System updated successfully.
migrationSuccess ? "Update Complete" : "Update Complete (Migration Failed)" ${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"
) )
] ]
}); });