lib/vrowser.rb in vrowser-0.1.2 vs lib/vrowser.rb in vrowser-0.1.3
- old
+ new
@@ -4,35 +4,45 @@
require 'logger'
require 'retry-handler'
require 'active_support/core_ext'
require 'yaml'
require 'json'
+require 'time'
module VrowserModel
def self.connect(options={})
- Sequel::Model.plugin(:schema)
- Sequel.connect(options)
+ logger = options.delete(:logger)
+
+ Sequel::Model.plugin :schema
+ Sequel::Model.plugin :timestamps, :update_on_create => true
+ Sequel::Model.plugin :force_encoding, 'utf-8'
+ if logger
+ Sequel.connect(options, :loggers => [logger])
+ else
+ Sequel.connect(options)
+ end
+
self.define_models
Servers.plugin :timestamps, :create=>:created_at, :update=>:updated_at
end
def self.define_models
module_eval %{
class Servers < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
- string :name
- string :host, :unique => true
- string :status
- integer :ping
- string :num_players
- string :type
- string :map
- string :players
- timestamp :created_at
- timestamp :updated_at
+ String :name
+ String :host, :unique => true
+ String :status
+ Integer :ping
+ String :num_players
+ String :type
+ String :map
+ String :players
+ timestamp :created_at, :default => nil, :null => true
+ timestamp :updated_at, :default => nil, :null => true
end
create_table
end
end
}
@@ -97,12 +107,12 @@
Servers.all.each{ |server|
@@logger.info "trying to update: #{server.host}, #{server.name}"
self.update(server.host, protocol)
updated += 1
}
- rescue
- @@logger.error $!
+ #rescue => ex
+ # @@logger.error "#{ex.inspect}"
ensure
@@logger.info "updated #{updated} servers"
end
end
@@ -112,12 +122,12 @@
Servers.all.each{ |server|
@@logger.info "trying to update_info: #{server.host}, #{server.name}"
self.update_info(server.host, protocol)
updated += 1
}
- rescue
- @@logger.error $!
+ rescue => ex
+ @@logger.error "#{ex.inspect}"
ensure
@@logger.info "updated #{updated} servers"
end
end
@@ -208,10 +218,10 @@
proc{
@@logger.info "try to fetch server list"
return QStat.query_serverlist(host, gametype, gamename, maxping)
}.retry(:accept_exception => StandardError, :logger => @@logger)
rescue => ex
- @@logger.error "error: #{ex}"
+ @@logger.error "#{ex.inspect}"
return []
end
def self.read_serverlist_from_xml(path)
QStat.read_from_xml(path)