aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clj/queue_api/db/core.clj36
-rw-r--r--src/clj/queue_api/routes/services.clj7
-rw-r--r--test/clj/queue_api/test/db/core_test.clj11
-rw-r--r--test/clj/queue_api/test/handler.clj4
4 files changed, 47 insertions, 11 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"]
diff --git a/test/clj/queue_api/test/db/core_test.clj b/test/clj/queue_api/test/db/core_test.clj
index c1ecc6d..a624319 100644
--- a/test/clj/queue_api/test/db/core_test.clj
+++ b/test/clj/queue_api/test/db/core_test.clj
@@ -42,8 +42,8 @@
;;Agent that will be linked to jobs
{:agent/id "644be0ce-035d-48cb-867e-8e6de2714a8d"
:agent/name "Dummy Derp"
- :primary-skillset ["rewards-question" "bills-question"]
- :secondary-skillset []}
+ :agent/primary-skillset ["rewards-question" "bills-question"]
+ :agent/secondary-skillset []}
;;Change job status to :completed and link agent
{:job/id "1e0d939d-494b-48d2-9247-b5ae207a519a"
:job/status :completed
@@ -138,4 +138,9 @@
(testing "Test sum-agent"
(is (= [{:type "bills-question", :jobs 2} {:type "purchases-question", :jobs 1}]
(sum-agent "644be0ce-035d-48cb-867e-8e6de2714a8d")))
- (is (= [] (sum-agent "00000000-0000-0000-0000-000000000000"))))) \ No newline at end of file
+ (is (= [] (sum-agent "00000000-0000-0000-0000-000000000000")))))
+
+(deftest request-job-test
+ (testing "test query for skillset"
+ (is (= (d/entity @conn [:job/id "96cf6f11-591d-4cde-9ab0-56e371acb6d2"])
+ (request-job "644be0ce-035d-48cb-867e-8e6de2714a8d"))))) \ No newline at end of file
diff --git a/test/clj/queue_api/test/handler.clj b/test/clj/queue_api/test/handler.clj
index aa0dfa1..3473ce8 100644
--- a/test/clj/queue_api/test/handler.clj
+++ b/test/clj/queue_api/test/handler.clj
@@ -38,15 +38,13 @@
(let [response (-> (request :post "/job")
(json-body {:agent_id "8ab86c18-3fae-4804-bfd9-c3d6e8f66260"})
app)]
- (is (= 200 (:status response))))))
+ (is (= 400 (:status response))))))
(deftest queue-test
(testing "Queue route"
(let [response (app (request :get "/queue"))]
(is (= 200 (:status response))))))
-(deftest queue "/queue")
-
(deftest invalid-test
(testing "not-found route"
(let [response (app (request :get "/invalid"))]