Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
query_factory = MemoizingQueryFactory.new(TimingOutQueryFactory.new(Query, 1.second))
QueryEvaluator.new(ConnectionPool.new(20), query_factory)
class MemoizingQueryFactory
def initialize(query_factory)
@memo = Hash.new do |h, k|
h = query_factory.new(*k)
end
end
def new(connection, query_string, *args)
@memo[[connection, query_string, args]]
end
end
class QueryEvaluator
def initialize(connection_pool, query_factory = Query)
@query_factory = query_factory
@connection_pool = connection_pool
end
def select(query_string, *args)
@connection_pool.with_connection do |connection|
@query_factory.new(connection, query_string, *args).select
end
end
end
class TimingOutQueryProxyFactory
def initialize(query_factory, timeout)
@query_factory = query_factory
@timeout = timeout
end
def new(connection, query_string, *args)
@query_factory.new(connection, query_string, *args)
end
end
class TimingOutQueryProxy
def initialize(query, timeout)
@query = query
@timeout = timeout
end
def select
Timeout.timeout(@timeout) do
@query.select
end
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.