-
Notifications
You must be signed in to change notification settings - Fork 11
API
akshat edited this page Sep 18, 2024
·
13 revisions
Goose exposes APIs to manage Async, Scheduled, Cron, Batch & Dead Jobs. The APIs are in the form of functions.
Note: APIs are meant to be used manually & under supervision. Some operations are not scalable and should not be used in an unsupervised fashion as part of an automated script.
- Find/Update/Delete APIs aren't feasible in RabbitMQ because you cannot traverse a queue
- We recommend RabbitMQ's Management Plugin for managing nodes, cluster & queues
API | Redis | RabbitMQ |
---|---|---|
Enqueued Jobs | ||
list-all-queues |
✅ | ❌ |
size |
✅ | ✅ |
find-by-id |
✅ | ❌ |
find-by-pattern |
✅ | ❌ |
prioritise-execution |
✅ | ❌ |
delete |
✅ | ❌ |
purge |
✅ | ✅ |
Scheduled Jobs | ||
size |
✅ | ❌ |
find-by-id |
✅ | ❌ |
find-by-pattern |
✅ | ❌ |
prioritise-execution |
✅ | ❌ |
delete |
✅ | ❌ |
purge |
✅ | ❌ |
Batch Jobs | ||
status |
✅ | ❌ |
delete |
✅ | ❌ |
Cron Jobs | ||
size |
✅ | ❌ |
find-by-name |
✅ | ❌ |
delete |
✅ | ❌ |
purge |
✅ | ❌ |
Dead Jobs | ||
size |
✅ | ✅ |
pop |
✅ | ✅ |
find-by-id |
✅ | ❌ |
find-by-pattern |
✅ | ❌ |
replay-job |
✅ | ❌ |
replay-n-jobs |
✅ | ✅ |
delete |
✅ | ❌ |
delete-older-than |
✅ | ❌ |
purge |
✅ | ✅ |
(ns goose-api
(:require
[goose.api.cron-jobs :as cron-jobs]
[goose.api.dead-jobs :as dead-jobs]
[goose.api.enqueued-jobs :as enqueued-jobs]
[goose.api.scheduled-jobs :as scheduled-jobs]
[goose.brokers.redis.broker :as redis]
[goose.brokers.rmq.broker :as rmq]))
;;; Both Producer/Consumer satisfy broker protocol.
;;; However, only Producer initializes the broker.
;;; Consumer simply stores broker config for the worker.
;;; Hence, provide a Producer, not a Consumer to API functions.
(def redis-producer (redis/new-producer redis/default-opts))
(def rmq-producer (rmq/new-producer rmq/default-opts))
Enqueued Jobs
(enqueued-jobs/list-all-queues redis-producer)
;=> ("queue-1" "queue-2")
(enqueued-jobs/size redis-producer "queue-1")
;=> 9
; Find 5 jobs of function "my-fn"
(let [pattern-match? (fn [job] (= (:execute-fn-sym job) 'my-app/my-fn))
limit 5]
(enqueued-jobs/find-by-pattern redis-producer pattern-match? 1))
;=> ({...} Sequence of Jobs {...})
(let [async-job (enqueued-jobs/find-by-id redis-producer "queue-2" "092b5257-6a18-4048-b601-a88f16a13f87")]
(enqueued-jobs/prioritise-execution redis-producer async-job))
Scheduled Jobs
(let [scheduled-job (scheduled-jobs/find-by-id redis-producer "6f606a70-667d-4401-a171-845e0c971b7e")]
(scheduled-jobs/prioritise-execution redis-producer scheduled-job))
Batch Jobs
(let [batch-id "f0e2dbd8-6390-4c09-9e61-fcbca8cc1c03"]
(batch-jobs/status redis-producer batch-id)
(batch-jobs/delete redis-producer batch-id))
Cron Jobs
(cron-jobs/find-by-name redis-producer "my-cron-job")
;=> {... map of cron entry ...}
;; Cron Jobs can be updated by re-registering a cron-entry using `goose.client/perform-every`
(cron-jobs/delete redis-producer "my-cron-job")
;=> true
Dead Jobs
(dead-jobs/pop redis-producer)
;=> {... map of job ...}
(let [dead-job (dead-jobs/find-by-id redis-producer "946f9d97-b276-4a65-844f-662050d71f32")]
(dead-jobs/replay-job redis-producer dead-job))
(dead-jobs/replay-n-jobs redis-producer 20)
;=> 20
; NOTE: Epoch is in milliseconds
(dead-jobs/delete-older-than redis-producer 1659090656000)
(dead-jobs/purge redis-producer)
;=> true
(enqueued-jobs/size rmq-producer "queue-1")
;=> 9
(dead-jobs/pop rmq-producer)
;=> {... map of job ...}
(dead-jobs/replay-n-jobs rmq-producer 20)
;=> 20
(dead-jobs/purge rmq-producer)
;=> true
Previous: Middlewares Next: Specs
Home | Getting Started | RabbitMQ | Redis | Error Handling | Monitoring | Production Readiness | Troubleshooting
Need help? Open an issue or ping us on #goose @Clojurians slack.