aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-18 21:00:55 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-18 21:00:55 -0300
commit9dd6aeb32d21ed8673bdd490341302fd7f37d2fc (patch)
tree8362688060eaea737f40ddf514648a22f8c2d4fe /src
parent48bd546122842012a65572fa436fe58cfd965ca7 (diff)
downloadqueue-api-9dd6aeb32d21ed8673bdd490341302fd7f37d2fc.tar.gz
queue-api-9dd6aeb32d21ed8673bdd490341302fd7f37d2fc.tar.bz2
queue-api-9dd6aeb32d21ed8673bdd490341302fd7f37d2fc.zip
Adds functions that were missing
Diffstat (limited to 'src')
-rw-r--r--src/clj/queue_api/db/core.clj36
-rw-r--r--src/clj/queue_api/routes/services.clj7
2 files changed, 38 insertions, 5 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index 40e6188..35a87fd 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -109,10 +109,40 @@
[id]
(let [a (d/entity @conn [:agent/id id])]
(if (not (nil? a))
- (let [p (q-skillset (:primary-skillset a))]
+ (let [p (q-skillset (:agent/primary-skillset a))]
(if (not (nil? p))
p
- (q-skillset (:secondary-skillset a)))))))
+ (q-skillset (:agent/secondary-skillset a)))))))
+
+(defn t-job
+ ([id s]
+ (d/transact! conn [{:job/id id
+ :job/status s}]))
+ ([id s a]
+ (d/transact! conn [{:job/id id
+ :job/status s
+ :job/agent [:agent/id a]}])))
+
+(defn t-agent [id j]
+ (d/transact! conn [{:agent/id id
+ :agent/job [:job/id j]}]))
+(defn end-job [a]
+ (let [jid (-> a :agent/job :job/id)]
+ (if (not (nil? jid))
+ (t-job jid :completed))))
+
+(defn t-agent-job-status
+ [a j]
+ (if (not (nil? j))
+ (do
+ (t-job j :processing a)
+ (t-agent a j)
+ {:job_request {:job_id j :agent_id a}})
+ {:job_request {:job_id nil :agent_id a}}))
(defn dequeue-job [id]
- ) \ No newline at end of file
+ (let [j (request-job id)
+ a (d/entity @conn [:agent/id id])]
+ (if (not (nil? a))
+ (do (end-job a)
+ (t-agent-job-status (-> a :agent/id) (-> j :job/id)))))) \ No newline at end of file
diff --git a/src/clj/queue_api/routes/services.clj b/src/clj/queue_api/routes/services.clj
index d432517..e8f03f9 100644
--- a/src/clj/queue_api/routes/services.clj
+++ b/src/clj/queue_api/routes/services.clj
@@ -38,10 +38,13 @@
:urgent urgent})
(ok))
(POST "/" []
- :return {:job_request {:job_id String :agent_id String}}
+ :return {:job_request {:job_id s/Any :agent_id String}}
:body-params [agent_id :- String]
:summary "Request a job to a given agent"
- (ok (db/dequeue-job agent_id))))
+ (let [j (db/dequeue-job agent_id)]
+ (if (nil? j)
+ (bad-request {:message "Agent does not exist"})
+ (ok j)))))
(context "/queue" []
:tags ["queue"]