Made "Save to stage" unblocking
This commit is contained in:
parent
ccb0122152
commit
1e2b72d2bd
@ -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,47 +173,43 @@ module.exports = class PublishService {
|
|||||||
updatedById: currentUser?.id || null,
|
updatedById: currentUser?.id || null,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
// Process in background
|
||||||
const summary = await this.withProjectPublishLock(
|
setImmediate(async () => {
|
||||||
projectId,
|
try {
|
||||||
async (transaction) => {
|
const summary = await this.withProjectPublishLock(
|
||||||
await publishEvent.update(
|
projectId,
|
||||||
{
|
async (transaction) => {
|
||||||
started_at: new Date(),
|
await publishEvent.update(
|
||||||
status: EVENT_STATUS.RUNNING,
|
{
|
||||||
error_message: null,
|
started_at: new Date(),
|
||||||
updatedById: currentUser?.id || null,
|
status: EVENT_STATUS.RUNNING,
|
||||||
},
|
updatedById: currentUser?.id || null,
|
||||||
{ transaction },
|
},
|
||||||
);
|
{ transaction },
|
||||||
|
);
|
||||||
|
return this.copyDevToStage(projectId, currentUser, transaction);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return this.copyDevToStage(projectId, currentUser, transaction);
|
await publishEvent.update({
|
||||||
},
|
status: EVENT_STATUS.SUCCESS,
|
||||||
);
|
finished_at: new Date(),
|
||||||
|
pages_copied: summary.pages_copied,
|
||||||
|
audios_copied: summary.audios_copied,
|
||||||
|
updatedById: currentUser?.id || null,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
await publishEvent.update({
|
||||||
|
status: EVENT_STATUS.FAILED,
|
||||||
|
finished_at: new Date(),
|
||||||
|
error_message: error.message,
|
||||||
|
updatedById: currentUser?.id || null,
|
||||||
|
});
|
||||||
|
console.error('[SaveToStage] Background error:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await publishEvent.update({
|
return { success: true, publishEventId: publishEvent.id };
|
||||||
status: EVENT_STATUS.SUCCESS,
|
|
||||||
finished_at: new Date(),
|
|
||||||
pages_copied: summary.pages_copied,
|
|
||||||
audios_copied: summary.audios_copied,
|
|
||||||
error_message: null,
|
|
||||||
updatedById: currentUser?.id || null,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
publishEventId: publishEvent.id,
|
|
||||||
summary,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
await publishEvent.update({
|
|
||||||
status: EVENT_STATUS.FAILED,
|
|
||||||
finished_at: new Date(),
|
|
||||||
error_message: error.message,
|
|
||||||
updatedById: currentUser?.id || null,
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -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 } };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user