C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • WebSockets
  • Task Scheduling
  • Queues
  • Job Batches
  • Caching
  • Events
  • Broadcasting
  • Notifications
  • SMS Channels
  • File Storage
  • Payment
  • Search
  • Security
  • Security Comparison
  • Performance
  • HTTP/2 Support
  • Deployment
Advanced

Task Scheduling

Define your scheduled tasks directly in code using a fluent API, instead of managing raw crontab entries.

Defining Schedules

You can define tasks using scheduler.call() or scheduler.command().

src/schedule.ts
1// src/app.ts or src/schedule.ts
2import { scheduler } from "canxjs";
3
4// Schedule a closure to run every minute
5scheduler.call(() => {
6 console.log("Running every minute");
7}).everyMinute();
8
9// Schedule a command
10scheduler.command("bun run cleanup").dailyAt("02:00");
11
12// Advanced chaining
13scheduler.call(async () => {
14 await db.users.deleteExpired();
15})
16.name("cleanup-users")
17.withoutOverlapping()
18.every("5m");

Running the Scheduler

On your server, you only need to add a single cron entry that runs the `canx schedule:run` command every minute.

Terminal/Crontab
# Run the scheduler (manual)
bun run canx schedule:run
# Setup Cron (Linux/Mac)
* * * * * cd /path/to/project && bun run canx schedule:run >> /dev/null 2>&1

Next Steps

Optimize your application performance with caching.