A lightweight cron-style scheduler for Roblox-TS projects. It lets you register callbacks against cron expressions or shorthand aliases and trigger them from a heartbeat loop.
The package accepts either 5-field expressions (minute hour day-of-month month day-of-week) or 6-field expressions that include seconds at the front. It also includes a set of shorthand values such as @hourly, @daily, and @weekly.
yarn add @nrbx/cron
npm install @nrbx/cron
pnpm add @nrbx/cronThen add the package under your Rojo node_modules configuration:
"node_modules": {
"$className": "Folder",
"@rbxts": {
"$path": "node_modules/@rbxts"
},
"@nrbx": {
"$path": "node_modules/@nrbx"
}
}And make sure your tsconfig.json includes the package types:
"typeRoots": ["node_modules/@rbxts", "node_modules/@nrbx"]import { cron, CronShorthand } from "@nrbx/cron";
cron.jobs.add("* * * * *", () => {
print("Every minute");
});
cron.jobs.add(CronShorthand.Hourly, () => {
print("Runs every hour");
});The scheduler uses Roblox's RunService.Heartbeat to check schedules continuously as the game runs.
This package follows common cron semantics with a few helpful extras:
- 5-field format:
minute hour dayOfMonth month dayOfWeek - 6-field format:
second minute hour dayOfMonth month dayOfWeek - Shorthand aliases:
@yearly,@annually,@monthly,@weekly,@daily,@midnight,@hourly,@minutely,@everySecond - Lists and ranges are supported, such as
0,30,1-5, or*/15
Examples:
cron.jobs.add("0 * * * *", () => print("Every hour at minute 0"));
cron.jobs.add("0,30 * * * * *", () => print("At second 0 and 30 of every minute"));
cron.jobs.add("30 9 * * 1-5", () => print("Weekdays at 09:30"));
cron.jobs.add(CronShorthand.Daily, () => print("Daily at midnight"));Registers a new job and returns a unique job ID.
const id = cron.jobs.add("0 8 * * 1-5", () => {
print("Good morning");
});| Argument | Type | Description |
|---|---|---|
expression |
string |
Cron expression or shorthand alias |
callback |
() => void |
Function to run when the schedule matches |
Returns: string — the job ID.
Removes a job permanently.
cron.jobs.remove(id);Returns: boolean — whether a matching job was removed.
Pause or resume a registered job without deleting it.
cron.jobs.disable(id);
cron.jobs.enable(id);Remove all registered jobs.
cron.jobs.clear();Returns the current job snapshot.
const jobs = cron.jobs.list();
print(jobs.size());Start or stop the scheduler loop manually.
cron.jobs.stop();
cron.jobs.start();import { CronShorthand } from "@nrbx/cron";
CronShorthand.Yearly;
CronShorthand.Annually;
CronShorthand.Monthly;
CronShorthand.Weekly;
CronShorthand.Daily;
CronShorthand.Midnight;
CronShorthand.Hourly;
CronShorthand.Minutely;
CronShorthand.EverySecond;# Install dependencies
yarn install
# Compile with roblox-ts
yarn build
# Watch mode
yarn watch
# Lint + format with Biome
yarn biomeMIT
