diff --git a/convex/cron.ts b/convex/cron.ts new file mode 100644 index 0000000..1999d95 --- /dev/null +++ b/convex/cron.ts @@ -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, +); diff --git a/convex/init.ts b/convex/init.ts index 658b8e7..93852f5 100644 --- a/convex/init.ts +++ b/convex/init.ts @@ -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); }, }); diff --git a/convex/models.ts b/convex/models.ts index 57c6933..1f58997 100644 --- a/convex/models.ts +++ b/convex/models.ts @@ -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); @@ -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); }, });