Scheduled Task Does Not Remove on Fail
I have a listener that creates a new task when a member joins voice if a condition is met, and removes it when they leave. The task itself executes perfectly fine, however, if it errors it will not remove the task. I do handle users leaving the channel in the voice state code, however if the bot has downtime and the member leaves during it, it'll have to error out.
I'm not entirely sure if this is intended behavior and I'm just understand the use-case wrong, I checked documentation for bull and it seems like it should remove on error, but it does not.
Solution:Jump to solution
Well the plugin is just a fairly tiny wrapper around the bullmq library and that is a bullmq option. So it only counts when it fails on the bullmq side. This could be when it fails to send from redis to the client for example.
7 Replies
I'm honestly a bit lost in the code. Where exactly is the error thrown where you would expect the job to be removed?
In
IncrementVoiceActivity.ts
, just wherever it throws a new error
for example: if (!list.includes(payload.memberId)) throw new Error('Member no longer connected.');
, i'd expect it to remove after something like thishm no that wont happen. It'll get send to event
ScheduledTaskEvents.ScheduledTaskError
but nothing else. Sapphire and its official plugins will never do such cleanup actions for you automatically and expects you to implement them yourself. This is a design choice.Ah alright, I assumed that adding
removeOnFail
to custom job options would make bull handle it automatically since that's how it's stated in their docs (unless I misunderstood them), but I can write something to handle it, was just confused on why it wasn't working 😅Ah
Solution
Well the plugin is just a fairly tiny wrapper around the bullmq library and that is a bullmq option. So it only counts when it fails on the bullmq side. This could be when it fails to send from redis to the client for example.
Alrighty, thanks for the clearing things up for me, appreciate it