Created
August 30, 2010 13:08
-
-
Save rrodrigu3z/557370 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
# coding:utf-8 | |
$:.unshift(File.join(File.dirname(__FILE__), 'lib')) | |
require 'rubygems' | |
require 'active_record' | |
require 'em-mysqlplus' | |
require 'em-synchrony' | |
require 'em-activerecord' | |
db_config = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'database.yml')) | |
ActiveRecord::Base.configurations["qimax_production"] = db_config['qimax_production'] | |
class Message < ActiveRecord::Base; end; | |
module ConnectionHandler | |
def receive_data(msg) | |
# Works adding a Fiber here!!! | |
Fiber.new { | |
puts "-- Datos recibidos: #{msg.length} bytes" | |
puts Message.find_by_sql("select sleep(1)") | |
}.resume | |
end | |
end | |
EventMachine.synchrony { | |
ActiveRecord::Base.establish_connection :qimax_production | |
EventMachine::start_server "0.0.0.0", 9003, ConnectionHandler | |
puts "Iniciando servidor..." | |
} | |
puts "Recator detenido!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment