aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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