feat(P19IM1-1,P19IM1-2): 新增通知渠道配置与Outbox派发
这个提交包含在:
@@ -1,12 +1,12 @@
|
||||
const cron = require("node-cron");
|
||||
const cron = require('node-cron');
|
||||
|
||||
const {
|
||||
fetchPendingOutboxEvents,
|
||||
markOutboxFailed,
|
||||
markOutboxProcessing,
|
||||
markOutboxSucceeded,
|
||||
} = require("../services/integrations/outbox");
|
||||
const { dispatchOutboxEvent } = require("../services/integrations/dispatcher");
|
||||
} = require('../services/integrations/outbox');
|
||||
const { dispatchOutboxEvent } = require('../services/integrations/dispatcher');
|
||||
|
||||
async function runIntegrationOutboxOnce(prisma, config, logger) {
|
||||
const items = await fetchPendingOutboxEvents(prisma, {
|
||||
@@ -21,6 +21,7 @@ async function runIntegrationOutboxOnce(prisma, config, logger) {
|
||||
|
||||
try {
|
||||
await dispatchOutboxEvent({
|
||||
prisma,
|
||||
config,
|
||||
eventType: item.event_type,
|
||||
payload: item.payload,
|
||||
@@ -28,7 +29,7 @@ async function runIntegrationOutboxOnce(prisma, config, logger) {
|
||||
await markOutboxSucceeded(prisma, item.id, null);
|
||||
succeeded += 1;
|
||||
} catch (error) {
|
||||
const retryable = typeof error?.retryable === "boolean" ? error.retryable : true;
|
||||
const retryable = typeof error?.retryable === 'boolean' ? error.retryable : true;
|
||||
await markOutboxFailed(prisma, config, item, error, null, { retryable });
|
||||
failed += 1;
|
||||
logger.error(
|
||||
@@ -37,8 +38,11 @@ async function runIntegrationOutboxOnce(prisma, config, logger) {
|
||||
retryable,
|
||||
outboxId: item.id,
|
||||
eventType: item.event_type,
|
||||
channelId: item.payload?.channelId ?? null,
|
||||
channelType: item.payload?.channelType ?? null,
|
||||
notificationType: item.payload?.notificationType ?? null,
|
||||
},
|
||||
"Integration outbox dispatch failed",
|
||||
'Integration outbox dispatch failed',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -66,16 +70,16 @@ function startIntegrationOutboxJob(fastify) {
|
||||
fastify.log,
|
||||
);
|
||||
fastify.metrics?.jobRunsTotal?.inc?.({
|
||||
job: "integration.outbox.dispatch",
|
||||
driver: "cron",
|
||||
outcome: "success",
|
||||
job: 'integration.outbox.dispatch',
|
||||
driver: 'cron',
|
||||
outcome: 'success',
|
||||
});
|
||||
if (result.succeeded > 0) {
|
||||
fastify.metrics?.jobProcessedTotal?.inc?.(
|
||||
{
|
||||
job: "integration.outbox.dispatch",
|
||||
driver: "cron",
|
||||
kind: "succeeded",
|
||||
job: 'integration.outbox.dispatch',
|
||||
driver: 'cron',
|
||||
kind: 'succeeded',
|
||||
},
|
||||
result.succeeded,
|
||||
);
|
||||
@@ -83,26 +87,26 @@ function startIntegrationOutboxJob(fastify) {
|
||||
if (result.failed > 0) {
|
||||
fastify.metrics?.jobProcessedTotal?.inc?.(
|
||||
{
|
||||
job: "integration.outbox.dispatch",
|
||||
driver: "cron",
|
||||
kind: "failed",
|
||||
job: 'integration.outbox.dispatch',
|
||||
driver: 'cron',
|
||||
kind: 'failed',
|
||||
},
|
||||
result.failed,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
fastify.log.error({ err: error }, "Integration outbox job failed");
|
||||
fastify.log.error({ err: error }, 'Integration outbox job failed');
|
||||
fastify.metrics?.jobRunsTotal?.inc?.({
|
||||
job: "integration.outbox.dispatch",
|
||||
driver: "cron",
|
||||
outcome: "failure",
|
||||
job: 'integration.outbox.dispatch',
|
||||
driver: 'cron',
|
||||
outcome: 'failure',
|
||||
});
|
||||
} finally {
|
||||
running = false;
|
||||
}
|
||||
});
|
||||
|
||||
fastify.addHook("onClose", async () => {
|
||||
fastify.addHook('onClose', async () => {
|
||||
task.stop();
|
||||
task.destroy();
|
||||
});
|
||||
@@ -112,7 +116,7 @@ function startIntegrationOutboxJob(fastify) {
|
||||
cron: fastify.config.integrationOutboxCron,
|
||||
batchSize: fastify.config.integrationOutboxBatchSize,
|
||||
},
|
||||
"Integration outbox job scheduled",
|
||||
'Integration outbox job scheduled',
|
||||
);
|
||||
|
||||
return task;
|
||||
|
||||
在新工单中引用
屏蔽一个用户