Duplicate Tasks

Hello, I'm using @sapphire/plugin-scheduled-tasks on my bot and have configured a paterne to run the task every 10 seconds When the task reaches 0 seconds, the run() function is called 2 times Here's my code and a screen to help you understand:
const { ScheduledTask } = require('@sapphire/plugin-scheduled-tasks')

module.exports = class ExampleTask extends ScheduledTask {
constructor(context, options) {
super(context, {
...options,
name: 'example',
pattern: '*/10 * * * * *',
})
}

run() {
this.container.logger.info('Task ran!')
}
}
const { ScheduledTask } = require('@sapphire/plugin-scheduled-tasks')

module.exports = class ExampleTask extends ScheduledTask {
constructor(context, options) {
super(context, {
...options,
name: 'example',
pattern: '*/10 * * * * *',
})
}

run() {
this.container.logger.info('Task ran!')
}
}
No description
8 Replies
Favna
Favna•15mo ago
Do you have any other tasks with the same name? Otherwise check your Redis instance using RedisInsight: https://redis.com/redis-enterprise/redis-insight/ The plugin is only a tiny wrapper around the bullmq library (https://docs.bullmq.io) and this would be entirely on their side assuming the task doesn't actually get registered twice by Sapphire (doubtful because we use Maps which require unique keys)
Redis
RedisInsight | The Best Redis GUI
RedisInsight provides an intuitive and efficient graphical interface for Redis, allowing you to interact with your databases and manage your data.
Zaros
ZarosOP•15mo ago
I don't have any other tasks with the same name Maybe the problem is in bullmq
Favna
Favna•15mo ago
I'd say start by checking the redis instance and see what is there. If the task is there twice.. well then it's put there twice by bullmq.
Zaros
ZarosOP•15mo ago
I've never used RedisInsight, I'm not sure how to check that
Favna
Favna•15mo ago
it's pretty straightforward. Install it, and configure the same connection properties as you did for the plugin.
Zaros
ZarosOP•15mo ago
I cleared everything that was in RedisInsight and restarted my node instance and the problem is fixed 👌
Favna
Favna•15mo ago
good to hear then it was probably that bullmq put the task there twice, possibly due to reloads of the bot and slight differences somewhere in your code
Zaros
ZarosOP•15mo ago
I use nodemon, so yes, that's probably it
Want results from more Discord servers?
Add your server