-
Notifications
You must be signed in to change notification settings - Fork 100
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
Named tasks can not be recreated after they complete #164
Comments
The idea is to be able to execute certain tasks once a day / period. So we chose a task name like |
Now that you say it, I realize I completely overlooked https://github.com/vmihailenco/taskq#message-deduplication and how What are your thoughts on something like: task.WithArgs(ctx, "my input", 42).OnceUntilComplete() in order to trigger cleanup of Redis/LocalStorage dedupe cache on completion of the task |
That is possible, but I can't describe/understand what guarantees such logic provides... |
I think the confusion on my side is that currently setting a name really acts as though I called a The proposed Continuing with the spider example, imagine there is a website where people can request to have their site indexed. Sites are indexed in FIFO order. Users are free to request their site be re-indexed at any time, but to save memory/queue length I only want each requested site in the queue once (yes, this memory constraint is contrived - in my real use case taskq is being used on an IoT device that is actually memory constrained). So, if someone requests "www.google.com" to be indexed, and there is already a pending task for "www.google.com", the site would just return "your site will be indexed soon". If there was not a pending task for "www.google.com", a new task would be added to the end of the queue. The alternative to this is that I have to maintain a totally separate list of what is currently in the queue to ensure I don't add duplicates to the queue. Given the Redis and LRU maps that already exist in taskq, extending Happy to submit a PR for this, just want to make sure there is a chance you'll accept it before I do the work. |
I had left this comment in #106, but figured it was worth asking more directly...
RedisStorage holds these for 24hr and LocalStorage will hold them until 128,000 additional tasks have been queued.
An example:
spider_www_google_com
spider_www_google_com
- taskq rightfully returnstaskq.ErrDuplicate
spider_www_google_com
task completes successfully and isconsumer.Put
is called which callsconsumer.delete
, which callsQueue.Delete
... this callsRedis.XDel
on the ID for Redis andscheduler.Remove
for memqueuespider_www_google_com
- taskq returnstaskq.ErrDuplicate
I would expect step 4 to succeed, but it fails because
RedisStorage.Exists
callsSetNX
on the task's name whereas the call toXDel
is on the task's ID ... which leaves the name lock lingering for 24hr. Similarly,LocalStorage.Exists
puts the name in a LRU cache (of size 128,000) whereasscheduler.Remove
is a map based with the task's pointer as its key.The easy fix is to extend the
Storage
interface to have aDelete
method that can be called when a task is completed successfully... however, for Redis it is probably best to simply pass both the task's ID and name toXDel
to avoid needing a second round-trip to Redis and then leavingRedisStorage.Delete
to do nothing.Thoughts? Am I missing something here?
The text was updated successfully, but these errors were encountered: