aboutsummaryrefslogtreecommitdiff
path: root/src/clj/queue_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/clj/queue_api')
-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"]