Skip to content

Commit 3d88cdd

Browse files
committed
Batch requests
1 parent e150a8e commit 3d88cdd

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

website/workers/app.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ export default {
6565
)
6666
)
6767
.orderBy(asc(sql`date(timestamp)`))
68+
.limit(99) // Limit to 99 days which is the limit of the workflow instances
6869
.catch((error) => {
6970
throw new Error("Failed to get dates", { cause: error });
7071
});
7172
const days = allDates.map((date) => new Date(date.day as string));
72-
for (const day of days) {
73-
const workflowInstance = await env.WORKFLOW_OVERNIGHT_SAVE_TO_R2.create({
74-
params: {
75-
dayToProcess: day,
76-
},
77-
});
78-
await workflowInstance.status();
79-
}
73+
// Create a new batch of 3 Workflow instances, each with its own ID and pass params to the Workflow instances
74+
await env.WORKFLOW_OVERNIGHT_SAVE_TO_R2.createBatch(
75+
days.map((day) => ({
76+
params: { dayToProcess: day },
77+
}))
78+
);
79+
console.log(`Created ${days.length} workflow instances`);
8080
},
8181
} satisfies ExportedHandler<Env>;
8282

website/wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
"preview_urls": false,
7474
"triggers": {
75-
"crons": ["30 2 * * *"] // every day at 2:30 AM UTC
75+
"crons": ["15 10 * * *"] // every day at 10:15 AM UTC
7676
},
7777
"version_metadata": {
7878
"binding": "CF_VERSION_METADATA"

0 commit comments

Comments
 (0)