Skip to content

Commit

Permalink
feat(schedule): cronをAPI-fetchではなく直接実行するように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
wiyco committed Feb 3, 2025
1 parent 066c0b9 commit d3cab52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import api from "~/api";
import { APIError, apiErrorHandler } from "~/handler";
import { authMiddleware } from "~/middleware";
import type { Bindings } from "~/types";
import { callCronEndpoint } from "./schedule";
import { cron } from "./schedule";

const app = new Hono<{ Bindings: Bindings }>();

Expand All @@ -23,12 +23,7 @@ const scheduled: ExportedHandlerScheduledHandler<Bindings> = async (
env,
ctx,
) => {
ctx.waitUntil(
callCronEndpoint({
path: "/v1/cron",
env,
}),
);
ctx.waitUntil(cron(env));
};

export default {
Expand Down
12 changes: 12 additions & 0 deletions src/schedule/cron.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { CronService } from "~/api/v1/cron/service";
import type { Bindings } from "~/types";
import { generateHMAC } from "~/utils/crypto";

export async function cron(env: Bindings) {
console.log("Processing cron job...");

try {
await CronService.processCronJob(env);
console.log(`Cron job processed at ${new Date().toISOString()}`);
} catch (error) {
console.error("Cron job processing failed:", error);
}
}

export async function callCronEndpoint(props: {
path: string;
env: Bindings;
Expand Down

0 comments on commit d3cab52

Please sign in to comment.