diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-03-08 23:23:21 -0300 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2018-03-08 23:23:21 -0300 |
commit | 501308ea04a0fd8cee325f210ae994995f192edc (patch) | |
tree | 9db51ec566147b28e2757220ce305485f2f0df17 | |
parent | de7cd8220c364dd816f4136a9d4c5a4d6618359d (diff) | |
download | queue-api-501308ea04a0fd8cee325f210ae994995f192edc.tar.gz queue-api-501308ea04a0fd8cee325f210ae994995f192edc.tar.bz2 queue-api-501308ea04a0fd8cee325f210ae994995f192edc.zip |
Better(?) naming, and removes warningmaster
-rw-r--r-- | src/clj/queue_api/db/core.clj | 29 | ||||
-rw-r--r-- | test/clj/queue_api/test/db/core_test.clj | 33 | ||||
-rw-r--r-- | test/clj/queue_api/test/handler.clj | 3 |
3 files changed, 34 insertions, 31 deletions
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`" diff --git a/test/clj/queue_api/test/db/core_test.clj b/test/clj/queue_api/test/db/core_test.clj index 4afa99d..2d4e511 100644 --- a/test/clj/queue_api/test/db/core_test.clj +++ b/test/clj/queue_api/test/db/core_test.clj @@ -4,7 +4,8 @@ [queue-api.db.core :refer :all] [datascript.core :as d] [clj-time.core :as time] - [mount.core :as mount])) + [mount.core :as mount]) + (:refer-clojure :exclude [agent])) (def base-schema "Scenario base for tests, it has most of combinations to simulate a real composition" @@ -122,7 +123,7 @@ tx-data (:tx-data tx)] (is (not (empty? tx-data)))))) -(deftest q-status-test +(deftest query-status-test (testing "Test query job by status" (are [left right] (= left right) @@ -131,12 +132,12 @@ ["f90e149e-fa51-4212-a6bf-8cf81c78d28c"] ["dfa7744f-8d61-4d37-885f-dbef2d4df13b"] ["c471f9e0-fbbd-461d-adb0-7466c2d9830f"] - ["6e90db58-7a6d-46e2-a02a-e33dc82e6e33"]} (q-status :unassigned) + ["6e90db58-7a6d-46e2-a02a-e33dc82e6e33"]} (query-status :unassigned) #{["1e0d939d-494b-48d2-9247-b5ae207a519a"] ["aa327540-4e24-47f4-9e9c-81cdd5195934"] - ["3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"]} (q-status :completed) - #{["b201d085-91b5-4a13-9a74-7861426e9996"]} (q-status :processing) - #{} (q-status :nil)))) + ["3cdc52fe-b538-40a6-a9d7-92fa840c2c4b"]} (query-status :completed) + #{["b201d085-91b5-4a13-9a74-7861426e9996"]} (query-status :processing) + #{} (query-status :nil)))) (deftest sum-queue-test (testing "test get summary of the current state of the queue" @@ -152,20 +153,20 @@ "6e90db58-7a6d-46e2-a02a-e33dc82e6e33"]} (sum-queue))))) -(deftest q-job-test +(deftest query-job-test (testing "Test query job" (is (= [(job "96cf6f11-591d-4cde-9ab0-56e371acb6d2") (job "dfa7744f-8d61-4d37-885f-dbef2d4df13b")] - (q-job false :unassigned "rewards-question"))) + (query-job false :unassigned "rewards-question"))) (is (= [(job "b201d085-91b5-4a13-9a74-7861426e9996")] - (q-job true :processing "purchases-question"))) + (query-job true :processing "purchases-question"))) (is (= [(job "aa327540-4e24-47f4-9e9c-81cdd5195934")] - (q-job true :completed "bills-question"))) - (is (= [] (q-job false :completed "rewards-question"))) + (query-job true :completed "bills-question"))) + (is (= [] (query-job false :completed "rewards-question"))) (is (= [(job "1e0d939d-494b-48d2-9247-b5ae207a519a")] - (q-job false :completed "rewards-question" "bills-question"))) + (query-job false :completed "rewards-question" "bills-question"))) (is (= [(job "1e0d939d-494b-48d2-9247-b5ae207a519a")] - (q-job false :completed ["rewards-question" "bills-question"]))))) + (query-job false :completed ["rewards-question" "bills-question"]))))) (deftest agent-jobs-test (testing "Test fetch relation agent job" @@ -191,12 +192,12 @@ (is (= "51ab0771-f1e4-4268-868f-9029a58f6612" (-> a :agent/job :job/id)))))) -(deftest t-job-test +(deftest transact-job-test (testing "Test transact job" - (let [_ (t-job "51ab0771-f1e4-4268-868f-9029a58f6612" :completed) + (let [_ (transact-job "51ab0771-f1e4-4268-868f-9029a58f6612" :completed) j (job "51ab0771-f1e4-4268-868f-9029a58f6612")] (is (= :completed (:job/status j)))) - (let [_ (t-job "51ab0771-f1e4-4268-868f-9029a58f6612" :completed "644be0ce-035d-48cb-867e-8e6de2714a8d") + (let [_ (transact-job "51ab0771-f1e4-4268-868f-9029a58f6612" :completed "644be0ce-035d-48cb-867e-8e6de2714a8d") j (job "51ab0771-f1e4-4268-868f-9029a58f6612")] (are [left right] (= left right) diff --git a/test/clj/queue_api/test/handler.clj b/test/clj/queue_api/test/handler.clj index 0af1b9f..26c71b0 100644 --- a/test/clj/queue_api/test/handler.clj +++ b/test/clj/queue_api/test/handler.clj @@ -5,7 +5,8 @@ [queue-api.db.core :refer :all] [mount.core :as mount] [queue-api.test.db.core-test :refer [base-schema]] - [datascript.core :as d])) + [datascript.core :as d]) + (:refer-clojure :exclude [agent])) (use-fixtures :once |