Manager
Reading time:2 min read
The ScheduleManager is the object that holds together the nyx schedule system. At a glance:
- Registration flow: when adding a schedule, stores it in the repository and then starts its runtime job in the scheduler.
- Failure safety: if schedule registration fails midway, rolls back repository state and scheduler job creation to stay consistent.
- Execution boundary:
tickresolves a schedule by ID and executes it through the executor with populated metadata. - Schedule events: emits manager-level
ScheduleAdd/ScheduleRemoveevents and supports subscriptions for schedule lifecycle reactions.
In practice, this makes it the boundary where schedule persistence, job lifecycle, execution, and manager events are coordinated.
Overriding
Creation
Create a custom schedule manager by either:
- Extending
DefaultScheduleManager(@base's implementation, recommended for less work). - Implementing
ScheduleManager(@base's interface).
import { } from '@nyx-discord/djs';
class extends {
public () {
return 'I work!' as ;
}
}Registration
Then you can pass it to your bot:
import { , type } from '@nyx-discord/djs';
const = .((: ) => ({
// ... other options
: new (/** ... */),
}));
const = .();
const result = .();The class is able to infer the type of your custom manager, so accessing any custom method or property will work without errors.
If you ever want to use this custom bot type with your injected manager somewhere else, you can do so via the generic:
import type { , } from '@nyx-discord/djs';
type = < & { : }>;
function (: ) {
const = .();
const result = .();}For readability purposes, we recommend storing the type with the generic in a separate type, like in the example.
Edit on GitHub
Last updated on
