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
# 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)

  @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.



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

def backend
  @backend
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#acquire(options = {}) ⇒ Object

:max_acquire => nil :alive_time => nil



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

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

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

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

:message => nil



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

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

#closeObject



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

def close
  @backend.close
end

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

:message => nil :retention_time => default_retention_time



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

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



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

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



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

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

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

:message => nil :alive_time => nil



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

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

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

#init_database(options = {}) ⇒ Object



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

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

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



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

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

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

:message => nil :alive_time => @alive_time



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

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

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

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



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

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

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

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



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

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

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

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

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



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

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