generated from sapphiredev/sapphire-template
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scheduled-tasks): add error listeners (#499)
- Loading branch information
Showing
5 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Listener } from '@sapphire/framework'; | ||
import { ScheduledTaskEvents } from '../lib/types/ScheduledTaskEvents'; | ||
|
||
export class PluginListener extends Listener<typeof ScheduledTaskEvents.ScheduledTaskStrategyConnectError> { | ||
public constructor(context: Listener.Context) { | ||
super(context, { | ||
name: ScheduledTaskEvents.ScheduledTaskStrategyConnectError, | ||
event: ScheduledTaskEvents.ScheduledTaskStrategyConnectError | ||
}); | ||
} | ||
|
||
public override run(error: unknown) { | ||
this.container.logger.error(`[ScheduledTaskPlugin] Encountered an error when trying to connect to the Redis instance`, error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Listener } from '@sapphire/framework'; | ||
import { ScheduledTaskEvents } from '../lib/types/ScheduledTaskEvents'; | ||
|
||
export class PluginListener extends Listener<typeof ScheduledTaskEvents.ScheduledTaskError> { | ||
public constructor(context: Listener.Context) { | ||
super(context, { | ||
name: ScheduledTaskEvents.ScheduledTaskError, | ||
event: ScheduledTaskEvents.ScheduledTaskError | ||
}); | ||
} | ||
|
||
public override run(error: unknown, task: string) { | ||
let message = `Encountered error on scheduled task "${task}"`; | ||
|
||
const piece = this.container.stores.get('scheduled-tasks').get(task); | ||
if (piece) message = message.concat(` at path "${piece.location.full}"`); | ||
|
||
this.container.logger.error(message, error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Listener } from '@sapphire/framework'; | ||
import { ScheduledTaskEvents } from '../lib/types/ScheduledTaskEvents'; | ||
|
||
export class PluginListener extends Listener<typeof ScheduledTaskEvents.ScheduledTaskNotFound> { | ||
public constructor(context: Listener.Context) { | ||
super(context, { | ||
name: ScheduledTaskEvents.ScheduledTaskNotFound, | ||
event: ScheduledTaskEvents.ScheduledTaskNotFound | ||
}); | ||
} | ||
|
||
public override run(task: string) { | ||
this.container.logger.error(`[ScheduledTaskPlugin] There was no task found for "${task}"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters