 (defn event->uid [event]
   (get-in event [:ring-req :cookies "ring-session" :value]))
 
-; TODO: should be passing tracking around
-(defn stop-tracking! [user-id]
-  (when-let [current (@tracking user-id)]
-    (component/stop (:client current))
-    (future-cancel (:tracking-fut current))))
-
-(defn start-tracking! [send-fn! deployment-id peer-config user-id]
-  (stop-tracking! user-id)
-  (let [client (component/start (system/onyx-client peer-config))] 
-    (swap! tracking 
-           assoc 
-           user-id
-           {:client client
-            :tracking-fut (future 
-                            (track-deployment send-fn!
-                                              client
-                                              (assoc peer-config :onyx/id deployment-id)
-                                              user-id))})))
-
 (defn start-event-handler [sente peer-config]
-  (thread
+  (future
     (loop []
       (when-let [event (<!! (:ch-chsk sente))]
-        (info "EVENT:" event)
+        ;(info "EVENT:" event)
         ;; TODO: more sophisticated tracking,
         ;; should track by cluster id rather than user
         ;; and count the number of users tracking it. When the user count drops to 0

            [:security :anti-forgery]
            {:read-token (fn [req] (-> req :params :csrf-token))}))

; Improve fn name
(defn job-peer-allocated-task [job-allocations job-id peer-id]
  (ffirst 

        (let [user-id (event->uid event)] 
          (case (:id event) 
            :deployment/track (start-tracking! (:chsk-send! sente)
                                               peer-config
                                               (:?data event)
                                               user-id)
            :deployment/get-listing ((:chsk-send! sente) user-id [:deployment/listing @deployments])
            :chsk/uidport-close (stop-tracking! user-id)
            :chsk/ws-ping nil
            (println "Dunno what to do with: " event)))
        (recur)))))
