Skip to content

Commit

Permalink
add logging to email/jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
konstrybakov committed Jul 25, 2024
1 parent 8952520 commit 547a6ab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/api/email/jobs/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Jobs from '@/emails/jobs'
import { queryGetJobs } from '@/lib/db/queries'
import { logger } from '@/lib/logger'
import { render } from '@react-email/render'
import { ReasonPhrases, StatusCodes } from 'http-status-codes'
import { headers } from 'next/headers'
Expand All @@ -9,6 +10,8 @@ const resend = new Resend(process.env.RESEND_API_KEY)

export const GET = async () => {
try {
logger.info('Starting `send-email` cron job')

const headerList = headers()
const auth = headerList.get('Authorization')

Expand All @@ -25,13 +28,20 @@ export const GET = async () => {

const recipients = process.env.PERSONAL_EMAIL

logger.info('Found recipients')

if (!recipients) {
throw new Error('No recipients found')
}

const { data: jobs } = await queryGetJobs(['new'])
const { data: savedJobs } = await queryGetJobs(['topChoice'])

logger.info(
{ newJobs: jobs.length, savedJobs: savedJobs.length },
'Found jobs',
)

const { data, error } = await resend.emails.send({
from: 'OWAT <[email protected]>',
to: [recipients],
Expand All @@ -45,6 +55,8 @@ export const GET = async () => {

return Response.json({ data }, { status: StatusCodes.OK })
} catch (error) {
logger.error({ error }, 'Error sending email')

return Response.json(
{ error },
{ status: StatusCodes.INTERNAL_SERVER_ERROR },
Expand Down

0 comments on commit 547a6ab

Please sign in to comment.