Skip to content

Commit

Permalink
Format all code
Browse files Browse the repository at this point in the history
- Add formatting check in CI
  • Loading branch information
olttwa committed Sep 23, 2024
1 parent cbf90ae commit b38b9da
Show file tree
Hide file tree
Showing 72 changed files with 667 additions and 668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
RABBITMQ_DEFAULT_PASS: top-gun
steps:
- uses: actions/checkout@v3
- name: Check formatting
run: clj -M:cljfmt check
- name: Run tests
run: clj -X:test
env:
Expand Down
2 changes: 2 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
:exec-fn test-runner/test-and-shutdown}
:repl {:extra-deps {vvvvalvalval/scope-capture {:mvn/version "0.3.2"}
org.clojure/tools.namespace {:mvn/version "1.3.0"}}}
:cljfmt {:deps {dev.weavejester/cljfmt {:mvn/version "0.12.0"}}
:main-opts ["-m" "cljfmt.main"]}
:redis-perf {:extra-paths ["perf"]
:exec-fn goose.redis.load/benchmark
:extra-deps {criterium/criterium {:mvn/version "0.4.6"}
Expand Down
4 changes: 2 additions & 2 deletions src/goose/api/batch.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns goose.api.batch
(:require
[goose.broker :as b]
[goose.client]))
[goose.broker :as b]
[goose.client]))

(defn status
"For given `:batch-id`, reports progress of a batch.
Expand Down
2 changes: 1 addition & 1 deletion src/goose/api/cron_jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
To update a cron entry, call [[goose.client/perform-every]] since it is idempotent.
- [API wiki](https://github.com/nilenso/goose/wiki/API)"
(:require
[goose.broker :as b]))
[goose.broker :as b]))

(defn size
"Returns count of Cron entries."
Expand Down
2 changes: 1 addition & 1 deletion src/goose/api/dead_jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- [API wiki](https://github.com/nilenso/goose/wiki/API)"
(:refer-clojure :exclude [pop])
(:require
[goose.broker :as b]))
[goose.broker :as b]))

(defn size
"Returns count of Dead Jobs."
Expand Down
2 changes: 1 addition & 1 deletion src/goose/api/enqueued_jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"API to manage enqueued jobs.
- [API wiki](https://github.com/nilenso/goose/wiki/API)"
(:require
[goose.broker :as b]))
[goose.broker :as b]))

(defn list-all-queues
"Lists all the queues."
Expand Down
2 changes: 1 addition & 1 deletion src/goose/api/scheduled_jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"API to manage scheduled jobs.
- [API wiki](https://github.com/nilenso/goose/wiki/API)"
(:require
[goose.broker :as b]))
[goose.broker :as b]))

(defn size
"Returns count of Scheduled Jobs."
Expand Down
6 changes: 3 additions & 3 deletions src/goose/batch.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns goose.batch
(:require
[goose.job :as job]
[goose.utils :as u]
[goose.job :as job]
[goose.utils :as u]

[clojure.tools.logging :as log]))
[clojure.tools.logging :as log]))

(defn construct-args
"A utility function to construct a collection of args for batch-jobs."
Expand Down
8 changes: 4 additions & 4 deletions src/goose/brokers/redis/api/batch.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns ^:no-doc goose.brokers.redis.api.batch
(:require
[goose.brokers.redis.api.enqueued-jobs :as enqueued-jobs]
[goose.brokers.redis.api.scheduled-jobs :as scheduled-jobs]
[goose.brokers.redis.batch :as batch]
[goose.brokers.redis.commands :as redis-cmds]))
[goose.brokers.redis.api.enqueued-jobs :as enqueued-jobs]
[goose.brokers.redis.api.scheduled-jobs :as scheduled-jobs]
[goose.brokers.redis.batch :as batch]
[goose.brokers.redis.commands :as redis-cmds]))

(defn status [redis-conn id]
(batch/get-batch redis-conn id))
Expand Down
8 changes: 4 additions & 4 deletions src/goose/brokers/redis/api/dead_jobs.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns ^:no-doc goose.brokers.redis.api.dead-jobs
(:refer-clojure :exclude [pop])
(:require
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]))
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]))

(defn size [redis-conn]
(redis-cmds/sorted-set-size redis-conn d/prefixed-dead-queue))
Expand Down Expand Up @@ -51,7 +51,7 @@

(defn delete-older-than [redis-conn epoch-ms]
(< 0 (redis-cmds/del-from-sorted-set-until
redis-conn d/prefixed-dead-queue epoch-ms)))
redis-conn d/prefixed-dead-queue epoch-ms)))

(defn purge [redis-conn]
(= 1 (redis-cmds/del-keys redis-conn d/prefixed-dead-queue)))
Expand Down
6 changes: 3 additions & 3 deletions src/goose/brokers/redis/api/enqueued_jobs.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns ^:no-doc goose.brokers.redis.api.enqueued-jobs
(:require
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]))
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]))

(defn list-all-queues
"Lists all the queues"
Expand Down
6 changes: 3 additions & 3 deletions src/goose/brokers/redis/api/scheduled_jobs.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns ^:no-doc goose.brokers.redis.api.scheduled-jobs
(:require
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]))
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]))

(defn size [redis-conn]
(redis-cmds/sorted-set-size redis-conn d/prefixed-schedule-queue))
Expand Down
86 changes: 43 additions & 43 deletions src/goose/brokers/redis/batch.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(ns ^:no-doc goose.brokers.redis.batch
(:require
[goose.batch :as batch]
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]
[goose.metrics :as m]
[goose.retry]
[goose.utils :as u]
[goose.batch :as batch]
[goose.brokers.redis.commands :as redis-cmds]
[goose.defaults :as d]
[goose.job :as job]
[goose.metrics :as m]
[goose.retry]
[goose.utils :as u]

[taoensso.carmine :as car]
[clojure.tools.logging :as log]))
[taoensso.carmine :as car]
[clojure.tools.logging :as log]))

(defn batch-keys [id]
{:batch-hash (d/prefix-batch id)
Expand All @@ -24,40 +24,40 @@
pruned-batch-state (dissoc batch :jobs)
job-ids (map :id jobs)]
(redis-cmds/atomic
redis-conn
(car/multi)
(car/hmset* batch-hash pruned-batch-state)
(apply car/sadd enqueued-set job-ids)
(doseq [job jobs]
(car/lpush (:ready-queue job) job)))))
redis-conn
(car/multi)
(car/hmset* batch-hash pruned-batch-state)
(apply car/sadd enqueued-set job-ids)
(doseq [job jobs]
(car/lpush (:ready-queue job) job)))))

;;; When fetching a hash from Redis, primitive data types
;;; like integer, boolean and keyword get converted to string.
;;; We restore data types to avoid any type-casting errors.
(defn- restore-data-types
[{:keys [linger-sec total status created-at] :as batch}]
(assoc batch
:linger-sec (Long/valueOf linger-sec)
:total (Long/valueOf total)
:status (keyword status)
:created-at (Long/valueOf created-at)))
:linger-sec (Long/valueOf linger-sec)
:total (Long/valueOf total)
:status (keyword status)
:created-at (Long/valueOf created-at)))

(defn get-batch
[redis-conn id]
(let [{:keys [batch-hash enqueued-set retrying-job-set success-set dead-set]} (batch-keys id)
[batch enqueued retrying success dead] (redis-cmds/wcar*
redis-conn
(car/parse-map (car/hgetall batch-hash) :keywordize)
(car/scard enqueued-set)
(car/scard retrying-job-set)
(car/scard success-set)
(car/scard dead-set))]
redis-conn
(car/parse-map (car/hgetall batch-hash) :keywordize)
(car/scard enqueued-set)
(car/scard retrying-job-set)
(car/scard success-set)
(car/scard dead-set))]
(when (not-empty batch)
(assoc (restore-data-types batch)
:enqueued enqueued
:retrying retrying
:success success
:dead dead))))
:enqueued enqueued
:retrying retrying
:success success
:dead dead))))

(defn- record-metrics
[{:keys [metrics-plugin]}
Expand All @@ -77,17 +77,17 @@
(let [{:keys [batch-hash success-set dead-set]} (batch-keys id)
callback (batch/new-callback-job batch id completion-status)]
(redis-cmds/atomic
redis-conn
(car/multi)
redis-conn
(car/multi)
;; Enqueue callback to front of queue.
(car/rpush ready-queue callback)
(car/rpush ready-queue callback)
;; Update batch status to reflect completion status.
(car/hset batch-hash :status completion-status)
(car/hset batch-hash :status completion-status)
;; Terminal job execution marks completion of a batch, NOT callback execution.
;; Clean-up batch after enqueuing callback.
(car/expire batch-hash linger-sec "NX")
(car/expire success-set linger-sec "NX")
(car/expire dead-set linger-sec "NX"))))
(car/expire batch-hash linger-sec "NX")
(car/expire success-set linger-sec "NX")
(car/expire dead-set linger-sec "NX"))))

(defn- mark-batch-completion
[{:keys [redis-conn] :as opts} job batch-id completion-status]
Expand Down Expand Up @@ -123,13 +123,13 @@
[redis-conn src dst job-id batch-keys status]
(let [{:keys [enqueued-set retrying-set success-set dead-set]} batch-keys
[_ atomic-results] (redis-cmds/atomic
redis-conn
(car/multi)
(car/smove src dst job-id)
(car/scard enqueued-set)
(car/scard retrying-set)
(car/scard success-set)
(car/scard dead-set))
redis-conn
(car/multi)
(car/smove src dst job-id)
(car/scard enqueued-set)
(car/scard retrying-set)
(car/scard success-set)
(car/scard dead-set))
[_ enqueued retrying success dead] atomic-results]
(reset! status (batch/status-from-job-states enqueued retrying success dead))))

Expand Down
32 changes: 16 additions & 16 deletions src/goose/brokers/redis/broker.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(ns goose.brokers.redis.broker
(:require
[goose.broker :as b]
[goose.brokers.redis.api.batch :as batch-api]
[goose.brokers.redis.api.dead-jobs :as dead-jobs]
[goose.brokers.redis.api.enqueued-jobs :as enqueued-jobs]
[goose.brokers.redis.api.scheduled-jobs :as scheduled-jobs]
[goose.brokers.redis.batch :as batch]
[goose.brokers.redis.commands :as redis-cmds]
[goose.brokers.redis.connection :as redis-connection]
[goose.brokers.redis.cron :as cron]
[goose.brokers.redis.scheduler :as redis-scheduler]
[goose.brokers.redis.worker :as redis-worker]
[goose.brokers.redis.console :as redis-console]
[goose.defaults :as d]
[goose.specs :as specs]))
[goose.broker :as b]
[goose.brokers.redis.api.batch :as batch-api]
[goose.brokers.redis.api.dead-jobs :as dead-jobs]
[goose.brokers.redis.api.enqueued-jobs :as enqueued-jobs]
[goose.brokers.redis.api.scheduled-jobs :as scheduled-jobs]
[goose.brokers.redis.batch :as batch]
[goose.brokers.redis.commands :as redis-cmds]
[goose.brokers.redis.connection :as redis-connection]
[goose.brokers.redis.cron :as cron]
[goose.brokers.redis.scheduler :as redis-scheduler]
[goose.brokers.redis.worker :as redis-worker]
[goose.brokers.redis.console :as redis-console]
[goose.defaults :as d]
[goose.specs :as specs]))

(defrecord Redis [redis-conn opts]
b/Broker
Expand Down Expand Up @@ -97,7 +97,7 @@
(batch-api/status (:redis-conn this) id))
(batch-delete [this id]
(batch-api/delete (:redis-conn this) id))

;; console API
(handler [this req]
(redis-console/handler this req)))
Expand Down Expand Up @@ -154,7 +154,7 @@
([conn-opts scheduler-polling-interval-sec]
(specs/assert-redis-consumer conn-opts scheduler-polling-interval-sec)
(let [opts (assoc conn-opts
:scheduler-polling-interval-sec scheduler-polling-interval-sec)]
:scheduler-polling-interval-sec scheduler-polling-interval-sec)]
;; Connection to Redis is opened/closed from start/stop functions of worker.
;; This was done to avoid duplication of code & mis-match in `threads` config.
(->Redis nil opts))))
Loading

0 comments on commit b38b9da

Please sign in to comment.