Skip to content

Commit

Permalink
fix: implement keeping cloudflare function open while logstream runs?
Browse files Browse the repository at this point in the history
  • Loading branch information
xynydev committed Apr 22, 2024
1 parent 9696fda commit ab2e868
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/routes/api/github/createRepo/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { ghApiGet, ghApiPost, ghApiPut } from "$lib/ts/github/api";
import { createLogStream } from "$lib/ts/misc/logStream";
import type { Endpoints } from "@octokit/types";

export async function POST({ request, cookies }): Promise<Response> {
export async function POST({ request, cookies, platform }): Promise<Response> {
let done = false;
async function waitForDone() {
while (!done) {
await new Promise((r) => setTimeout(r, 100));
}
return null;
}
platform?.context.waitUntil(waitForDone());

return await createLogStream(async (log) => {
const token = cookies.get("github_oauth_token");
if (token === undefined) throw new Error("Not logged in");
Expand Down Expand Up @@ -111,5 +120,6 @@ export async function POST({ request, cookies }): Promise<Response> {
// }

log("Initial repository setup DONE!");
done = true;
});
}

0 comments on commit ab2e868

Please sign in to comment.