Skip to content

Instantly share code, notes, and snippets.

@mrmekon
Created January 30, 2012 15:19
Show Gist options
  • Save mrmekon/1704930 to your computer and use it in GitHub Desktop.
Save mrmekon/1704930 to your computer and use it in GitHub Desktop.
Cancel all ISS messages in queue
(ns com.trevorbentley.cancelMessages
(:require [http.async.client :as client]
[cheshire.core :as cheshire]))
(def host (if (> (count *command-line-args*) 0)
(first *command-line-args*)
"localhost"))
(def cancelUrl (str "http://" host ":9090/cancelMessage"))
(def activeUrl (str "http://" host ":9090/activeMessages"))
(println "Querying " activeUrl)
(defn cancelId [id]
(with-open [client (client/create-client)]
(let [response (client/POST client cancelUrl
:body {:json (cheshire/generate-string {:id id})})]
(client/await response)
(when-let [err (client/error response)]
(println "error: " err))
(client/string response))))
(defn activeMsgs []
(with-open [client (client/create-client)]
(let [response (client/GET client activeUrl)]
(client/await response)
(when-let [err (client/error response)]
(println "error: " err))
(client/string response))))
(def msgs (activeMsgs))
(println "Active messages: " msgs)
(def json (cheshire/parse-string msgs true))
(if (== 0 (count json)) (System/exit 0))
(doseq [j json] (println "Cancelling " (get j :id))
(cancelId (get j :id)))
(def msgs (activeMsgs))
(println "Active messages: " msgs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment