Task was not found | plugin-scheduled-tasks

👋🏿 I'm getting "[ScheduledTaskPlugin] There was no task found for "task_name"" error for all my scheduled tasks. Sometimes they run successfully but mostly they giving me this error. There is the code of how i'm declaring task:
import { ApplyOptions } from "@sapphire/decorators"
import { ScheduledTask } from "@sapphire/plugin-scheduled-tasks"
import { Time } from "@sapphire/time-utilities"

@ApplyOptions<ScheduledTask.Options>({ interval: Time.Minute, name: "violation" })
export class ViolationCheckTask extends ScheduledTask {
public async run() {
this.container.utilities.violation.check()
}
}
import { ApplyOptions } from "@sapphire/decorators"
import { ScheduledTask } from "@sapphire/plugin-scheduled-tasks"
import { Time } from "@sapphire/time-utilities"

@ApplyOptions<ScheduledTask.Options>({ interval: Time.Minute, name: "violation" })
export class ViolationCheckTask extends ScheduledTask {
public async run() {
this.container.utilities.violation.check()
}
}
And this is my configuration for "tasks"
tasks: {
bull: {
defaultJobOptions: {
removeOnComplete: true,
},
connection: {
host: "localhost",
port: 6379,
},
},
},
tasks: {
bull: {
defaultJobOptions: {
removeOnComplete: true,
},
connection: {
host: "localhost",
port: 6379,
},
},
},
Am I doing something wrong? :thinkPeepo:
Solution:
you should use a different logical redis database for every bot then
Jump to solution
17 Replies
Favna
Favna4mo ago
orderevent and violation are not the same name?
secre
secre4mo ago
no I just copied 1 error from 5, and random task just to show how I implement them
Favna
Favna4mo ago
Can you share your exact file/folder structure?
secre
secre4mo ago
yes sure
No description
secre
secre4mo ago
I also specify main in package.json
No description
secre
secre4mo ago
still can't figure out why this error happens. all tasks failing and sometimes randomly executes :NotLikeThis:
No description
Favna
Favna4mo ago
well I don't see tasks of those names in the folder...
secre
secre4mo ago
becase they are split among 5 bots. That's like logs when I start all of them in 1 command. on my prev screen you can lottery task, and there is eventban and order event check
No description
Solution
Favna
Favna4mo ago
you should use a different logical redis database for every bot then
Favna
Favna4mo ago
set db: in the connection settings int value from 0 to 16
secre
secre4mo ago
you think problem might be in this? because those tasks doesn't overlap with each other
Favna
Favna4mo ago
definitely. bullmq doesn't distinguish by some kind of process identifier so it just sends to the event emitter that a task triggers then sapphire is like "I can't find that task" and logs it
secre
secre4mo ago
ohhh, I think I gotchu. Like each bot thinks that he has that task, but it doesnt okay will check db value, might help 👍🏿 oh also, is there a way to run tasks only when bot login? because I execute some utilities in them and it's impossible to use utility before bot's login state
Favna
Favna4mo ago
uh dont call the plugin's register and write your own file very similar to this one except use the registerPostLoginHook hook where right now we have preGenericsInitialization and postInitialization (both the static methods and the code at the bottom). You can dump everything in registerPostLoginHook https://github.com/sapphiredev/plugins/blob/9fbf980e603022c3e1cd61a9ad742cd43a60e7fa/packages/scheduled-tasks/src/register.ts oh and then import it similar to how you import register now, of course
secre
secre4mo ago
I see. Will play with that tomorrow 👍🏿 Right now I just added a check if utility exists in utilities property - if not just return...
secre
secre4mo ago
nice, changing db to different values for each redis client worked out
No description
secre
secre4mo ago
tysm for help!