Class: BackgroundQueue::Client

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

Overview

The main interface to the background queue from the client. this class will look after sending a command to the server, using a failover server if needed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/background_queue/client.rb', line 9

def initialize(path)
  @config = BackgroundQueue::ClientLib::Config.load_file(path)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/background_queue/client.rb', line 7

def config
  @config
end

Instance Method Details

#add_task(worker, owner_id, job_id, task_id, priority, task_parameters = {}, options = {}, server = nil) ⇒ Object

add a task to the background



14
15
16
17
18
19
# File 'lib/background_queue/client.rb', line 14

def add_task(worker, owner_id, job_id, task_id, priority, task_parameters={}, options={}, server=nil )
  job_id, task_id = generate_ids(worker, owner_id, job_id, task_id)
  result, server = send_command(BackgroundQueue::ClientLib::Command.add_task_command(worker, owner_id, job_id, task_id, priority, task_parameters, options ), server)
  #the server currently either returns :ok or an exception would have been thrown
  BackgroundQueue::ClientLib::JobHandle.new(owner_id, job_id, server)
end

#add_tasks(worker, owner_id, job_id, tasks, priority, shared_parameters = {}, options = {}, server = nil) ⇒ Object

add multiple tasks to the background, all with the same worker/owner/job



22
23
24
# File 'lib/background_queue/client.rb', line 22

def add_tasks(worker, owner_id, job_id, tasks, priority, shared_parameters={}, options={}, server=nil )
  send_command(BackgroundQueue::ClientLib::Command.add_tasks_command(worker, owner_id, job_id, tasks, priority, shared_parameters, options ), server)
end

#get_stats(server, options = {}) ⇒ Object



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

def get_stats(server, options={})
  result, server = send_command(BackgroundQueue::ClientLib::Command.stats_command(options ), server)
  result.args
end

#get_status(job_handle, options = {}) ⇒ Object



26
27
28
29
# File 'lib/background_queue/client.rb', line 26

def get_status(job_handle, options={})
  result, server = send_command(BackgroundQueue::ClientLib::Command.get_status_command(job_handle.job_id, options ), job_handle.server)
  result
end