aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-20 13:34:57 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-20 13:34:57 -0300
commitb8f65dd00187023edf33ea462b92f50b01e32b00 (patch)
tree01328caef1d6385670fd5e5370f4d2ca00d5c17c /src
parent1467bfae9c7971ba04429a1741d6d8549f5acbe2 (diff)
downloadqueue-api-b8f65dd00187023edf33ea462b92f50b01e32b00.tar.gz
queue-api-b8f65dd00187023edf33ea462b92f50b01e32b00.tar.bz2
queue-api-b8f65dd00187023edf33ea462b92f50b01e32b00.zip
Improve code idiomaticness (thanks to kibit)
Diffstat (limited to 'src')
-rw-r--r--src/clj/queue_api/db/core.clj19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index 3210a6c..00af5cb 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -36,15 +36,15 @@
(defn agent-jobs
"Get a job that has a agent bounded with given `id` and a status of `s`"
[id s]
- (->> (d/q '[:find ?jid
+ (map #(d/entity @conn [:job/id (first %)])
+ (d/q '[:find ?jid
:in $ ?id ?s
:where
[?e :agent/id ?id]
[?x :job/id ?jid]
[?x :job/status ?s]
[?x :job/agent ?e]]
- @conn id s)
- (map #(d/entity @conn [:job/id (first %)]))))
+ @conn id s)))
(defn q-job
"Query jobs and sort them by date
@@ -96,10 +96,10 @@
if nothing was found query for not urgent ones."
[s]
(let [ju (q-job true :unassigned s)]
- (if (not (empty? ju))
+ (if (seq ju)
(first ju)
(let [jn (q-job false :unassigned s)]
- (if (not (empty? jn))
+ (if (seq jn)
(first jn))))))
(defn request-job
@@ -108,7 +108,7 @@
(let [a (d/entity @conn [:agent/id id])]
(if (not (nil? a))
(let [p (q-skillset (:agent/primary-skillset a))]
- (if (not (nil? p))
+ (if-not (nil? p)
p
(q-skillset (:agent/secondary-skillset a)))))))
@@ -139,17 +139,14 @@
"Change status of a job `j` to :processing
and bind it to an agent `a`"
[^String a ^String j]
- (if (not (nil? j))
- (do
- (t-job j :processing a)
- (bind-agent a j))))
+ (when-not (nil? j) (t-job j :processing a) (bind-agent a j)))
(defn dequeue-job
"Dequeue a job to a agent `id`"
[^String id]
(let [a (d/entity @conn [:agent/id id])]
(if (not (nil? a))
- (let [jid (-> (request-job id) :job/id)]
+ (let [jid (:job/id (request-job id))]
(end-job a)
(start-job id jid)
jid)))) \ No newline at end of file