Initial commit

This commit is contained in:
Yaser
2026-08-13 19:50:53 +03:30
commit 38084458fe
879 changed files with 95198 additions and 0 deletions

31
lib/peatio/influxdb.rb Normal file
View File

@@ -0,0 +1,31 @@
# encoding: UTF-8
# frozen_string_literal: true
module Peatio
module InfluxDB
class << self
def client(opts={})
# Map InfluxDB clients with received opts.
clients[opts] ||= ::InfluxDB::Client.new(parse(config.merge(opts)))
end
def config
yaml = ::Pathname.new("config/influxdb.yml")
return {} unless yaml.exist?
erb = ::ERB.new(yaml.read)
::SafeYAML.load(erb.result)[ENV.fetch('RAILS_ENV', 'development')].symbolize_keys || {}
end
def clients
@clients ||= {}
end
def parse(configs)
hosts = configs[:host]
configs[:host] = hosts[Zlib::crc32(configs[:keyshard].to_s) % hosts.count]
configs
end
end
end
end