The ScheduledTaskJob
interface has been removed in favor of defining types on ScheduledTasks
.
You can define a payload type for a task by using module augmentation on ScheduledTasks
. If the value of the entry is set to never
or undefined
in the interface, then there is no payload required for the task. If the type union contains an undefined
, then the payload will be optional. Otherise, it will enforce the provided type for that task. Below are some examples.
declare module '@sapphire/plugin-scheduled-tasks' {
interface ScheduledTasks {
[ExampleTasks.One]: { data: string } | null;
[ExampleTasks.Two]: never;
[ExampleTasks.Three]: boolean | undefined;
}
}
/** ExampleTasks.One */
// Good
await container.tasks.create({ name: ExampleTasks.One, payload: { data: 'value' } });
await container.tasks.create({ name: ExampleTasks.One, payload: null });
// Type error
await container.tasks.create({ name: ExampleTasks.One, payload: { data: true } });
await container.tasks.create({ name: ExampleTasks.One, payload: false });
/** ExampleTasks.Two */
// Good
await container.tasks.create(ExampleTasks.Two);
await container.tasks.create({ name: ExampleTasks.Two });
// Type error
await container.tasks.create({ name: ExampleTasks.Two, payload: null });
/** ExampleTasks.Three */
// Good
await container.tasks.create(ExampleTasks.Three);
await container.tasks.create({ name: ExampleTasks.Three });
await container.tasks.create({ name: ExampleTasks.Three, payload: true });
Due to the removal of ScheduledTaskJob
, the BullClient
will now be typed as unknown
since the Job types in the Queue can not really be known. So you will need to do validation when interacting directly with the client.
The included error listeners are now enabled by default. If you want them to be disabled, just set loadScheduledTaskErrorListeners
to false in the SapphireClient
options.
The internal BullMQ client does not actually throw any errors, it just emits them from the client. As such, those error events will now be sent to the corresponding error listener registered by the plugin.
The error listeners previously only returned the name of the task when an error was emitted, but now the event will provide the associated Piece.
The BullMQ dependency is being updated to v5 from v3. If you depend on the internal BullMQ client in any way, check out their releases for breaking changes.
The tasks
property for options relating to this plugin are now required. They were previously optional which was an oversight, as a connection string is always needed.