fix: version 3.0.1 -- Actualizador espera a backend y frontend antes de recargar
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,11 @@ export const getUpdateStatus = asyncHandler(async (req, res) => {
|
||||
ok(res, await service.checkForUpdates());
|
||||
});
|
||||
|
||||
export const getApplyProgress = asyncHandler(async (req, res) => {
|
||||
res.set('Cache-Control', 'no-store');
|
||||
ok(res, service.getApplyProgress());
|
||||
});
|
||||
|
||||
export const applyUpdate = asyncHandler(async (req, res) => {
|
||||
ok(res, await service.applyUpdate(req.currentUser.id));
|
||||
});
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Router } from 'express';
|
||||
import { requireAuth, requireRole, CAN_MANAGE_SETTINGS } from '../../middleware/auth.js';
|
||||
import { getUpdateStatus, applyUpdate } from './controller.js';
|
||||
import { getUpdateStatus, getApplyProgress, applyUpdate } from './controller.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.use(requireAuth, requireRole(...CAN_MANAGE_SETTINGS));
|
||||
router.get('/status', getUpdateStatus);
|
||||
router.get('/progress', getApplyProgress);
|
||||
router.post('/apply', applyUpdate);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -10,6 +10,8 @@ import { logAudit } from '../../utils/audit.js';
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const VERSION_FILE = path.resolve(__dirname, '../../../../VERSION');
|
||||
const MIGRATIONS_DIR = path.resolve(__dirname, '../../../database/migrations');
|
||||
// Fijada al arrancar: leer VERSION en cada request adelanta falsamente el fin tras git reset.
|
||||
const runningVersion = fs.readFileSync(VERSION_FILE, 'utf8').trim();
|
||||
|
||||
function parseVersion(v) {
|
||||
const [major, minor, patch] = v.trim().split('.').map(Number);
|
||||
@@ -70,6 +72,21 @@ function isApplyAvailable() {
|
||||
return !!(env.update.appDir && env.update.backendService && env.update.frontendService);
|
||||
}
|
||||
|
||||
export function getApplyProgress() {
|
||||
let state = 'idle';
|
||||
let phase = 'idle';
|
||||
let targetVersion = null;
|
||||
if (isApplyAvailable()) {
|
||||
try {
|
||||
const fields = fs.readFileSync(path.join(env.update.appDir, 'logs', 'update.status'), 'utf8').trim().split('|');
|
||||
if (fields.length === 3) [state, phase, targetVersion] = fields;
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') throw error;
|
||||
}
|
||||
}
|
||||
return { runningVersion, state, phase, targetVersion };
|
||||
}
|
||||
|
||||
export async function checkForUpdates() {
|
||||
const currentVersion = getLocalVersion();
|
||||
const changelogText = await repo.fetchChangelog();
|
||||
@@ -128,8 +145,10 @@ export async function applyUpdate(actorId) {
|
||||
throw new HttpError(409, 'Ya hay una actualizacion en curso');
|
||||
}
|
||||
|
||||
applyInProgress = true;
|
||||
const scriptPath = path.join(env.update.appDir, 'scripts', 'apply-update.sh');
|
||||
// La copia externa debe corresponder al código actual antes de hacer git reset en source/.
|
||||
fs.copyFileSync(path.resolve(__dirname, '../../../../scripts/apply-update.sh'), scriptPath);
|
||||
applyInProgress = true;
|
||||
const child = spawn('bash', [scriptPath], {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
@@ -138,6 +157,7 @@ export async function applyUpdate(actorId) {
|
||||
APP_DIR: env.update.appDir,
|
||||
BACKEND_SERVICE: env.update.backendService,
|
||||
FRONTEND_SERVICE: env.update.frontendService,
|
||||
TARGET_VERSION: status.latestVersion,
|
||||
},
|
||||
});
|
||||
child.unref();
|
||||
|
||||
Reference in New Issue
Block a user