@nexim/task-scheduler
Version:
A TypeScript task scheduler with persistence and conditional execution.
74 lines (42 loc) • 1.92 kB
Markdown
[@nexim/task-scheduler](../README.md) / TaskScheduler
# Class: TaskScheduler
Manages scheduled tasks with persistence and conditional execution
## Constructors
### Constructor
> **new TaskScheduler**(): `TaskScheduler`
#### Returns
`TaskScheduler`
## Methods
### addTask()
> **addTask**(`id`: `string`, `fn`: () => `void` \| `Promise`\<`void`\>, `interval`: `Duration`, `options?`: [`TaskOptions`](../interfaces/TaskOptions.md)): `void`
Adds a new scheduled task
#### Parameters
| Parameter | Type | Description |
| ---------- | --------------------------------------------- | ------------------------------------- |
| `id` | `string` | Unique task identifier |
| `fn` | () => `void` \| `Promise`\<`void`\> | Function to execute |
| `interval` | `Duration` | Execution interval (e.g., '5m', '1h') |
| `options?` | [`TaskOptions`](../interfaces/TaskOptions.md) | Additional task options |
#### Returns
`void`
---
### removeTask()
> **removeTask**(`id`: `string`): `void`
Removes a task from the scheduler
#### Parameters
| Parameter | Type | Description |
| --------- | -------- | ------------------------- |
| `id` | `string` | Task identifier to remove |
#### Returns
`void`
---
### updateLastRun()
> **updateLastRun**(`id`: `string`, `timestamp`: `number`): `void`
Updates the last run timestamp for a task (useful for external trigger tasks)
#### Parameters
| Parameter | Type | Description |
| ----------- | -------- | ---------------------------------------- |
| `id` | `string` | Task identifier |
| `timestamp` | `number` | New last run timestamp (defaults to now) |
#### Returns
`void`