Created
May 17, 2018 22:09
-
-
Save lucywyman/4c1e893844db1b7dd0e5e0de1467a455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-plan-job-status | |
"Returns a list of states for a plan job" | |
[db plan-job-id] | |
{:pre [(some? db)]} | |
(sql/with-db-transaction [conn db] | |
(let [query {:select [:jobs.id | |
[(h/call :json_agg | |
(h/call :json_build_object | |
"state" :job_statuses.state | |
"enter_time" :job_statuses.enter_time | |
"exit_time" :job_statuses.exit_time)) :result]] | |
:from [:job_statuses :jobs] | |
:inner-join [:jobs [:= :job_statuses.job_id :jobs.id]] | |
:where [:= :jobs.plan_job_id plan-job-id] | |
:group-by [:jobs.id]} | |
result (sql/query conn (h/format query)) | |
; result is ({:id 1, :result #object[org.postgresql.util.PGobject 0x2fb34336 [{"state" : "ready", "enter_time" : "2018-05-17T14:49:22.356292", "exit_time" : "2018-05-17T14:49:22.366159"}]}) | |
formatted (map (fn [m] {(:id m) (keywordize-keys | |
(parse-jsonb-object | |
(:result m)))}) result) | |
; Map returns a collection of element which is our hash of statuses, | |
; but we just need the hash of statuses | |
statuses (first formatted)] | |
(if (nil? statuses) {} statuses)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prints