Skip to content

Commit

Permalink
feat: add cron job for processing video tasks and update Deno configu…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
Ovler-Young committed Dec 24, 2024
1 parent ac307ed commit d4fdbad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
"compilerOptions": {
"jsx": "precompile",
"jsxImportSource": "hono/jsx"
},
"deploy": {
"project": "f4b70966-04b4-4b53-9110-1f64c556bc5c",
"exclude": [
"**/node_modules"
],
"include": [],
"entrypoint": "main.ts"
}
}
8 changes: 7 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from './src/index.ts'
import { app, processVideoTasks } from './src/index.ts'

// const app = new Hono()

Expand All @@ -7,3 +7,9 @@ app.get('/', (c) => {
})

Deno.serve({ port: 8787 },app.fetch)

Deno.cron("sample cron", "* * * * *", async () => {
console.log("cron job running every minute");
const result = await processVideoTasks();
console.log("Processed video tasks:", result);
});
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ async function fetchTasks(apibase: string): Promise<number[]> {
.filter((aid) => typeof aid === "number") as number[];
}

async function processVideoTasks(apibase: string, aids: number[]) {
export async function processVideoTasks() {
const apibase = getAPIBASE();
const aids = await fetchTasks(apibase);
console.log(`Starting task with ${aids.length} videos`);

const data: BiliResponse = (await batchGetVideoInfo(aids)) as BiliResponse;
Expand Down Expand Up @@ -122,10 +124,8 @@ app.get("/gettasks", async (c) => {
});

app.get("/starttask", async (c) => {
const apibase = getAPIBASE();
try {
const aids = await fetchTasks(apibase);
const result = await processVideoTasks(apibase, aids);
const result = await processVideoTasks();
return c.json(result);
} catch (error: any) {
return c.json({ error: error.message }, 500);
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"@cloudflare/workers-types/2023-07-01"
],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
"jsxImportSource": "hono/jsx",
"allowImportingTsExtensions": true,
"noEmit": true
},
}

0 comments on commit d4fdbad

Please sign in to comment.