coravel icon indicating copy to clipboard operation
coravel copied to clipboard

Allow cancel Invocable with payload on ConsumeQueueOnShutdown

Open lengockyquang opened this issue 3 years ago • 3 comments

Check if invocableWithParams is ICancellableTask, assign its token to give token source. Cancel it on ConsumeQueueOnShutdown

lengockyquang avatar Jan 17 '22 09:01 lengockyquang

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.

jamesmh avatar Apr 23 '22 02:04 jamesmh

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.
        }

jamesmh avatar Apr 23 '22 03:04 jamesmh

Thanks for those reviews @jamesmh , I just add few commits. If you have freetime, please take a look for it :D

lengockyquang avatar May 15 '22 10:05 lengockyquang