attach the request id during the job
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Elizabeth Hunt 2024-12-15 14:03:55 -08:00
parent c0a96e82af
commit 157dc327e8
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE
2 changed files with 14 additions and 9 deletions

View File

@ -1,6 +1,6 @@
import { perform } from "./email"; import { perform } from "./email";
import { redactJob, type EmailJob } from "./job"; import { redactJob, type EmailJob } from "./job";
import { ConsoleLogger } from "./logger"; import { ConsoleLogger, type Logger } from "./logger";
export const main = (port: number) => { export const main = (port: number) => {
const server = Bun.serve({ const server = Bun.serve({
@ -14,27 +14,32 @@ export const main = (port: number) => {
const jobInsensitive = redactJob(job); const jobInsensitive = redactJob(job);
const uuid = crypto.randomUUID(); const uuid = crypto.randomUUID();
ConsoleLogger.info( const logger: Logger = {
`[${uuid}] Received email job: ${JSON.stringify(jobInsensitive)}`, info: (message) => ConsoleLogger.info(`[${uuid}] ${message}`),
warn: (message) => ConsoleLogger.warn(`[${uuid}] ${message}`),
error: (message) => ConsoleLogger.error(`[${uuid}] ${message}`),
}
logger.info(
`Received email job: ${JSON.stringify(jobInsensitive)}`,
)(); )();
const performEmailTest = perform(job)(); const performEmailTest = perform(job, undefined, logger)();
return performEmailTest return performEmailTest
.then((result) => { .then((result) => {
if (result._tag === "Left") { if (result._tag === "Left") {
const error = result.left; const error = result.left;
ConsoleLogger.warn( logger.warn(
`[${uuid}] job failure due to ${error.message}`, `job failure due to ${error.message}`,
)(); )();
return new Response(error.message, { return new Response(error.message, {
status: 400, status: 400,
}); });
} }
ConsoleLogger.info(`[${uuid}] success`)(); logger.info('success')();
return Response.json({ success: true }); return Response.json({ success: true });
}) })
.catch((e) => { .catch((e) => {
ConsoleLogger.error(`[${uuid}] internal failure due to ${e}`)(); logger.error(`internal failure due to ${e}`)();
return new Response(e.message, { return new Response(e.message, {
status: 500, status: 500,
}); });

View File

@ -3,7 +3,7 @@ import * as TE from "fp-ts/lib/TaskEither";
import * as O from "fp-ts/lib/Option"; import * as O from "fp-ts/lib/Option";
import { createTransport } from "nodemailer"; import { createTransport } from "nodemailer";
import { toError } from "fp-ts/lib/Either"; import { toError } from "fp-ts/lib/Either";
import { flow, pipe } from "fp-ts/lib/function"; import { pipe } from "fp-ts/lib/function";
import { import {
ImapFlow, ImapFlow,
type FetchMessageObject, type FetchMessageObject,