fix(publish): no saltar piezas programadas en revisión
El cron también publica revision_agencia/programada con horario vencido; mover en calendario deja la pieza en cola. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -105,6 +105,10 @@ async function syncPipelineSchedule(
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
scheduled_at: scheduledAt,
|
scheduled_at: scheduledAt,
|
||||||
|
// Mover en calendario = reprogramar: el cron debe poder publicarla
|
||||||
|
status: 'aprobada',
|
||||||
|
publish_status: 'queued',
|
||||||
|
publish_error: null,
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,10 +94,13 @@ export async function processDuePipelinePublishes(opts?: {
|
|||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
const limit = Math.min(50, Math.max(1, opts?.limit || 10));
|
const limit = Math.min(50, Math.max(1, opts?.limit || 10));
|
||||||
|
|
||||||
// Two complementary queries (PostgREST OR with nested AND is fragile).
|
// Complementary queries (PostgREST OR with nested AND is fragile).
|
||||||
|
// Incluye revision_agencia/programada en idle: a veces se programa
|
||||||
|
// desde calendario sin pasar por el flujo que pone publish_status=queued.
|
||||||
const common =
|
const common =
|
||||||
`scheduled_at=lte.${encodeURIComponent(now)}` +
|
`scheduled_at=lte.${encodeURIComponent(now)}` +
|
||||||
`&cover_path=not.is.null` +
|
`&cover_path=not.is.null` +
|
||||||
|
`&published_at=is.null` +
|
||||||
`&select=${SELECT}&order=scheduled_at.asc&limit=${limit}` +
|
`&select=${SELECT}&order=scheduled_at.asc&limit=${limit}` +
|
||||||
(opts?.tenantId
|
(opts?.tenantId
|
||||||
? `&tenant_id=eq.${encodeURIComponent(opts.tenantId)}`
|
? `&tenant_id=eq.${encodeURIComponent(opts.tenantId)}`
|
||||||
@@ -108,13 +111,20 @@ export async function processDuePipelinePublishes(opts?: {
|
|||||||
`${base}/rest/v1/creative_pipeline?publish_status=in.(queued,failed)&${common}`;
|
`${base}/rest/v1/creative_pipeline?publish_status=in.(queued,failed)&${common}`;
|
||||||
const q2 =
|
const q2 =
|
||||||
`${base}/rest/v1/creative_pipeline?publish_status=eq.idle&status=eq.aprobada&${common}`;
|
`${base}/rest/v1/creative_pipeline?publish_status=eq.idle&status=eq.aprobada&${common}`;
|
||||||
|
const q3 =
|
||||||
|
`${base}/rest/v1/creative_pipeline?publish_status=eq.idle&status=in.(revision_agencia,programada)&${common}`;
|
||||||
|
|
||||||
const [r1, r2] = await Promise.all([
|
const [r1, r2, r3] = await Promise.all([
|
||||||
fetch(q1, { headers, cache: 'no-store' }),
|
fetch(q1, { headers, cache: 'no-store' }),
|
||||||
fetch(q2, { headers, cache: 'no-store' }),
|
fetch(q2, { headers, cache: 'no-store' }),
|
||||||
|
fetch(q3, { headers, cache: 'no-store' }),
|
||||||
]);
|
]);
|
||||||
if (!r1.ok || !r2.ok) {
|
if (!r1.ok || !r2.ok || !r3.ok) {
|
||||||
const err = !r1.ok ? await r1.text() : await r2.text();
|
const err = !r1.ok
|
||||||
|
? await r1.text()
|
||||||
|
: !r2.ok
|
||||||
|
? await r2.text()
|
||||||
|
: await r3.text();
|
||||||
return { ok: false, due: 0, results: [], error: err.slice(0, 400) };
|
return { ok: false, due: 0, results: [], error: err.slice(0, 400) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,9 +134,10 @@ export async function processDuePipelinePublishes(opts?: {
|
|||||||
updated_at?: string;
|
updated_at?: string;
|
||||||
})[];
|
})[];
|
||||||
const b = (await r2.json()) as typeof a;
|
const b = (await r2.json()) as typeof a;
|
||||||
|
const c = (await r3.json()) as typeof a;
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
const due: typeof a = [];
|
const due: typeof a = [];
|
||||||
for (const row of [...a, ...b]) {
|
for (const row of [...a, ...b, ...c]) {
|
||||||
if (seen.has(row.id)) continue;
|
if (seen.has(row.id)) continue;
|
||||||
seen.add(row.id);
|
seen.add(row.id);
|
||||||
due.push(row);
|
due.push(row);
|
||||||
|
|||||||
Reference in New Issue
Block a user