Skip to content

Commit

Permalink
Use cron.ts instead of manual scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Oct 16, 2024
1 parent 00916fd commit 7176232
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 10 additions & 0 deletions convex/cron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { cronJobs } from "convex/server";
import { internal } from "./_generated/api";

const crons = cronJobs();

crons.interval(
"run games for all active models",
{ minutes: 5 },
internal.models.runActiveModelsGames,
);
1 change: 0 additions & 1 deletion convex/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ export default internalMutation({
handler: async (ctx) => {
await ctx.runMutation(internal.maps.seedMaps);
await ctx.runMutation(internal.models.seedModels);
await ctx.runMutation(internal.models.scheduleModelsGames);
},
});
6 changes: 2 additions & 4 deletions convex/models.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AI_MODELS } from "./constants";
import { api, internal } from "./_generated/api";
import { api } from "./_generated/api";
import { internalMutation, query } from "./_generated/server";

export const scheduleModelsGames = internalMutation({
export const runActiveModelsGames = internalMutation({
handler: async (ctx) => {
const models = await ctx.runQuery(api.models.getActiveModels);

Expand All @@ -11,8 +11,6 @@ export const scheduleModelsGames = internalMutation({
ctx.runMutation(api.games.startNewGame, { modelId: model.slug }),
),
);

await ctx.scheduler.runAfter(300_000, internal.models.scheduleModelsGames);
},
});

Expand Down

0 comments on commit 7176232

Please sign in to comment.