Made "Save to stage" unblocking

This commit is contained in:
Dmitri 2026-04-14 18:23:04 +04:00
parent ccb0122152
commit 1e2b72d2bd
2 changed files with 39 additions and 60 deletions

View File

@ -151,8 +151,8 @@ module.exports = class PublishService {
} }
/** /**
* Save dev content to stage environment * Save dev content to stage environment (non-blocking)
* This is the first step in the publishing workflow: dev -> stage -> production * Returns immediately, processing continues in background.
*/ */
static async saveToStage(projectId, currentUser) { static async saveToStage(projectId, currentUser) {
if (!projectId) { if (!projectId) {
@ -173,6 +173,8 @@ module.exports = class PublishService {
updatedById: currentUser?.id || null, updatedById: currentUser?.id || null,
}); });
// Process in background
setImmediate(async () => {
try { try {
const summary = await this.withProjectPublishLock( const summary = await this.withProjectPublishLock(
projectId, projectId,
@ -181,12 +183,10 @@ module.exports = class PublishService {
{ {
started_at: new Date(), started_at: new Date(),
status: EVENT_STATUS.RUNNING, status: EVENT_STATUS.RUNNING,
error_message: null,
updatedById: currentUser?.id || null, updatedById: currentUser?.id || null,
}, },
{ transaction }, { transaction },
); );
return this.copyDevToStage(projectId, currentUser, transaction); return this.copyDevToStage(projectId, currentUser, transaction);
}, },
); );
@ -196,15 +196,8 @@ module.exports = class PublishService {
finished_at: new Date(), finished_at: new Date(),
pages_copied: summary.pages_copied, pages_copied: summary.pages_copied,
audios_copied: summary.audios_copied, audios_copied: summary.audios_copied,
error_message: null,
updatedById: currentUser?.id || null, updatedById: currentUser?.id || null,
}); });
return {
success: true,
publishEventId: publishEvent.id,
summary,
};
} catch (error) { } catch (error) {
await publishEvent.update({ await publishEvent.update({
status: EVENT_STATUS.FAILED, status: EVENT_STATUS.FAILED,
@ -212,8 +205,11 @@ module.exports = class PublishService {
error_message: error.message, error_message: error.message,
updatedById: currentUser?.id || null, updatedById: currentUser?.id || null,
}); });
throw error; console.error('[SaveToStage] Background error:', error);
} }
});
return { success: true, publishEventId: publishEvent.id };
} }
/** /**

View File

@ -232,29 +232,12 @@ export function useConstructorPageActions({
return; return;
} }
// First save current changes
await saveConstructor(); await saveConstructor();
try { try {
setIsSavingToStage(true); setIsSavingToStage(true);
await axios.post('/publish/save-to-stage', { projectId });
const response = await axios.post<{ onSuccess?.('Saved to stage.');
success: boolean;
summary?: { pages_copied: number; audios_copied: number };
}>('/publish/save-to-stage', { projectId });
const pagesCopied = response.data?.summary?.pages_copied ?? 0;
const audiosCopied = response.data?.summary?.audios_copied ?? 0;
if (pagesCopied === 0) {
onError?.(
'No pages were found to copy. Make sure you have dev pages saved before publishing to stage.',
);
} else {
onSuccess?.(
`Successfully saved to stage: ${pagesCopied} page${pagesCopied !== 1 ? 's' : ''} and ${audiosCopied} audio track${audiosCopied !== 1 ? 's' : ''} copied.`,
);
}
} catch (error: unknown) { } catch (error: unknown) {
const axiosError = error as { const axiosError = error as {
response?: { data?: { message?: string } }; response?: { data?: { message?: string } };