Skip to content

Commit ab6b806

Browse files
authored
Merge branch 'main' into malted/rsvp-specifics-2
2 parents dfa7af5 + 8e3dd78 commit ab6b806

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

src/app/api/cron/create-background-job.ts

-12
This file was deleted.

src/app/api/cron/every-day/route.ts

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
11
export const dynamic = 'force-dynamic'
22
export const fetchCache = 'force-no-store'
33

4-
import createBackgroundJob from '../create-background-job'
4+
import 'server-only'
5+
import Airtable from 'airtable'
6+
7+
async function triggerShirtJob() {
8+
Airtable.configure({
9+
apiKey: process.env.AIRTABLE_API_KEY,
10+
endpointUrl: process.env.AIRTABLE_ENDPOINT_URL,
11+
})
12+
13+
const base = Airtable.base(process.env.BASE_ID)
14+
console.log('Getting people to regenerate')
15+
const peopleToRegenerate = await base('people')
16+
.select({
17+
filterByFormula: `
18+
AND(
19+
NOT({action_generate_shirt_design} = TRUE()),
20+
NOT({ysws_submission} = BLANK())
21+
)`,
22+
fields: [],
23+
})
24+
.all()
25+
26+
const peopleIds = peopleToRegenerate.map((person) => person.id)
27+
console.log('People to regenerate:', peopleIds.length)
28+
const chunkSize = 10
29+
for (let i = 0; i < peopleIds.length; i += chunkSize) {
30+
console.log(`Processing chunk ${i} to ${i + chunkSize}`)
31+
const chunk = peopleIds.slice(i, i + chunkSize)
32+
await base('people').update(
33+
chunk.map((id) => ({
34+
id,
35+
fields: {
36+
action_generate_shirt_design: true,
37+
},
38+
})),
39+
)
40+
}
41+
}
542

643
async function processDailyJobs() {
744
console.log('Processing daily jobs')
45+
await triggerShirtJob()
846
}
947

1048
export async function GET() {

0 commit comments

Comments
 (0)