lib/grumlin.rb in grumlin-0.22.5 vs lib/grumlin.rb in grumlin-0.23.0

- old
+ new

@@ -15,10 +15,11 @@ require "async/queue" require "async/barrier" require "async/http/endpoint" require "async/websocket/client" +require "middleware" require "retryable" require "zeitwerk" loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false) @@ -32,10 +33,11 @@ module Grumlin class Error < StandardError; end class TransactionError < Error; end + class Rollback < TransactionError; end class UnknownError < Error; end class ConnectionError < Error; end @@ -97,19 +99,23 @@ # TODO: parse message and assign @id # NOTE: Neptune does not return id. end class VertexAlreadyExistsError < AlreadyExistsError; end + class EdgeAlreadyExistsError < AlreadyExistsError; end class ConcurrentModificationError < ServerError; end + class ConcurrentInsertFailedError < ConcurrentModificationError; end class ConcurrentVertexInsertFailedError < ConcurrentInsertFailedError; end + class ConcurrentEdgeInsertFailedError < ConcurrentInsertFailedError; end class ConcurrentVertexPropertyInsertFailedError < ConcurrentInsertFailedError; end + class ConcurrentEdgePropertyInsertFailedError < ConcurrentInsertFailedError; end class ServerSerializationError < ServerSideError; end class ServerTimeoutError < ServerSideError; end @@ -132,12 +138,10 @@ class RepositoryError < Error; end class WrongQueryResult < RepositoryError; end - @pool_mutex = Mutex.new - class << self def configure yield config config.validate! @@ -145,37 +149,37 @@ def config @config ||= Config.new end + def default_middlewares + config.middlewares + end + # returns a subset of features for currently configured backend. # The features lists are hardcoded as there is no way to get them # from the remote server. def features Features.for(config.provider) # no memoization as provider may be changed end def default_pool - if Thread.current.thread_variable_get(:grumlin_default_pool) - return Thread.current.thread_variable_get(:grumlin_default_pool) - end + t = Thread.current + return t.thread_variable_get(:grumlin_default_pool) if t.thread_variable_get(:grumlin_default_pool) - @pool_mutex.synchronize do - Thread.current.thread_variable_set(:grumlin_default_pool, - Async::Pool::Controller.new(Grumlin::Client::PoolResource, - limit: config.pool_size)) - end + t.thread_variable_set(:grumlin_default_pool, + Async::Pool::Controller.new(Grumlin::Client::PoolResource, + limit: config.pool_size)) end def close - return if Thread.current.thread_variable_get(:grumlin_default_pool).nil? + t = Thread.current + return if t.thread_variable_get(:grumlin_default_pool).nil? - @pool_mutex.synchronize do - pool = Thread.current.thread_variable_get(:grumlin_default_pool) - pool.wait while pool.busy? - pool.close - Thread.current.thread_variable_set(:grumlin_default_pool, nil) - end + pool = t.thread_variable_get(:grumlin_default_pool) + pool.wait while pool.busy? + pool.close + t.thread_variable_set(:grumlin_default_pool, nil) end def definitions @definitions ||= YAML.safe_load(File.read(File.join(__dir__, "definitions.yml")), symbolize_names: true) end