Skip to content
Browse files

Remove registering mechanism; unnecessary with syntax-quote.

  • Loading branch information...
1 parent 465a48c commit 5e94fb288dc3e9b5ea91f80dc11a16b578e33324 @technomancy committed Aug 2, 2011
Showing with 8 additions and 56 deletions.
  1. +3 −13 README.md
  2. +2 −22 src/die/roboter.clj
  3. +3 −21 test/die/test/roboter.clj
View
16 README.md
@@ -28,25 +28,14 @@ The Robots get your work done in an straightforward way.
(roboter/work) ; on the worker nodes (this will block)
;; ordering around
- (roboter/send-off '(println "Boing, Boom Tschak.")) ; returns immediately
+ (roboter/send-off `(println "Boing, Boom Tschak.")) ; returns immediately
- (roboter/broadcast '(println "Greetings all Programs!")) ; runs on all nodes
+ (roboter/broadcast `(println "Greetings all Programs!")) ; runs on all nodes
(let [f (roboter/future
(slurp "/etc/hosts"))]
(println @f)) ; when you need a return value back
- ;; By default only clojure/core is available for robot
- ;; workers, but you can tag defns to make them available.
- (defn ^{:roboter true} my-job [a b c]
- (prn :my-job {:a a :b b :c c})
-
- ;; These defns should be loaded before you run roboter/work,
- ;; but you can pick up stragglers explicitly:
-
- (roboter/register #'my-job)
- (roboter/auto-register "my.project") ; searches all matching namespaces
-
Jobs will not ack to the server until they've completed successfully,
so workers that throw exceptions or disappear entirely will have their
jobs automatically retried. By default failed jobs will simply log
@@ -79,6 +68,7 @@ use the `with-robots` macro to bind it dynamically.
* Thread pooling
* Switch to tools.namespace once it's fixed
* Fix broadcast (see failing test)
+* Control queue
## License
View
24 src/die/roboter.clj
@@ -3,8 +3,9 @@
(:refer-clojure :exclude [future send-off])
(:require [com.mefesto.wabbitmq :as wabbit]
[clojure.tools.logging :as log]
- [leiningen.util.ns :as ns]) ; TODO: spin off into lib
+ [leiningen.util.ns :as ns]) ; TODO: use clojure.tools.namespace
(:import (java.util UUID)
+ (java.util.concurrent Executors TimeUnit TimeoutException)
(java.lang.management ManagementFactory)))
(def ^{:doc "Namespace in which robots work." :private true} context
@@ -72,25 +73,6 @@
(wabbit/with-queue reply-queue#
(-> (wabbit/consuming-seq true) first :body String. read-string))))))
-(defn register
- "Register var to be available for robots to run."
- [var]
- (binding [*ns* context]
- (refer (.getName (:ns (meta var))) :only [(:name (meta var))])))
-
-(defn auto-register
- "Register all vars with :robots metadata in namespaces starting with prefix.
- This requires the namespaces, so it could cause code to be loaded. prefix
- defaults to the empty string."
- ([prefix]
- (doseq [namespace (ns/namespaces-matching prefix)]
- (try (with-out-str (require namespace))
- (doseq [[_ var] (ns-publics namespace)
- :when (:robots (meta var))]
- (register var))
- (catch Throwable _))))
- ([] (auto-register "")))
-
(defn- consume [{:keys [body envelope] :as msg}]
(binding [*ns* context,*current-message* msg]
;; TODO: timeouts
@@ -101,8 +83,6 @@
(defn work
"Wait for work and eval it continually."
([config]
- (when (:auto-register config true)
- (auto-register (:auto-register config "")))
(with-robots config
(wabbit/with-queue (:queue config "die.roboter.work")
(log/trace "Consuming on" (:queue config "die.roboter.work"))
View
24 test/die/test/roboter.clj
@@ -18,7 +18,7 @@
(defn work-fixture [f]
(clear-queues! "die.roboter.work")
- (let [worker (clojure.core/future (work {:auto-register false}))]
+ (let [worker (clojure.core/future (work))]
(reset! state {})
(try (f)
(finally (.cancel worker true)
@@ -44,35 +44,17 @@
(deftest test-future
(is (= 1 (.get (future 1) 100 TimeUnit/MILLISECONDS))))
-(defn my-job []
- (swap! state assoc :my-job true))
-
-(defn ^{:robots true} my-job2 []
- (swap! state assoc :my-job2 true))
-
-(deftest test-register
- (register #'my-job)
- (with-block 1
- (send-off `(my-job)))
- (is (= {:my-job true} @state)))
-
-(deftest test-auto-register
- (auto-register (name (.getName *ns*)))
- (with-block 1
- (send-off `(my-job2)))
- (is (= {:my-job2 true} @state)))
-
(def bound :root)
(deftest test-broadcast
(with-block 2
;; TODO: these jerks aren't pulling their weight
(let [worker1 (clojure.core/future
(binding [bound 1]
- (work-on-broadcast {:auto-register false})))
+ (work-on-broadcast)))
worker2 (clojure.core/future
(binding [bound 2]
- (work-on-broadcast {:auto-register false})))]
+ (work-on-broadcast)))]
(try (broadcast `(swap! state assoc bound true))
(finally (.cancel worker1 true)
(.cancel worker2 true)))))

0 comments on commit 5e94fb2

Please sign in to comment.
Something went wrong with that request. Please try again.