You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
608 B
27 lines
608 B
7 years ago
|
class Datastore
|
||
|
@@index = Stretcher::Server.new(ENV['ES_URL']).index :cryptcheck
|
||
|
@@index.create unless @@index.exists?
|
||
|
|
||
7 years ago
|
def self.host(type, host, port)
|
||
|
result = @@index.type(type).get self.key(host, port)
|
||
7 years ago
|
result.date = Time.parse result.date
|
||
|
result
|
||
|
rescue Stretcher::RequestError::NotFound
|
||
|
end
|
||
|
|
||
7 years ago
|
def self.pending(type, host, port)
|
||
|
self.post type, host, port, { pending: true }
|
||
7 years ago
|
end
|
||
|
|
||
7 years ago
|
def self.post(type, host, port, data)
|
||
7 years ago
|
data[:date] = DateTime.now
|
||
7 years ago
|
@@index.type(type).put self.key(host, port), data
|
||
|
end
|
||
|
|
||
|
private
|
||
|
def self.key(host, port)
|
||
|
host = "#{host}:#{port}" if port
|
||
|
host
|
||
7 years ago
|
end
|
||
|
end
|