aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2018-02-21 13:05:43 -0300
committerGabriel A. Giovanini <mail@gabrielgio.me>2018-02-21 13:05:43 -0300
commit540f46fece32d683411143152272c7564fd9ce45 (patch)
tree5846ac2cf3fa9ee4e201bd34698797a1a211ee8b
parentc16068d87243159830b48a6e17034573f2539524 (diff)
downloadqueue-api-540f46fece32d683411143152272c7564fd9ce45.tar.gz
queue-api-540f46fece32d683411143152272c7564fd9ce45.tar.bz2
queue-api-540f46fece32d683411143152272c7564fd9ce45.zip
Readme and doc
-rw-r--r--README.md27
-rw-r--r--src/clj/queue_api/db/core.clj8
2 files changed, 23 insertions, 12 deletions
diff --git a/README.md b/README.md
index 1686dd4..1f0b199 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ then access [localhost:3000/swagger-ui](http://localhost:3000/swagger-ui/index.h
## Stack
-I chose [luminus](http://www.luminusweb.net/) for my stack as it made the initial setup way easier since it provide a wide range option of configuration for a lot of technologies.
+I chose [luminus](http://www.luminusweb.net/) for my stack as it makes the initial setup way easier since it provide a wide range option of configuration for a bunch of technologies.
To bootstrap the project I used `lein new luminus queue-api +swagger +service +kibit` plus datascrypt, which by default doesn't come with Luminus.
### +Swagger
@@ -31,7 +31,7 @@ I added because it gives some insight how to make you code more idiomatic.
I chose [datascript](https://github.com/tonsky/datascript) for its easy setup, after little to no effort I had it working.
Even though it was meant to run on browser it fit nicely in the project, and because it works pretty much like Datomic it has [powerful query system](https://docs.datomic.com/on-prem/query.html) and works seamlessly with clojure.
-Additionally it had an okay [non-documentation](https://github.com/tonsky/datascript/wiki/Getting-started) with some [samples](https://github.com/kristianmandrup/datascript-tutorial) and if I couldn't find for Datascript I would search for a Datomic seeing that query system of both are compatible.
+Additionally it had an okay [non-documentation](https://github.com/tonsky/datascript/wiki/Getting-started) with some [samples](https://github.com/kristianmandrup/datascript-tutorial) and if I couldn't find for Datascript I'd search for a Datomic seeing that query system of both are compatible.
## Solution
@@ -53,6 +53,8 @@ Project has two models:
* `:completed` it has been done with.
* `:job/agent` reference a job that is processing this job or had processed it. it is nil when `:unassigned`
* `:job/type` type of the job that it can perform
+ * `:job/date` date time when job has entered into the system.
+ * `:job/urgent` urgent flag that tell when a job has priority over other not urgent ones
Those models wrap up in schema:
@@ -71,20 +73,29 @@ After all luminus file there is actually two files that have the core logic of t
For `services.clj` it holds all code for endpoint definition and model validation and considering the exercise requirements we gonna need 5 endpoints:
* Endpoint to add agent is a`:put` at `/agent`
-* Endpoint to get how many jobs of each type this agent has performed is a `:post` at `/agent`. Note: usually since it is a method that doesn't modify anything I would have used `:get` and pass the agent id via path (`/agent/:id`) but one of the requirement is "*All endpoints should accept and return JSON content type payloads*" I worked with POST PUT.
+* Endpoint to get how many jobs of each type this agent has performed is a `:post` at `/agent`. Note: usually since it is a method that doesn't modify anything I'd have used `:get` and pass the agent id via path (`/agent/:id`) but one of the requirement is "*All endpoints should accept and return JSON content type payloads*" I worked with POST PUT.
* Endpoint to add a job is `:put` at `/job`
* Endpoint to request a job is `:post` at `/job`
* Endpoint to get current queue state is `:get` at `/job`
-For model detail access swagger-ui.
+For model and validation details access swagger-ui.
### db/core.clj
-To be continued...
-
-
+Core.clj holds all logic to interact with Datascrip therefore all the code to manage with the queue.
+The idea behind it is actually simpler than part 1 since Datascrip handle all data storing process.
+For example, to store jobs and agents I'd simply `transact!` the entire object and we good to go.
+```clojure
+ (d/transact! queue-api.db.core/conn
+ [{:job/id "319ce5e6-6ed6-4931-8e29-550052b02409"
+ :job/type "bills-request"
+ :job/urgent false
+ :job/date (time/now)
+ :job/status :unassigned}])
+```
+## Testing
+To be continued...
-
diff --git a/src/clj/queue_api/db/core.clj b/src/clj/queue_api/db/core.clj
index 00af5cb..c76f0fb 100644
--- a/src/clj/queue_api/db/core.clj
+++ b/src/clj/queue_api/db/core.clj
@@ -17,7 +17,7 @@
(defn add-agent
"Add an agent into the database"
[{:keys [id name primary-skillset secondary-skillset]}]
- (d/transact! queue-api.db.core/conn
+ (d/transact! conn
[{:agent/id id
:agent/name name
:agent/primary-skillset primary-skillset
@@ -26,7 +26,7 @@
(defn add-job
"Add a job into the database"
[{:keys [id type urgent]}]
- (d/transact! queue-api.db.core/conn
+ (d/transact! conn
[{:job/id id
:job/type type
:job/urgent urgent
@@ -85,7 +85,7 @@
(conj l {t (inc (get l t))})))) {} jobs)))
(defn sum-queue
- "Count all jobs aggregated by type"
+ "List all jobs aggregated by status"
[]
{:completed (map first (q-status :completed))
:processing (map first (q-status :processing))
@@ -145,7 +145,7 @@
"Dequeue a job to a agent `id`"
[^String id]
(let [a (d/entity @conn [:agent/id id])]
- (if (not (nil? a))
+ (if-not (nil? a)
(let [jid (:job/id (request-job id))]
(end-job a)
(start-job id jid)