Class: Wamp::Worker::Ticker

Inherits:
Object
  • Object
show all
Defined in:
lib/wamp/worker/ticker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Ticker

Constructor

Parameters:

  • name (Symbol)
    • The name of the worker



10
11
12
13
# File 'lib/wamp/worker/ticker.rb', line 10

def initialize(name)
  @redis = Wamp::Worker.config.redis(name)
  @ticker_key = "wamp:#{name}:tick"
end

Instance Attribute Details

#redisObject (readonly)

Returns the value of attribute redis.



5
6
7
# File 'lib/wamp/worker/ticker.rb', line 5

def redis
  @redis
end

#ticker_keyObject (readonly)

Returns the value of attribute ticker_key.



5
6
7
# File 'lib/wamp/worker/ticker.rb', line 5

def ticker_key
  @ticker_key
end

Instance Method Details

#getInt

Returns the tick for the worker

Returns:

  • (Int)
    • The value of the tick



18
19
20
# File 'lib/wamp/worker/ticker.rb', line 18

def get
  self.redis.get(self.ticker_key) || 0
end

#incrementObject

Increments the tick



24
25
26
# File 'lib/wamp/worker/ticker.rb', line 24

def increment
  self.redis.incr(self.ticker_key)
end