Task schedule is a piece of shit
Source: Dev.to
Overview
Run your TypeScript file at a specific time. The library supports three scheduling methods:
- interval – run repeatedly at a set interval
- atTime – run once at a specific time each day
- inRange – run within a defined time range
For detailed options, see api.ts.
Creating a Script
- Create a TypeScript file in the
scriptsfolder with the.sche.tsextension. - Import the API and instantiate it.
// import API from api.ts
import { API } from './api.ts';
// instantiate API
const timer = new API();Examples
Interval
Run a function every 5 minutes:
timer.interval({
min: 5,
func: () => {
console.log('hello world');
}
});At a Specific Time
Run a function every day at 10:00:
timer.atTime({
time: '10:00',
func: () => {
console.log('hello world');
}
});Startup with the OS
To launch the script automatically on system start, create a shortcut (Alt + Drag) and place it in the shell:startup folder.
Using Packages
If your script requires additional packages, initialize an npm project and install dependencies using npm or bun.
npm init -y
npm install
# or with bun
bun init
bun add Configuration
You can adjust the checkInterval setting in api.ts to change how frequently the scheduler checks for pending tasks.