diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/queue_api/db/core.clj | 9 | ||||
-rw-r--r-- | src/clj/queue_api/routes/services.clj | 31 |
2 files changed, 22 insertions, 18 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj index adbda25..0ad9b81 100644 --- a/src/clj/queue_api/db/core.clj +++ b/src/clj/queue_api/db/core.clj @@ -156,7 +156,8 @@ [^String id] (let [a (d/entity @conn [:agent/id id])] (if-not (nil? a) - (let [jid (:job/id (fittest-job id))] - (end-job a) - (start-job id jid) - jid))))
\ No newline at end of file + (locking (Object.) + (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 9b8cc91..01937c1 100644 --- a/src/clj/queue_api/routes/services.clj +++ b/src/clj/queue_api/routes/services.clj @@ -8,9 +8,9 @@ (s/defschema new-agent - {:id s/Str - :name s/Str - :primary_skillset [s/Str] + {:id s/Str + :name s/Str + :primary_skillset [s/Str] :secondary_skillset [s/Str]}) (s/defschema new-job @@ -55,21 +55,24 @@ (if (nil? (db/agent (:id body))) (do (db/add-agent body) {:status 201}) - (bad-request {:message "Agent id already exists"})))} - :post {:summary "Get summary of an agent" - :parameters {:body-params agent-id} + (bad-request {:message "Agent id already exists"})))}})) + + (context "/agent/:id" [] + (resource + {:tags ["agent"] + :get {:summary "Get summary of an agent" + :parameters {:path-params {:id s/Str}} :responses {http-status/ok {:schema agent-sum :description "Fetched correctly"} http-status/not-found {:schema error-message :description "Agent not found"}} - :handler (fn [{body :body-params}] - (let [a (:agent_id body)] - (if-not (nil? (db/agent a)) - (let [jobs (db/sum-agent a)] - (ok (map (fn [x] - {:type (first x) - :jobs (last x)}) jobs))) - (not-found {:message "Agent does not exist"}))))}})) + :handler (fn [{{:keys [id]} :path-params}] + (if-not (nil? (db/agent id)) + (let [jobs (db/sum-agent id)] + (ok (map (fn [x] + {:type (first x) + :jobs (last x)}) jobs))) + (not-found {:message "Agent does not exist"})))}})) (context "/job" [] |