diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-18 02:21:05 -0300 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-18 02:21:05 -0300 |
commit | a17538127a37d480cd6efd6d3c44faab4a0a7f76 (patch) | |
tree | 217f917029e079fa0240b3a7df60f91f61bc6d5c /src/clj | |
parent | 65357035e6fee399993da80d6d26aa833979cfcf (diff) | |
download | queue-api-a17538127a37d480cd6efd6d3c44faab4a0a7f76.tar.gz queue-api-a17538127a37d480cd6efd6d3c44faab4a0a7f76.tar.bz2 queue-api-a17538127a37d480cd6efd6d3c44faab4a0a7f76.zip |
Adds some functions to manage the queue
Diffstat (limited to 'src/clj')
-rw-r--r-- | src/clj/queue_api/db/core.clj | 30 |
1 files changed, 28 insertions, 2 deletions
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 |