Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src-cljs/spankins/app.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns spankins.app
;; (:require-macros [jayq.macros :refer [ready]])
;; (:require [spankins.dashboard :as dash :refer [new-async-app]])
)

(defn main [& args]
"Application driver attaches event handlers to elements and starts the application going"
;;(dash/new-async-app :body)
(.log js/console "client app starting"))
37 changes: 21 additions & 16 deletions src-cljs/spankins/dashboard.cljs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(comment
(ns spankins.dashboard
^{:author "Matthew Burns"
:doc "Spankins Dashboard"}
Expand All @@ -6,18 +7,20 @@
[shoreleave.remotes.macros :as srm :refer [rpc]])
(:require [cljs.core.async :refer [alts! chan >! >! put!]]
[cljs.core.async.impl.ioc-helpers ]
[cljs.core.match]
[jayq.core :as jq :refer [$ text val on prevent remove-class add-class remove empty html children append]]
[shoreleave.browser.storage.sessionstorage :refer [storage]]
[shoreleave.remote]))


(def session "client side data"(storage))
(assoc! session :user-id 1)
(assoc! session :doc-id 1)

(defn extract-dom
[event ui]
"Gather the necessary dom and admin data from a droppable event and ui element node"
(let [demo (jq/html ($ ".demo"))
(let [demo (jq/html (jq/$ ".demo"))
dom (nth (js->clj (.-item ui)) 0)
xpath (js/getXPath dom)]
{:page-html demo :snippet-html (.-innerHTML dom) :xpath xpath :dom dom
Expand All @@ -26,7 +29,7 @@
(defn data-from-event
"Extracts and transforms event data into a clojure map"
[event]
(-> event .-currentTarget $ .data (js->clj :keywordize-keys true)))
(-> event .-currentTarget jq/$ .data (js->clj :keywordize-keys true)))

(defn click-chan
"Creates and returns a channel that encapsulates and delivers the click data on a given element determined by the selector"
Expand All @@ -43,43 +46,44 @@
"Create an element channel that respondse to drop events on the element by extracting the
relevent data from the event and ui object and sending it as a message to be dispatched
via the created channel"
(let [elm ($ selector)
(let [elm (jq/$ selector)
element-channel (chan)
_ (.sortable elm (clj->js {:receive (fn [event ui]
(do (.log js/console (clj->js [event ui elm]))
(go (>! element-channel [msg-name (assoc (formatter event ui) :target elm)]))))}))]
element-channel))

(defn update
(defn update-dashboard
"Call the server side update api method notice the use of using the console for debugging by print
TODO: Replace console logging with something more tunable"
[drop-channel & {:keys [biz-id biz-cat analytics] :as tuple}]
(do (.log js/console "updating something")
(.log js/console tuple)
(srm/rpc
(comment (srm/rpc
(api/update tuple) [resp]
(put! drop-channel [:updated-dom (assoc resp :dom dom :target target)]))))
(put! drop-channel [:updated-dom (assoc resp :dom dom :target target)])))))

(defn save
"Call the server side persiting logic to save site edits"
[drop-channel & {:keys [page-html user-id doc-id] :as tuple}]
(do (.log js/console "saving site")
(.log js/console tuple)
(srm/rpc
(comment
(srm/rpc
(api/save {:page-html page-html :user-id user-id :doc-id doc-id}) [resp]
(put! drop-channel [:site-saved {:page-html resp}]))))
(put! drop-channel [:site-saved {:page-html resp}])))))

(defn render-workspace
[ch model elm host-element-class]
"Insert the job with the recent edits"
(do (if (:uuid model)
;; (add-class ($ ((.-getElementsByXPath js/xpath) js/document (:xpath model))) (str "uuid_" (:uuid model))))
;; (add-class (jq/$ ((.-getElementsByXPath js/xpath) js/document (:xpath model))) (str "uuid_" (:uuid model))))
(.log js/console (clj->js model)))
(.log js/console (js/getXPath (:target model)))
;; (add-class ($ (:dom model)) "demo")
;; (add-class ($ elm) host-element-class)
(jq/add-class ($ elm) "demo")
(jq/html ($ elm) (or (:tmp-page-html model) (:page-html model)))))
;; (add-class (jq/$ (:dom model)) "demo")
;; (add-class (jq/$ elm) host-element-class)
(jq/add-class (jq/$ elm) "demo")
(jq/html (jq/$ elm) (or (:tmp-page-html model) (:page-html model)))))

(defn new-async-app
"Create the event channels and start the loop that feeds the event data to the
Expand All @@ -92,9 +96,10 @@
channels [save-channel drop-channel]
dispatcher (fn [ch val]
(match [(nth val 0)]
[:save] (save drop-channel {:page-html (jq/html ($ ".demo")) :user-id (:user-id session) :doc-id (:landing-site-id session)})
[:drop] (update drop-channel (nth val 1))
[:update] (render-workspace ch (nth val 1) ($ ".demo") "")))]
[:save] (save drop-channel {:page-html (jq/html (jq/$ ".demo")) :user-id (:user-id session) :doc-id (:landing-site-id session)})
[:drop] (update-dashboard drop-channel (nth val 1))
[:update] (render-workspace ch (nth val 1) (jq/$ ".demo") "")))]
(go (while true
(let [[val ch] (alts! channels)]
(dispatcher ch val))))))
)
12 changes: 0 additions & 12 deletions src-cljs/spankins/driver.cljs

This file was deleted.

13 changes: 11 additions & 2 deletions src/spankins/model/job_run.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
[korma.db :refer [defdb mysql]]
[spankins.database :refer [job-run-dbh]]))

(declare job run job_run)
(declare job run job_run job_log run_log)

(defentity job
(pk :id)
(table :job)
(fields :id :name :type :created_on :last_ran :last_success :last_fail)
(fields :id :name :type :created_on :last_ran :last_success :last_fail)
(many-to-many job_run {:fk :job_id}))

(defentity job_log)
(defentity run_log)

(defentity run
(pk :id)
(table :run)
Expand All @@ -30,6 +33,12 @@
(table :url)
(fields :url))

(defn validate-job [name] false)
(defn validate-run [] false)
(defn log-job [job] [:1])
(defn log-run [run] [:2])


(comment
(defn insert-entity [db entity]
"Validate and attempt to store the entity in the database"
Expand Down
71 changes: 71 additions & 0 deletions src/spankins/model/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,74 @@ LEFT OUTER JOIN job_run jr ON jr.job_id = j.id
LEFT OUTER JOIN run r ON r.id = jr.run_id
WHERE f.filing_date > :begin_date AND f.filing_date < :end_date
GROUP BY j.name

-- select-run-results
SELECT * FROM build WHERE run_id = :run-id

-- select-run-errors
SELECT jl.job_id, j.run_id, j.fid, j.runtime, j.begin_date, j.end_date, jl.type, j.status, j.run_count, jl.description
FROM job j, job_log jl
WHERE j.job_id = jl.job_id and run_id = :run-id

-- insert_job_log
INSERT INTO job_log (job_id, run_id type, runtime, description, object)
VALUES (:job-id, :run-id, :type, :runtime, :description, :object)

-- insert-job
INSERT INTO job (job_id, run_id, runtime, begin_date, end_date,status)
VALUES(:job-id, :run-id, :runtime, :description, :object)

-- get-run-id
SELECT distinct(run_id)
FROM job
WHERE job_id = :job-id

-- update-job
UPDATE job
SET :attribute-name = :attribute-value
WHERE job_id = :job-id

-- increment_runcount
UPDATE job
SET run_count = (run_count +1)
WHERE job_id = :job-id

-- get-run
SELECT run_id, runtime, user
FROM run
WHERE run_id = :run-id

-- create-run
INSERT INTO run(run_id, runtime, user)
VALUES(0, NOW(), :user)

-- get-failed-jobs
SELECT j.job_id, r.run_id, j.begin_date, j.end_date, j.status, j.runcount, r.user
FROM run r, job j
WHERE r.run_id = j.run_id
AND status = 'failed'

-- get-successful-jobs
SELECT j.job_id, r.run_id, j.begin_date, j.end_date, j.status, j.runcount, r.user
FROM run r, job j
WHERE r.run_id = j.run_id
AND status = 'done'

-- get-pending-jobs
SELECT j.job_id, r.run_id, j.begin_date, j.end_date, j.status, j.runcount, r.user
FROM run r, job j
WHERE r.run_id = j.run_id
AND status = 'pending'

-- run-results-summary
SELECT j.job_id, j.run_id, j.run_count, j.runtime, j.begin_date, j.end_date, j.status, r.user
FROM job j, run r
WHERE j.run_id = :run-id

-- generate-error-summary
SELECT jl.job_id, j.run_id, j.runtime, j.begin_date, j.end_date, jl.type, j.status, j.run_count jl.description
FROM job j, job_log jl
WHERE j.id = jl.job_id
AND j.run_id = :run-id
AND j.status IN ('pending', 'failed')
GROUP BY 1
42 changes: 42 additions & 0 deletions test/spankins/test/acceptance/spankins_site.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(ns acceptance.spankins-site
(:use [pallet.action :only[with-action-options]]
[pallet.configure :only[compute-service]]
[pallet.api :only[converge]]
[spankins.config :only [db-settings delivery-settings]]
[expectations]
[clj-webdriver.taxi :only [set-driver! to click exists? input-text submit quit] :as scraper]
[clojure.core]
)

;; Spin up a system of virtual machines to test with
(def service (compute-service (:provider db-settings)))
(def spankins-nodes (converge {database-group 1} :compute service))
(def spankins-node ((first (@spankins-nodes :targets)) :node))
(def spankins-ip (.primary-ip db-node))
(def monitoring-nodes (converge {monitoring-group 1} :compute service))
(def monitoring-node ((first (@db-nodes :targets)) :node))
(def monitoring-ip (.primary-ip db-node))

(defn wait-sec [n] (Thread/sleep (* 1000 n)))
(def test-port 8087)
(def signup-uri "/")
;;(def app-server (landing-site.handler/start test-port))
(def test-user {:email "matthewburns@gmail.com" :full_name "bob smit" :phone "8182546028"})

;; ACCEPTANCE TEST: Run job
(def app-uri (str "http://" spankins-ip ":" test-port signup-uri))
(scraper/set-driver! {:browser :firefox} app-uri)
;; select job
(scraper/click "#run-job-form-submit")
(.stop app-server)
(def run-record (first (kdb/select run
(kdb/fields :id :job_id
(kdb/where {:name (:name test-job}))))

(expect true (= (:name test-job) (:name run-record)))
(kdb/delete run
(kdb/where {:user (:user test-job)}))
(comment
(power-down provider-host)
(destroy provider-host)
)
30 changes: 30 additions & 0 deletions test/spankins/test/model/job_run.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns spankins.test.model.job_run
^{:author "Matt Burns"
:doc "Component level tests relating to storing and reporting on job run "}
(:require [spankins.model.job_run :refer [log-job job_log log-run job_run validate-job validate-run]]
[expectations :refer [expect]]
[korma.core :refer [defentity database insert values select where] :as kdb]
[korma.db :refer [defdb mysql]]))

(def good-test-job {})
(def bad-test-job {})
(def good-test-run {})
(def bad-test-run {})

(expect true (empty? (validate-job good-test-job)))
(expect false (empty? (validate-job bad-test-job)))
(expect true (empty? (validate-run good-test-run)))
(expect false (empty? (validate-run bad-test-run)))
(comment
(def entry (log-job good-test-job))
(def retreived-record (first (kdb/select job_log
(kdb/fields :full_name :email :phone)
(kdb/where {:id (:id entry)}))))

(expect true (= (:name good-test-job) (:name retreived-record)))

(def run-entry (log-run good-test-run))
(def retreived-record (first (kdb/select job_run
(kdb/fields :job_id)
(kdb/where {:id (:id run-entry)}))))
)