fix(notifications): replace Cloud Run job with worker service
This commit is contained in:
46
backend/command-api/src/worker-app.js
Normal file
46
backend/command-api/src/worker-app.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import pino from 'pino';
|
||||
import pinoHttp from 'pino-http';
|
||||
|
||||
const logger = pino({ level: process.env.LOG_LEVEL || 'info' });
|
||||
|
||||
export function createWorkerApp({ dispatch = async () => ({}) } = {}) {
|
||||
const app = express();
|
||||
|
||||
app.use(
|
||||
pinoHttp({
|
||||
logger,
|
||||
})
|
||||
);
|
||||
app.use(express.json({ limit: '256kb' }));
|
||||
|
||||
app.get('/health', (_req, res) => {
|
||||
res.status(200).json({ ok: true, service: 'notification-worker-v2' });
|
||||
});
|
||||
|
||||
app.get('/readyz', (_req, res) => {
|
||||
res.status(200).json({ ok: true, service: 'notification-worker-v2' });
|
||||
});
|
||||
|
||||
app.post('/tasks/dispatch-notifications', async (req, res) => {
|
||||
try {
|
||||
const summary = await dispatch();
|
||||
res.status(200).json({ ok: true, summary });
|
||||
} catch (error) {
|
||||
req.log?.error?.({ err: error }, 'notification dispatch failed');
|
||||
res.status(500).json({
|
||||
ok: false,
|
||||
error: error?.message || String(error),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.use((_req, res) => {
|
||||
res.status(404).json({
|
||||
code: 'NOT_FOUND',
|
||||
message: 'Route not found',
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
Reference in New Issue
Block a user