diff --git a/README.md b/README.md index 2d8a2b6..85e8af7 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ If you want to mock all models - in convex, please add the following environment - `npx convex env set MOCK_MODELS true` - `npx convex env set FLAG_TEST_PAGE true` +- `npx convex env set FLAG_CRON_JOBS true` Add optional environment variable/s for simulating real AI models without mockup responses(when mockup flags are set to FALSE): diff --git a/convex/constants.ts b/convex/constants.ts index a1b390f..849abb4 100644 --- a/convex/constants.ts +++ b/convex/constants.ts @@ -16,3 +16,7 @@ export const AI_MODEL_IDS = AI_MODELS.map((model) => model.model); export const PLAY_DELAY = process.env.PLAY_DELAY ? parseInt(process.env.PLAY_DELAY) : 0; + +export const CRON_INTERVAL = process.env.CRON_INTERVAL + ? parseInt(process.env.CRON_INTERVAL) + : 60; diff --git a/convex/crons.ts b/convex/crons.ts index e703dfe..7f1c752 100644 --- a/convex/crons.ts +++ b/convex/crons.ts @@ -1,11 +1,12 @@ import { cronJobs } from "convex/server"; import { internal } from "./_generated/api"; +import { CRON_INTERVAL } from "./constants"; const crons = cronJobs(); crons.interval( "run games for all active models", - { minutes: 60 }, + { minutes: CRON_INTERVAL }, internal.models.runActiveModelsGames, ); diff --git a/convex/flags.ts b/convex/flags.ts index 55619f3..24538e6 100644 --- a/convex/flags.ts +++ b/convex/flags.ts @@ -5,6 +5,7 @@ export const getFlags = query({ handler: async (ctx) => { return { showTestPage: process.env.FLAG_TEST_PAGE === "true", + enableCronJobs: process.env.FLAG_CRON_JOBS === "true", }; }, }); diff --git a/convex/models.ts b/convex/models.ts index 2fd89b7..e1cbf70 100644 --- a/convex/models.ts +++ b/convex/models.ts @@ -4,6 +4,11 @@ import { internalMutation, query } from "./_generated/server"; export const runActiveModelsGames = internalMutation({ handler: async (ctx) => { + const flags = await ctx.runQuery(api.flags.getFlags); + if (!flags.enableCronJobs) { + return; + } + const models = await ctx.runQuery(api.models.getActiveModels); await Promise.all(