Class: ResqueAdmin::Scheduler::Lock::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/resque_admin/scheduler/lock/base.rb

Direct Known Subclasses

Basic, Resilient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/resque_admin/scheduler/lock/base.rb', line 10

def initialize(key, options = {})
  @key = key

  # 3 minute default timeout
  @timeout = options[:timeout] || 60 * 3
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/resque_admin/scheduler/lock/base.rb', line 7

def key
  @key
end

#timeoutObject

Returns the value of attribute timeout.



8
9
10
# File 'lib/resque_admin/scheduler/lock/base.rb', line 8

def timeout
  @timeout
end

Instance Method Details

#acquire!Object

Attempts to acquire the lock. Returns true if successfully acquired.

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/resque_admin/scheduler/lock/base.rb', line 18

def acquire!
  raise NotImplementedError
end

#locked?Boolean

Returns true if you currently hold the lock.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/resque_admin/scheduler/lock/base.rb', line 27

def locked?
  raise NotImplementedError
end

#releaseObject

Releases the lock iff we own it



37
38
39
# File 'lib/resque_admin/scheduler/lock/base.rb', line 37

def release
  locked? && release!
end

#release!Object

Releases the lock.



32
33
34
# File 'lib/resque_admin/scheduler/lock/base.rb', line 32

def release!
  ResqueAdmin.redis.del(key) == 1
end

#valueObject



22
23
24
# File 'lib/resque_admin/scheduler/lock/base.rb', line 22

def value
  @value ||= [hostname, process_id].join(':')
end