Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Backiscute/scheduler

Repository files navigation

Back's scheduler

Join my discord server or visit my website.

What's this?

It's a task scheduler that uses either cron or setInterval.

Usage

Schedule a task

Using cron time

import Scheduler from "@backs/scheduler"

// Runs every hour
// Returns an id of type string
Scheduler.schedule("0 * * * *", () => console.log("Hello, World!"))

Using set interval

import Scheduler from "@backs/scheduler"

// Runs every 1 hour from the time of execution
// Returns an id of type string
Scheduler.schedule(60 * 60 * 1000, () => console.log("Hello, World!"))

Unscheduling a task

import Scheduler from "@backs/scheduler"

const myTaskID = Scheduler.schedule("0 * * * *", () => console.log("Hello, World!"))

Scheduler.unschedule(myTaskID)

Getting a task

import Scheduler from "@backs/scheduler"

const myTaskID = Scheduler.schedule("0 * * * *", () => console.log("Hello, World!"))

// Returns a Task object
const myTask = Schedule.getTask(myTaskID) 

NOTE

Modifying the task in any way could lead to unexpected errors. If you need to change a task just unschedule it and schedule a new one.

Getting all tasks

import Scheduler from "@backs/scheduler"

const myTaskID = Scheduler.schedule("0 * * * *", () => console.log("Hello, World!"))

// Returns an array of Task objects
const myTasks = Schedule.getTasks() 

About

A simple task scheduler.

Resources

License

Stars

Watchers

Forks

Packages

No packages published