Skip to content

Commit

Permalink
Merge pull request #1121 from hackclub/add-daily-shirt-generation-job
Browse files Browse the repository at this point in the history
Add daily shirt generation job trigger
  • Loading branch information
maxwofford authored Jan 22, 2025
2 parents c54b63e + 16f313a commit 8e3dd78
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
12 changes: 0 additions & 12 deletions src/app/api/cron/create-background-job.ts

This file was deleted.

40 changes: 39 additions & 1 deletion src/app/api/cron/every-day/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
export const dynamic = 'force-dynamic'
export const fetchCache = 'force-no-store'

import createBackgroundJob from '../create-background-job'
import 'server-only'
import Airtable from 'airtable'

async function triggerShirtJob() {
Airtable.configure({
apiKey: process.env.AIRTABLE_API_KEY,
endpointUrl: process.env.AIRTABLE_ENDPOINT_URL,
})

const base = Airtable.base(process.env.BASE_ID)
console.log('Getting people to regenerate')
const peopleToRegenerate = await base('people')
.select({
filterByFormula: `
AND(
NOT({action_generate_shirt_design} = TRUE()),
NOT({ysws_submission} = BLANK())
)`,
fields: [],
})
.all()

const peopleIds = peopleToRegenerate.map((person) => person.id)
console.log('People to regenerate:', peopleIds.length)
const chunkSize = 10
for (let i = 0; i < peopleIds.length; i += chunkSize) {
console.log(`Processing chunk ${i} to ${i + chunkSize}`)
const chunk = peopleIds.slice(i, i + chunkSize)
await base('people').update(
chunk.map((id) => ({
id,
fields: {
action_generate_shirt_design: true,
},
})),
)
}
}

async function processDailyJobs() {
console.log('Processing daily jobs')
await triggerShirtJob()
}

export async function GET() {
Expand Down

0 comments on commit 8e3dd78

Please sign in to comment.