Skip to content

Commit

Permalink
Konstantin/rka 20 setup cron job for pulling the jobs (#4)
Browse files Browse the repository at this point in the history
* rka-20: add cronjob, add route protection

* rka-20: add vercel build
  • Loading branch information
konstrybakov authored Jun 10, 2024
1 parent bd51337 commit 63c7723
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
19 changes: 17 additions & 2 deletions app/api/companies/process/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@ import { createPlatform } from '@/lib/hiring-platforms/registry'

import { logger } from '@/lib/logger'
import type { NonNullableProperty } from '@/lib/types/utils'
import { StatusCodes } from 'http-status-codes'
import { ReasonPhrases, StatusCodes } from 'http-status-codes'
import { headers } from 'next/headers'

// TODO: Express this through type also, on a lower level
const isHiringPlatform = (
company: SelectCompany,
): company is NonNullableProperty<SelectCompany, 'hiringPlatform'> =>
company.trackerType === 'hiring_platform'

export const POST = async () => {
export const GET = async () => {
const headerList = headers()
const auth = headerList.get('Authorization')

if (auth !== `Bearer ${process.env.CRON_SECRET}`) {
return Response.json(
{
message: ReasonPhrases.UNAUTHORIZED,
},
{
status: StatusCodes.UNAUTHORIZED,
},
)
}

logger.info('Processing companies and fetching jobs')

try {
Expand Down
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'

const isPublic = createRouteMatcher([])
const isPublic = createRouteMatcher(['/api/companies/process'])

export default clerkMiddleware((auth, request) => {
if (!isPublic(request)) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"dev": "PORT=4000 next dev | pino-pretty",
"build": "next build",
"build:vercel": "bun db:migrate && next build",
"start": "next start",
"lint": "next lint",
"typecheck": "tsc --noEmit",
Expand Down
8 changes: 8 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"crons": [
{
"path": "/api/companies/process",
"schedule": "0 10 * * *"
}
]
}

0 comments on commit 63c7723

Please sign in to comment.