For the life of me, I'm not sure what part of my code is causing this. The result appears to be a handful of openai calls that are immediately failing, so I'm doing something wrong.
I've bundled my async code into a single function which returns via
return Promise.all(promises)
return Promise.all(promises)
to ctx.waitUntil() in my fetch.
Running it locally (see screenshot) is also indecipherable.
async fetch(_: FetchEvent, env: Env, ctx: ExecutionContext) { const scheduledSync = new ScheduledSync(env) ctx.waitUntil(scheduledSync.sync()) return new Response('ok') },
async fetch(_: FetchEvent, env: Env, ctx: ExecutionContext) { const scheduledSync = new ScheduledSync(env) ctx.waitUntil(scheduledSync.sync()) return new Response('ok') },
sync.ts (truncated)
export default class ScheduledSync { private env: Env constructor(env: Env) { this.env = env } public async sync(): Promise<any> { let results: any = [] // truncated for clarity: const users = await g.query<User>('SELECT * FROM echo.dim_users WHERE name iS NOT NULL AND name <> ""') // owners/teammates for this org results = results.concat( Promise.all( users.map((user) => { // ... return v.upsert(`user:${user.source_system}:${user.user_id}`, text, meta) }) ) ) return results }}
export default class ScheduledSync { private env: Env constructor(env: Env) { this.env = env } public async sync(): Promise<any> { let results: any = [] // truncated for clarity: const users = await g.query<User>('SELECT * FROM echo.dim_users WHERE name iS NOT NULL AND name <> ""') // owners/teammates for this org results = results.concat( Promise.all( users.map((user) => { // ... return v.upsert(`user:${user.source_system}:${user.user_id}`, text, meta) }) ) ) return results }}