Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to Cancel a Future Scheduled Job #395

Closed
sesyilmaz opened this issue Oct 28, 2024 · 8 comments
Closed

Ability to Cancel a Future Scheduled Job #395

sesyilmaz opened this issue Oct 28, 2024 · 8 comments

Comments

@sesyilmaz
Copy link

Hello,

We are planning to use Solid Queue to schedule tasks for future execution. However, we have some use cases where we might need to cancel enqueued jobs before they run.

While we could include logic within the job itself to check business conditions and decide whether to proceed, this approach would still consume unnecessary resources. Therefore, we would prefer the ability to cancel jobs before they execute.

Is there any plan to implement this feature? If so, what timeline would you anticipate for it?

Thanks in advance !

@rosa
Copy link
Member

rosa commented Oct 29, 2024

Hey @sesyilmaz, thanks for writing this question! I'm not sure I understand very well how this feature would work 🤔 As I see it, would the idea be that when the job is due for execution, Solid Queue detects it shouldn't run, and discards it? How would you specify that in a way that Solid Queue can know? I think that whatever the condition, it'd be something that consumes the same resources as if you included it in the job 🤔 I think I might be misunderstanding how you have imagined this feature to work.

@sesyilmaz
Copy link
Author

Hello @rosa,

I apologize for the delayed response.

My question might not have been very clear. I wasn't looking for a way for Solid Queue to detect that it shouldn't run a job. Instead, I wanted to know how to delete, cancel or discard a job on demand if needed.

However, two of my colleagues had the chance to have a talk with you and mentioned this issue. Based on your suggestion, we will use the discard method you advised.

I will close this issue.

Thank you!

@rosa
Copy link
Member

rosa commented Dec 2, 2024

Ahhhh! I understand it now; thanks so much for clarifying and I'm sorry for the misunderstanding! Also, no worries at all about the delay 🙏

@janpeterka
Copy link

janpeterka commented Jan 22, 2025

The link to solution is not working, can you @sesyilmaz posts the used solution here please?

I'm probably looking into similar problem:
I have Tasks, which create Jobs to notify on due date.
However, when due date is changed, I want to "reschedule", or cancel the original job, and create new one with new due_datetime.

I think I really need this approach, as I cannot reliably and precisely decide on which job is correct one on execution.

@rosa
Copy link
Member

rosa commented Jan 22, 2025

@janpeterka, could you check, in the job, whether the due date is still valid? Or rely on a recurring task that checks all due dates for a given time and performs whatever action is required.

@janpeterka
Copy link

janpeterka commented Jan 22, 2025

I have thought about that.

We used recurring job in older version of app, but what if job is delayed, so the precise minute is not covered?

Same with checking valid time - it would have to be precise to minute, so there's a space for error.
EDIT: oh, if I can compare schedule time, not execution time, it should work! is it possible to access that?

However, I realized one way to manage it - o can add due_notified_at column,fill it on creating notification, and resetting it on changing due date.
So if canceling jobs is not possible/advisable, I will probably go this way.

Thank you so much for your help!

@rosa
Copy link
Member

rosa commented Jan 22, 2025

We used recurring job in older version of app, but what if job is delayed, so the precise minute is not covered?

Yeah, it depends on how often and with what margin you need to run the jobs, which would completely depend on what the notifications are for.

EDIT: oh, if I can compare schedule time, not execution time, it should work! is it possible to access that?

You can, this is accessible via ActiveJob, which I'd recommend using vs. depending on your specific job backend.

However, I realized one way to manage it - o can add due_notified_at column,fill it on creating notification, and resetting it on changing due date.
So if canceling jobs is not possible/advisable, I will probably go this way.

It is possible, yes, using SolidQueue::Job#discard method. That should work fine.

I personally like the solution where you don't need to worry about the underlying job system or about scheduled jobs, which is why I suggested other alternatives, but you can definitely use discard.

@janpeterka
Copy link

Amazing, thanks for your thorough help! I will try to compare to scheduled time then, I also like it better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants