Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Worker
- module App
- module Cli
- class Development < Thor
- namespace "worker:dev"
- @conf = {
- :host => "localhost",
- :user => "guest",
- :password => "guest",
- :vhost => "/",
- :logging => true,
- :port => 5672
- }
- desc "start_consumer", "start the test consumer"
- def start_consumer
- AMQP.start(@conf) do |connection|
- channel = AMQP::Channel.new(connection)
- requests_queue = channel.queue("leads")
- requests_queue.purge
- Signal.trap("INT") do
- connection.close do
- EM.stop{exit}
- end
- end
- requests_queue.subscribe(:ack => true) do |header, body|
- url_search = safe_json_decode(body)
- puts "we have a message at #{Time.now} with search terms of #{url_search.inspect}"
- doc = open(url_search["search_url"])
- parser = Parser.new(nil, doc)
- parser.find_potential_leads do |lead|
- puts "lead = #{lead.company}"
- json = lead.to_json(:include => [:emails, :contacts])
- AMQP::Exchange.default.publish(
- json,
- :routing_key => header.reply_to,
- :correlation_id => header.correlation_id
- )
- end
- end
- puts " [x] Awaiting RPC requests"
- end
- end
Add Comment
Please, Sign In to add comment