Skip to content

Mann-Conomy/job-scheduler

Repository files navigation

job-scheduler

A simple background job scheduler for the Mann-Conomy project.

npm version npm downloads Node.js version GitHub actions GitHub license

Installation

Using npm:

$ npm install @mann-conomy/job-scheduler

Using yarn:

$ yarn add @mann-conomy/job-scheduler

Testing

Using npm:

$ npm test

Using yarn:

$ yarn test

Examples

Fetching the full Team Fortress 2 item schema from the Steam Web API every day at 04:05.

import { randomUUID } from "crypto";
import { SchemaClient } from "@mann-conomy/tf-schema";
import { JobScheduler, JobEvent } from "@mann-conomy/job-scheduler";

const client = new SchemaClient(process.env.STEAM_WEB_API_KEY!);

const scheduler = new JobScheduler("Europe/Copenhagen");
scheduler.on(JobEvent.Created, (id: string) => {
    scheduler.start(id);
});

const uuid = randomUUID();

try {
    scheduler.schedule(uuid, "5 4 * * *", async () => await client.getItemSchema());
} catch(error) {
    if (error instanceof Error) {
        console.error("Error scheduling job", error.message);
    }
}

Some more examples are available in the examples and test directories.

Documentation

See the Wiki pages for further documentation.

License

MIT

Copyright 2025, The Mann-Conomy Project