taoensso / carmine

Redis client + message queue for Clojure
https://www.taoensso.com/carmine
Eclipse Public License 1.0
1.15k stars 130 forks source link

Stale mids (message ids) in the :done key of queue #225

Closed frankitox closed 4 years ago

frankitox commented 5 years ago

Hello, maybe this is something someone already found while using workers.

The thing is, when I use queues sometimes I end up with stale mids (message ids) in the :done set of the queue. If I try to get the message status it returns nil. I suspect this happens when the worker processing the queue item crashes, but I'm not sure.

For now I have a little function to clean the stale mids.

(defn clean-done [conn-opts & qnames]
  (when (seq qnames)
    (doseq [qname qnames]
      (let [{:keys [done]} (car-mq/queue-status server-connection qname)]
        (doseq [mid done]
          (when-not (car/wcar conn-opts (car-mq/message-status qname mid))
            (car/wcar conn-opts (car/srem (car/key :carmine :mq qname :done) mid))))))))

From the library design perspective, there's any case where it makes sense to keep a mid with nil status in the :done set of the queue?

ptaoussanis commented 4 years ago

Hi there!

Yes, it's possible for items to temporarily sit the done state until GC'd (until the item is next picked up again for processing). More info in the message-queue ns docstring, and here.

Hope that helps!