Skip to content
Browse files

Ruby: new_task.rb, ARGV fix.

  • Loading branch information...
1 parent f5ad3b0 commit d83ca8fadc31559da477c0c4bcbf6916d057d40c @botanicus botanicus committed May 3, 2011
Showing with 24 additions and 5 deletions.
  1. +1 −1 ruby/emit_log.rb
  2. +2 −2 ruby/emit_log_direct.rb
  3. +2 −2 ruby/emit_log_topic.rb
  4. +19 −0 ruby/new_task.rb
View
2 ruby/emit_log.rb
@@ -6,7 +6,7 @@
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.fanout("logs")
- message = (ARGV[0..-1] || ["info: Hello World!"]).join(" ")
+ message = ARGV.empty? ? "info: Hello World!" : ARGV.join(" ")
exchange.publish(message)
puts " [x] Sent #{message}"
View
4 ruby/emit_log_direct.rb
@@ -6,8 +6,8 @@
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.direct("direct_logs")
- severity = ARGV[0] || "info"
- message = (ARGV[1..-1] || ["Hello World!"]).join(" ")
+ severity = ARGV.shift || "info"
+ message = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
exchange.publish(message, :routing_key => severity)
puts " [x] Sent #{severity}:#{message}"
View
4 ruby/emit_log_topic.rb
@@ -6,8 +6,8 @@
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.topic("topic_logs")
- severity = ARGV[0] || "anonymous.info"
- message = (ARGV[1..-1] || ["Hello World!"]).join(" ")
+ severity = ARGV.shift || "anonymous.info"
+ message = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
exchange.publish(message, :routing_key => severity)
puts " [x] Sent #{severity}:#{message}"
View
19 ruby/new_task.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+# encoding: utf-8
+
+require "amqp"
+
+AMQP.start(:host => "localhost") do |connection|
+ channel = AMQP::Channel.new(connection)
+ queue = channel.queue("task_queue", :durable => true)
+ message = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
+
+ AMQP::Exchange.default.publish(message, :routing_key => queue.name, :persistent => true)
+ puts " [x] Sent #{message}"
+
+ EM.add_timer(0.5) do
+ connection.close do
+ EM.stop { exit }
+ end
+ end
+end

0 comments on commit d83ca8f

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