Skip to content

Instantly share code, notes, and snippets.

@terry3
Created January 20, 2017 10:06
Show Gist options
  • Save terry3/61acd31c44c9222ad97e89909368310a to your computer and use it in GitHub Desktop.
Save terry3/61acd31c44c9222ad97e89909368310a to your computer and use it in GitHub Desktop.
git lang ana core.clj
(ns git-lang-ana.core
(:require [clj-http.client :as client])
(:gen-class))
(import '(java.util TimerTask Timer))
(defn every [time f & args]
(let [task (proxy [TimerTask] []
(run [] (apply f args)))]
(. (new Timer) (schedule task 0 (* 1000 time)))))
(defn gla-exception-handler [exception]
(println "exception message is: " (.getMessage exception)))
(defn gla-fetch-repo []
(println (new java.util.Date))
(client/get "http://www.baidu.com"
{:async? true}
;; respond callback
(fn [response]
(println "response is:" response))
;; raise callback
(fn [exception]
(gla-exception-handler exception))))
(defn gla-fetch-repo-sync []
(println (new java.util.Date))
(println (:status (client/get "http://site.com/resources/id"))))
(defn -main
[& args]
(every 5 gla-fetch-repo-sync))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment