aboutsummaryrefslogtreecommitdiff
path: root/src/clj/queue_api/db/core.clj
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-20 21:34:01 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-20 21:34:01 -0300
commitfd953613e3259c63f54d49e042e16e50d47dd8fa (patch)
treefcfbbc4286650fc51a28b2a075705f5a19b14049 /src/clj/queue_api/db/core.clj
parentc70778a52e1e654f89970aad21b60e1f939818dd (diff)
parentb8f65dd00187023edf33ea462b92f50b01e32b00 (diff)
downloadqueue-api-fd953613e3259c63f54d49e042e16e50d47dd8fa.tar.gz
queue-api-fd953613e3259c63f54d49e042e16e50d47dd8fa.tar.bz2
queue-api-fd953613e3259c63f54d49e042e16e50d47dd8fa.zip
Merge branch 'master' of https://gitlab.com/gabrielgio/queue-api
Diffstat (limited to 'src/clj/queue_api/db/core.clj')
-rw-r--r--src/clj/queue_api/db/core.clj39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index 0381e1e..00af5cb 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -36,18 +36,18 @@
(defn agent-jobs
"Get a job that has a agent bounded with given `id` and a status of `s`"
[id s]
- (let [q (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 %)]) q)))
+ (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)))
(defn q-job
- "Fetch job and sort by date
+ "Query jobs and sort them by date
`u`: urgent flag
`s`: status of the job
`ts`: types of the job"
@@ -66,7 +66,7 @@
(map #(d/entity @conn [:job/id (last %)]))))
(defn q-status
- "Query job filtering only by `s`"
+ "Query job by status `s`"
[s]
(d/q '[:find ?id :in $ ?status
:where
@@ -75,7 +75,7 @@
@conn s))
(defn sum-agent
- "Get how many jobs a agent (`id`) has performed aggregated by type"
+ "Get how many jobs a agent `id` has performed aggregated by type"
[id]
(let [jobs (agent-jobs id :completed)]
(reduce (fn [l r]
@@ -85,7 +85,7 @@
(conj l {t (inc (get l t))})))) {} jobs)))
(defn sum-queue
- "Count all job aggregated by type"
+ "Count all jobs aggregated by type"
[]
{:completed (map first (q-status :completed))
:processing (map first (q-status :processing))
@@ -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