Created
December 28, 2011 04:31
-
-
Save Bek/1526274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MessageSender | |
def self.redis | |
@redis ||= EM::Hiredis.connect | |
end | |
def self.next | |
redis.blpop("company-out", 0) do |item| | |
if item[1] | |
message_hashed = JSON.parse(item[1]) | |
puts "this is the problematic hash #{message_hashed}" | |
UcellGateway.send_mt(message_hashed["from"], | |
message_hashed["to"], | |
message_hashed["message"]) | |
end | |
EM.next_tick(&method(:next)) | |
end | |
end | |
end | |
loop do | |
EventMachine::run do | |
@@tx = EventMachine::connect( | |
config[:host], | |
config[:port], | |
Smpp::Transceiver, | |
config, | |
self # delegate that will receive callbacks on MOs and DRs and other events | |
) | |
MessageSender.next # gets the messages from redis list and sends at each click of the EventMachine | |
end | |
puts "Disconnected. Reconnecting in 5 seconds.." | |
sleep 5 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment