From 501308ea04a0fd8cee325f210ae994995f192edc Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Thu, 8 Mar 2018 23:23:21 -0300 Subject: Better(?) naming, and removes warning --- src/clj/queue_api/db/core.clj | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/clj') diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj index 0ad9b81..72785ef 100644 --- a/src/clj/queue_api/db/core.clj +++ b/src/clj/queue_api/db/core.clj @@ -2,7 +2,8 @@ (:require [datascript.core :as d] [mount.core :as mount] [clj-time.core :as time]) - (:import (clojure.lang Keyword))) + (:import (clojure.lang Keyword)) + (:refer-clojure :exclude [agent])) (def schema {:agent/id {:db/unique :db.unique/identity} :agent/primary-skillset {:db/cardinality :db.cardinality/many} @@ -46,7 +47,7 @@ [?x :job/agent ?e]] @conn id s))) -(defn q-job +(defn query-job "Query jobs and sort them by date `u`: urgent flag `s`: status of the job @@ -65,7 +66,7 @@ (sort-by first) (map #(d/entity @conn [:job/id (last %)])))) -(defn q-status +(defn query-status "Query job by status `s`" [s] (d/q '[:find ?id :in $ ?status @@ -87,18 +88,18 @@ (defn sum-queue "List all jobs aggregated by status" [] - {:completed (map first (q-status :completed)) - :processing (map first (q-status :processing)) - :unassigned (map first (q-status :unassigned))}) + {:completed (map first (query-status :completed)) + :processing (map first (query-status :processing)) + :unassigned (map first (query-status :unassigned))}) -(defn q-skillset +(defn query-skillset "First query for :unassigned jobs with skillset of `s` and flagged as urgent if nothing was found query for not urgent ones." [s] - (let [ju (q-job true :unassigned s)] + (let [ju (query-job true :unassigned s)] (if (seq ju) (first ju) - (let [jn (q-job false :unassigned s)] + (let [jn (query-job false :unassigned s)] (if (seq jn) (first jn)))))) @@ -117,12 +118,12 @@ [^String id] (let [a (d/entity @conn [:agent/id id])] (if (not (nil? a)) - (let [p (q-skillset (:agent/primary-skillset a))] + (let [p (query-skillset (:agent/primary-skillset a))] (if-not (nil? p) p - (q-skillset (:agent/secondary-skillset a))))))) + (query-skillset (:agent/secondary-skillset a))))))) -(defn t-job +(defn transact-job "Transact status `s` and agent `a` of a job `id`" ([^String id ^Keyword s] (d/transact! conn [{:job/id id @@ -143,13 +144,13 @@ [^String a] (let [jid (-> a :agent/job :job/id)] (if (not (nil? jid)) - (t-job jid :completed)))) + (transact-job jid :completed)))) (defn start-job "Change status of a job `j` to :processing and bind it to an agent `a`" [^String a ^String j] - (when-not (nil? j) (t-job j :processing a) (bind-agent a j))) + (when-not (nil? j) (transact-job j :processing a) (bind-agent a j))) (defn dequeue-job "Dequeue a job to a agent `id`" -- cgit v1.2.3