moclojer / clj-rq

RQ (Redis Queue) is a simple Clojure package for queueing jobs and processing them in the background with workers. It is backed by Redis and it is designed to have a low barrier to entry
MIT License
15 stars 1 forks source link

API refactor proposal #4

Closed J0sueTM closed 2 months ago

J0sueTM commented 2 months ago

I noticed that our API is inconsistent and hard to understand.

  1. Functions are named as nouns and do not indicate state changes.
(defn producer
  "Push a job to the queue"

I feel like this gets the end user confused while trying to understand that this is a function, and not a var.

(defn push!

Would be better.

  1. queue != pubsub

This is a problem that I saw in Carmine, which even affected us. I like the idea of having a producer/consumer that repeats what pub/sub does, but it would be nice to focus more on the wrapper part (push-r, push-l, etc.) and leave the issue of sending/receiving messages outside of it, but still support it for the queue.

For example, this function

(defn consumer-size
  "get size of the queue"
  [redis-client queue-name]
  (.llen @redis-client (pattern-name queue-name)))

is part of queue.clj, but since it is named as consumer (thus part of the producer/consumer implementation that mimics pub/sub using queues), it confuses the user, even though the final operation (.llen) is specifically a queue operation.

What I have in mind:

;; queue

(queue/push! :r)
(queue/pop! :l)
(queue/llen)
(queue/rrange)

;; pubsub

(pubsub/publish!)
(pubsub/archive!)
(pubsub/unarchive!)
(pubsub/subscribe!)

na queue teria mais, ja que eh um wrapper do jedis de qualquer forma