class Ruboty::Brains::LocalPStore

Constants

KEY

Attributes

thread[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/ruboty/brains/local_pstore.rb, line 14
def initialize
  super
  @thread = Thread.new { sync }
  @thread.abort_on_exception = true
end

Public Instance Methods

data() click to toggle source
# File lib/ruboty/brains/local_pstore.rb, line 20
def data
  @data ||= pull || {}
end

Private Instance Methods

db() click to toggle source
# File lib/ruboty/brains/local_pstore.rb, line 49
def db
  @db ||= PStore.new('/tmp/__ruboty_pstore__')
end
interval() click to toggle source
# File lib/ruboty/brains/local_pstore.rb, line 53
def interval
  (ENV['PSTORE_SAVE_INTERVAL'] || 5).to_i
end
pull() click to toggle source
# File lib/ruboty/brains/local_pstore.rb, line 32
def pull
  db.transaction do
    db[KEY]
  end
end
push() click to toggle source
# File lib/ruboty/brains/local_pstore.rb, line 26
def push
  db.transaction do
    db[KEY] = data
  end
end
sync() click to toggle source
# File lib/ruboty/brains/local_pstore.rb, line 38
def sync
  loop do
    wait
    push
  end
end
wait() click to toggle source
# File lib/ruboty/brains/local_pstore.rb, line 45
def wait
  sleep(interval)
end