diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-18 02:38:18 -0300 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-02-18 02:38:18 -0300 |
commit | 7f492fb132b44917f2293b8435924de4524d3053 (patch) | |
tree | c85bcfe8f00200a36c7e1677f0024ec0f71d9bb8 /src/clj/queue_api/db | |
parent | a17538127a37d480cd6efd6d3c44faab4a0a7f76 (diff) | |
download | queue-api-7f492fb132b44917f2293b8435924de4524d3053.tar.gz queue-api-7f492fb132b44917f2293b8435924de4524d3053.tar.bz2 queue-api-7f492fb132b44917f2293b8435924de4524d3053.zip |
Adds doc
Diffstat (limited to 'src/clj/queue_api/db')
-rw-r--r-- | src/clj/queue_api/db/core.clj | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj index 765ce39..63446d8 100644 --- a/src/clj/queue_api/db/core.clj +++ b/src/clj/queue_api/db/core.clj @@ -13,13 +13,17 @@ (mount/defstate conn :start (d/create-conn schema)) -(defn add-agent [{:keys [id name primary-skillset secondary-skillset]}] +(defn add-agent + "Add an agent into the database" + [{:keys [id name primary-skillset secondary-skillset]}] (d/transact! queue-api.db.core/conn [{:agent/id id :agent/name name :agent/primary-skillset primary-skillset :agent/secondary-skillset secondary-skillset}])) -(defn add-job [{:keys [id type urgent]}] +(defn add-job + "Add a job into the database" + [{:keys [id type urgent]}] (d/transact! queue-api.db.core/conn [{:job/id id :job/type type :job/urgent urgent @@ -29,12 +33,13 @@ (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] +(defn agent-jobs + "Get a job that has a agent bounded with given `id` and a status of `s`" + [id s] (let [q (d/q '[:find ?jid :in $ ?id ?s :where @@ -45,8 +50,12 @@ @conn id s)] (map #(d/entity @conn [:job/id (first %)]) q))) - -(defn q-job [u s t] +(defn q-job + "Fetch job and order by date + `u`: if it is flagged urgent + `s` status of the job + `t` type of the job" + [u s t] (let [q (->> (d/q '[:find ?d ?id :in $ ?u ?s ?t :where @@ -59,14 +68,18 @@ (sort-by first))] (map #(d/entity @conn [:job/id (last %)]) q))) -(defn q-status [s] +(defn q-status + "Query job filtering only by status" + [s] (d/q '[:find ?id :in $ ?status :where [?e :job/status ?status] [?e :job/id ?id]] @conn s)) -(defn sum-queue [] +(defn sum-queue + "Count all job aggregated by type" + [] {:completed (map #(first %) (q-status :completed)) :processing (map #(first %) (q-status :processing)) :unassigned (map #(first %) (q-status :unassigned))})
\ No newline at end of file |