Job Adapter
Reading time:2 min read
The ScheduleJobAdapter wraps a specific scheduled job implementation so the schedule system can interact with jobs (pause, resume, destroy) without knowing the underlying library.
There are two default implementations: CronJobAdapter wraps jobs created by the croner library for cron strings and Dates, and TimerJobAdapter runs millisecond intervals with its own timer.
When to override
| ✅ Override if you want to... | ❌ Don't override if you want to... |
|---|---|
Use a different timing/job backend (not croner) through a custom ScheduleExecutionScheduler. | Change only schedule storage or execution behavior. Those are responsibilities of ScheduleRepository and ScheduleExecutor. |
Adapt a third-party scheduler/queue API to Nyx's pause/resume/destroy contract. | Only change interval parsing or next-run calculation. That belongs to ScheduleExecutionScheduler. |
Wrap platform-specific timer handles (e.g., setTimeout-based jobs) behind a uniform adapter API. | Add pre-execution checks. That belongs to ScheduleMiddlewareList. |
Overriding
Creation
Create a custom adapter implementing ScheduleJobAdapter.
import type { , } from '@nyx-discord/djs';
class implements <NodeJS.Timeout> {
constructor(
private readonly : NodeJS.Timeout,
private readonly :
) {}
public () {
(this.);
return this;
}
public () {
this..();
return this;
}
public () {
(this.);
return this;
}
public () {
// NodeJS.Timeout has no built-in running-state check; illustrative only.
return true;
}
public () {
return this.;
}
public () {
return this.;
}
}Registration
Use your adapter from a custom ScheduleExecutionScheduler, then set that scheduler to the ScheduleManager.
import type { } from '@nyx-discord/djs';
declare const : ;
.().(.());Edit on GitHub
Last updated on
