module BigBench::Store

The store encapsulates the communication with the redis key-value store. To the outside it looks like normal module methods would be called. It allows the simple starting of a test on multiple bots with the latest test reciept.

Constants

BOTS_KEY
RUNNING_KEY
TEST_RECEIPT_KEY
TRACKINGS_KEY

Public Class Methods

add_tracking(tracking) click to toggle source

Add a tracking to the trackings

# File lib/bigbench/store.rb, line 77
def self.add_tracking(tracking)
  @redis.rpush(TRACKINGS_KEY, tracking)
end
bot_is_working(id) click to toggle source

Adds a bot to the currently working bots list

# File lib/bigbench/store.rb, line 62
def self.bot_is_working(id)
  @redis.sadd(BOTS_KEY, id)
end
bot_stopped_working(id) click to toggle source

Removes a bot to the currently working bots list

# File lib/bigbench/store.rb, line 67
def self.bot_stopped_working(id)
  @redis.srem(BOTS_KEY, id)
end
bots() click to toggle source

Shows all currently working bots

# File lib/bigbench/store.rb, line 72
def self.bots
  @redis.smembers(BOTS_KEY)
end
count_trackings() click to toggle source

How many trackings are in the list

# File lib/bigbench/store.rb, line 87
def self.count_trackings
  @redis.llen(TRACKINGS_KEY)
end
pop_tracking() click to toggle source

Pop a tracking from the beginning of the list

# File lib/bigbench/store.rb, line 82
def self.pop_tracking
  @redis.lpop(TRACKINGS_KEY)
end
reset!() click to toggle source

Deletes all BigBench related keys on the redis store

# File lib/bigbench/store.rb, line 23
def self.reset!
  return if @redis.nil?
  
  @redis.del(TEST_RECEIPT_KEY)
  @redis.del(RUNNING_KEY)
  @redis.del(BOTS_KEY)
  @redis.del(TRACKINGS_KEY)
end
running?() click to toggle source

Returns true if a bot test has been started

# File lib/bigbench/store.rb, line 57
def self.running?
  @redis.get(RUNNING_KEY) == "1"
end
setup!(url = "localhost:6379", password = nil) click to toggle source

Setup the redis storage. Default values are localhost:6379 and no password. This needs to be called for any bot test

# File lib/bigbench/store.rb, line 16
def self.setup!(url = "localhost:6379", password = nil)
  uri = URI(url)
  @redis = ::Redis.new :host => uri.host, :port => uri.port, :password => password
  true
end
start() click to toggle source

Start the tests for all bots by setting the running key

# File lib/bigbench/store.rb, line 47
def self.start
  @redis.set(RUNNING_KEY, "1")
end
stop() click to toggle source

Stops the test for all bots by unsetting the running key

# File lib/bigbench/store.rb, line 52
def self.stop
  @redis.set(RUNNING_KEY, "0")
end
test() click to toggle source

Gets the current test from the redis

# File lib/bigbench/store.rb, line 42
def self.test
  @redis.get(TEST_RECEIPT_KEY)
end
test=(test) click to toggle source

Stores the current test receipt for all bots on the redis instance

# File lib/bigbench/store.rb, line 33
def self.test=(test)
  if test
    @redis.set(TEST_RECEIPT_KEY, test)
  else
    @redis.del(TEST_RECEIPT_KEY)
  end
end