Skip to content

Commit

Permalink
feat: get inserted count
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Apr 9, 2023
1 parent 7ca4f25 commit 498af25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ router.get('/resources', async (request, env: Env) => {

router.put('/resources', async (request, env: Env) => {
try {
await handleScheduled(env);
return makeResponse({});
return makeResponse(await handleScheduled(env));
} catch (error) {
console.log(error);
return makeErrorResponse({}, { status: 400 });
Expand Down
4 changes: 4 additions & 0 deletions packages/worker/src/scheduled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { makePrisma } from './prisma';
export async function handleScheduled(env: Env) {
const prisma = makePrisma(env);

let sum = 0;
const teams = new Set<number>();
const users = new Set<number>();

Expand Down Expand Up @@ -71,6 +72,9 @@ export async function handleScheduled(env: Env) {
});

if (count === 0) break;
sum += count;
console.log(`There are ${count} resources inserted`);
}

return { count: sum };
}

0 comments on commit 498af25

Please sign in to comment.