coravel
coravel copied to clipboard
Allow cancel Invocable with payload on ConsumeQueueOnShutdown
Check if invocableWithParams is ICancellableTask, assign its token to give token source. Cancel it on ConsumeQueueOnShutdown
Thanks for this! I'm actually thinking about re-working some of the queuing API significantly to be able handle cases where, let's say, an invocable that can be queued with a payload and is cancellable and [other things]. This will be coupled with other features like multiple queues.
If you're still up to it, let's get these changes in. I do have ideas long term like I mentioned, but these changes here are good.
Did you also want to add a new method to IQueue
bool TryCancel(string uniqueIdentifier)
?
Would look something like (this is all off the top of my head - there might some methods that aren't exact! lol)
public bool TryCancel(string uniqueIdentifier)
{
if(this._tokens.TryGet("uniqueIdentifier", out var token))
{
if(!token.IsCancellationRequested)
{
token.Cancel();
return true;
}
}
return false;
// Note: the tokens that are cancelled with be cleaned whenever the queue runs. No need to clear them out.
}
Thanks for those reviews @jamesmh , I just add few commits. If you have freetime, please take a look for it :D