Class: PerfectQueue::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/perfectqueue/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/perfectqueue/client.rb', line 21

def initialize(config)
  @config = {}
  config.each_pair {|k,v| @config[k.to_sym] = v }

  @backend = Backend.new_backend(self, @config)

  @max_acquire = @config[:max_acquire] || 1
  @retention_time = @config[:retention_time] || 300
  @alive_time = @config[:alive_time] || 300
  @retry_wait = @config[:retry_wait] || 300  # TODO retry wait algorithm
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



33
34
35
# File 'lib/perfectqueue/client.rb', line 33

def backend
  @backend
end

#configObject (readonly)

Returns the value of attribute config.



34
35
36
# File 'lib/perfectqueue/client.rb', line 34

def config
  @config
end

Instance Method Details

#acquire(options = {}) ⇒ Object

:max_acquire => nil :alive_time => nil



66
67
68
69
70
71
# File 'lib/perfectqueue/client.rb', line 66

def acquire(options={})
  alive_time = options[:alive_time] || @alive_time
  max_acquire = options[:max_acquire] || @max_acquire

  @backend.acquire(alive_time, max_acquire, options)
end

#cancel_request(key, options = {}) ⇒ Object

:message => nil



74
75
76
# File 'lib/perfectqueue/client.rb', line 74

def cancel_request(key, options={})
  @backend.cancel_request(key, options)
end

#closeObject



112
113
114
# File 'lib/perfectqueue/client.rb', line 112

def close
  @backend.close
end

#finish(task_token, options = {}) ⇒ Object

:message => nil :retention_time => default_retention_time



86
87
88
89
90
# File 'lib/perfectqueue/client.rb', line 86

def finish(task_token, options={})
  retention_time = options[:retention_time] || @retention_time

  @backend.finish(task_token, retention_time, options)
end

#force_finish(key, options = {}) ⇒ Object



78
79
80
81
82
# File 'lib/perfectqueue/client.rb', line 78

def force_finish(key, options={})
  retention_time = options[:retention_time] || @retention_time

  @backend.force_finish(key, retention_time, options)
end

#get_task_metadata(key, options = {}) ⇒ Object



40
41
42
# File 'lib/perfectqueue/client.rb', line 40

def (key, options={})
  @backend.(key, options)
end

#heartbeat(task_token, options = {}) ⇒ Object

:message => nil :alive_time => nil



94
95
96
97
98
# File 'lib/perfectqueue/client.rb', line 94

def heartbeat(task_token, options={})
  alive_time = options[:alive_time] || @alive_time

  @backend.heartbeat(task_token, alive_time, options)
end

#init_database(options = {}) ⇒ Object



36
37
38
# File 'lib/perfectqueue/client.rb', line 36

def init_database(options={})
  @backend.init_database(options)
end

#list(options = {}, &block) ⇒ Object



52
53
54
# File 'lib/perfectqueue/client.rb', line 52

def list(options={}, &block)
  @backend.list(options, &block)
end

#preempt(key, options = {}) ⇒ Object

:message => nil :alive_time => @alive_time



46
47
48
49
50
# File 'lib/perfectqueue/client.rb', line 46

def preempt(key, options={})
  alive_time = options[:alive_time] || @alive_time

  @backend.preempt(key, alive_time, options)
end

#release(task_token, options = {}) ⇒ Object



100
101
102
103
104
# File 'lib/perfectqueue/client.rb', line 100

def release(task_token, options={})
  alive_time = options[:alive_time] || 0

  @backend.heartbeat(task_token, alive_time, options)
end

#retry(task_token, options = {}) ⇒ Object



106
107
108
109
110
# File 'lib/perfectqueue/client.rb', line 106

def retry(task_token, options={})
  alive_time = options[:retry_wait] || @retry_wait

  @backend.heartbeat(task_token, alive_time, options)
end

#submit(key, type, data, options = {}) ⇒ Object

:run_at => Time.now :message => nil :user => nil :priority => nil



60
61
62
# File 'lib/perfectqueue/client.rb', line 60

def submit(key, type, data, options={})
  @backend.submit(key, type, data, options)
end