Skip to content

Instantly share code, notes, and snippets.

@bcambel
Forked from rrodrigu3z/em_server_mysqlplus.rb
Created November 10, 2011 18:48
Show Gist options
  • Save bcambel/1355730 to your computer and use it in GitHub Desktop.
Save bcambel/1355730 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