imperium

@smounters/imperium-cron

Cron scheduling for @smounters/imperium. Decorate methods with @Cron() and they run on a schedule. Jobs auto-stop on application shutdown.

Part of the Imperium monorepo.

Built on croner — lightweight, zero-dependency cron scheduler.

Install

pnpm add @smounters/imperium-cron

Usage

import { Injectable, Module } from "@smounters/imperium/decorators";
import { Cron, CronModule } from "@smounters/imperium-cron";

@Injectable()
class MarketSync {
  @Cron("*/30 * * * * *") // every 30 seconds
  async syncPrices() {
    // fetch latest prices
  }

  @Cron("0 0 * * *", { name: "daily-cleanup" })
  async cleanup() {
    // remove old data
  }
}

@Module({
  imports: [CronModule.register({ providers: [MarketSync] })],
})
class AppModule {}

API

@Cron(expression, options?)

Method decorator. Registers the method to run on a cron schedule.

CronModule.register({ providers })

Dynamic module. Pass providers that contain @Cron() methods. Only providers with at least one @Cron() method are scanned.

CronService

Injectable service for introspection:

Documentation

Full guide: smounters.github.io/imperium/guide/cron

License

MIT