CRON Jobs

Automate and manage recurring tasks in your VitNode app with cron jobs — perfect for cleanups, emails, reports, and more.

Adapters

Before you can use cron functionality, you need to provide an adapter to your application.

Usage

Create CRON file

cron/clean.cron.ts
import { buildCron } from "@vitnode/core/api/lib/cron";

export const cleanCron = buildCron({
  name: "clean",
  description: "Clean up expired sessions and tokens",
  // Run every 1 hour
  schedule: "0 * * * *",
  handler: async c => {
    console.log("Running cleanup cron job...");
  },
});

Register CRON in module

modules/clean/clean.module.ts
import { buildModule } from "@vitnode/core/api/lib/module";
import { CONFIG_PLUGIN } from "@/config";

import { cleanCron } from "./cron/clean.cron";

export const cronModule = buildModule({
  pluginId: CONFIG_PLUGIN.pluginId,
  name: "clean",
  routes: [],
  cronJobs: [cleanCron],
});

Check Your Cron Job

When your CRON job will run first time, you should see your job in AdminCP under Core => Advanced => Cron Jobs.

CRON Jobs - VitNode