From a17538127a37d480cd6efd6d3c44faab4a0a7f76 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sun, 18 Feb 2018 02:21:05 -0300 Subject: Adds some functions to manage the queue --- src/clj/queue_api/db/core.clj | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj index dc04187..765ce39 100644 --- a/src/clj/queue_api/db/core.clj +++ b/src/clj/queue_api/db/core.clj @@ -6,7 +6,7 @@ (def schema {:agent/id {:db/unique :db.unique/identity} :agent/primary-skillset {:db/cardinality :db.cardinality/many} :agent/secondary-skillset {:db/cardinality :db.cardinality/many} - :agent/job {:db.valueType :db.type/ref} + :agent/job {:db.valueType :db.type/ref} :job/id {:db/unique :db.unique/identity} :job/agent {:db.valueType :db.type/ref}}) @@ -23,16 +23,42 @@ (d/transact! queue-api.db.core/conn [{:job/id id :job/type type :job/urgent urgent - :job/date (time/now) + :job/date (time/now) :job/status :unassigned}])) (defn request-job [id] {:job_request {:job_id "Dummy" :agent_id "Dummy"}}) + (defn get-agent [id] [{:type "Dummy" :jobs -2}]) +(defn agent-jobs [id s] + (let [q (d/q '[:find ?jid + :in $ ?id ?s + :where + [?e :agent/id ?id] + [?x :job/id ?jid] + [?x :job/status ?s] + [?x :job/agent ?e]] + @conn id s)] + (map #(d/entity @conn [:job/id (first %)]) q))) + + +(defn q-job [u s t] + (let [q (->> (d/q '[:find ?d ?id + :in $ ?u ?s ?t + :where + [?e :job/date ?d] + [?e :job/id ?id] + [?e :job/urgent ?u] + [?e :job/status ?s] + [?e :job/type ?t]] + @conn u s t) + (sort-by first))] + (map #(d/entity @conn [:job/id (last %)]) q))) + (defn q-status [s] (d/q '[:find ?id :in $ ?status :where -- cgit v1.2.3