Skip to content

Commit

Permalink
add pause-tube in net tier, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Aug 25, 2011
1 parent a83106f commit 22bdeef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/clojalk/core.clj
Expand Up @@ -285,10 +285,10 @@
(:watch @session))

(defcommand "pause-tube" [session id timeout]
(let [tube ((keyword id) @tubes)]
(if-let [tube ((keyword id) @tubes)]
(dosync
(alter tube assoc :paused true)
(alter tube assoc :pause_deadline (+ timeout (current-time)))
(alter tube assoc :pause_deadline (+ (* timeout 1000) (current-time)))
(alter tube assoc :pauses (inc (:pauses @tube))))))

(defcommand "stats-job" [session id]
Expand Down
11 changes: 11 additions & 0 deletions src/clojalk/net.clj
Expand Up @@ -190,6 +190,16 @@
(let [stats- (exec-cmd "stats" nil)]
(enqueue ch ["OK" (format-stats stats-)])))

(defn on-pause-tube [ch args]
(try
(let [tube-name (first args)
timeout (as-int (second args))
tube (exec-cmd "pause-tube" nil tube-name timeout)]
(if (nil? tube)
(enqueue ch ["NOT_FOUND"])
(enqueue ch ["PAUSED"])))
(catch NumberFormatException e (enqueue ch ["BAD_FORMAT"]))))

(defn command-dispatcher [ch client-info msg]
(let [remote-addr (:remote-addr client-info)
cmd (first msg)
Expand Down Expand Up @@ -222,6 +232,7 @@
"STATS-JOB" (on-stats-job ch args)
"STATS-TUBE" (on-stats-tube ch args)
"STATS" (on-stats ch)
"PAUSE-TUBE" (on-pause-tube ch args)
(enqueue ch ["UNKNOWN_COMMAND"]))))

(defn default-handler [ch client-info]
Expand Down
3 changes: 2 additions & 1 deletion src/clojalk/net/protocol.clj
Expand Up @@ -64,7 +64,8 @@
"KICKED" [token-newline]
"TOUCHED" [token-newline]
"FOUND" [token-space body]
"TIMED_OUT" [token-newline]})
"TIMED_OUT" [token-newline]
"PAUSED" [token-newline]})

(defn- commands-mapping [cmd]
(let [normalized-cmd (upper-case cmd)]
Expand Down

0 comments on commit 22bdeef

Please sign in to comment.