aboutsummaryrefslogtreecommitdiff
path: root/src/clj/queue_api
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-21 22:41:20 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-21 22:41:20 -0300
commit0b8277f72cdc2ed2abeb566f30958bd8e0dc5167 (patch)
treeb4d26fa45fde855ccbc81ffd0af893c88aaba869 /src/clj/queue_api
parente05e7911084e3f23897d6d5b299d7f84494d618e (diff)
downloadqueue-api-0b8277f72cdc2ed2abeb566f30958bd8e0dc5167.tar.gz
queue-api-0b8277f72cdc2ed2abeb566f30958bd8e0dc5167.tar.bz2
queue-api-0b8277f72cdc2ed2abeb566f30958bd8e0dc5167.zip
Readme and validation
Diffstat (limited to 'src/clj/queue_api')
-rw-r--r--src/clj/queue_api/db/core.clj9
-rw-r--r--src/clj/queue_api/routes/services.clj12
2 files changed, 15 insertions, 6 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index c76f0fb..0482feb 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -102,7 +102,12 @@
(if (seq jn)
(first jn))))))
-(defn request-job
+(defn agent
+ "Get a agent by id"
+ [id]
+ (d/entity @conn [:agent/id id]))
+
+(defn fittest-job
"Get the fittest job for a agent `id`."
[^String id]
(let [a (d/entity @conn [:agent/id id])]
@@ -146,7 +151,7 @@
[^String id]
(let [a (d/entity @conn [:agent/id id])]
(if-not (nil? a)
- (let [jid (:job/id (request-job id))]
+ (let [jid (:job/id (fittest-job id))]
(end-job a)
(start-job id jid)
jid)))) \ 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 0b26281..766f831 100644
--- a/src/clj/queue_api/routes/services.clj
+++ b/src/clj/queue_api/routes/services.clj
@@ -44,10 +44,14 @@
:return {:job_request {:job_id s/Any :agent_id String}}
:body-params [agent_id :- String]
:summary "Request a job to a given agent"
- (let [j (db/dequeue-job agent_id)]
- (if (nil? j)
- (bad-request {:message "Agent does not exist"})
- (ok {:job_request {:job_id j :agent_id agent_id}}))))
+
+ (let [a (agent agent_id)]
+ (if (nil? a)
+ (not-found {:message "Agent does not exist"}))
+ (let [j (db/dequeue-job agent_id)]
+ (if (nil? j)
+ (not-found {:message "There is no job available for given agent"})
+ (ok {:job_request {:job_id j :agent_id agent_id}})))))
(GET "/" []
:return {:completed [String]