Created
January 30, 2012 15:19
-
-
Save mrmekon/1704930 to your computer and use it in GitHub Desktop.
Cancel all ISS messages in queue
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
(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