Skip to content

Instantly share code, notes, and snippets.

@rrodrigu3z
Created August 30, 2010 13:08
Show Gist options
  • Save rrodrigu3z/557370 to your computer and use it in GitHub Desktop.
Save rrodrigu3z/557370 to your computer and use it in GitHub Desktop.
# 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