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) ⇒ BackgroundQueue::ClientLib::JobHandle

Add a task to the background

Parameters:

  • worker (Symbol)

    name of the worker, ie :some_background_worker

  • owner_id (Symbol, String, Number)

    something that identified the owner of the task. This will make sure resources are divided between owners equally.

  • job_id (Symbol, String, Number)

    something to idetify the job. Tracking occurs per job.

  • task_id (Symbol, String, Number)

    a globally unique id for the task. If the task_id exists elsewhere, it will be removed and added to the owner/job queue specified.

  • priority (Integer)

    priority for 1 (highest) to 5 (lowest). Used to determine order of jobs.

  • task_parameters (Hash) (defaults to: {})

    a hash of parameters passed to the task

  • options (Hash) (defaults to: {})

    a hash of options that effect how the task is executed.

Options Hash (options):

  • :domain (String)

    the domain to set in the host header when calling the worker.

  • :exclude (Boolean)

    if true, will not be included in (x/y) counter of progress caption

  • :synchronous (Boolean)

    if true, the task is synchronous, and no other tasks in the job will run until it is finished

  • :weight (Number)

    the weight of the task. Usually its weight is the same as other tasks in job

  • :initial_progress_caption (String)

    the progress caption to display until the job has started reporting progress

  • :send_summary (Boolean)

    if true, the task will receive the summary data

  • :step (Symbol)

    the step to run, ‘:start`, `:run` (Default) or `:finish`

Returns:



32
33
34
35
36
37
# File 'lib/background_queue/client.rb', line 32

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

Parameters:

  • worker (Symbol)

    name of the worker, ie :some_background_worker

  • owner_id (Symbol, String, Number)

    something that identified the owner of the task. This will make sure resources are divided between owners equally.

  • job_id (Symbol, String, Number)

    something to idetify the job. Tracking occurs per job.

  • tasks (Array<Array<String, Hash, Hash>>)

    an array of arrays in the format [task_id, optional task_params (Hash), optional task_options (Hash)]

  • priority (Integer)

    priority for 1 (highest) to 5 (lowest). Used to determine order of jobs.

  • shared_parameters (Hash) (defaults to: {})

    a hash of parameters passed to the tasks. This is merged with the task_params specified in the tasks param.

  • options (Hash) (defaults to: {})

    a hash of options that effect how the tasks are executed. This is merged with the task_options specified in the tasks param. Refer to #add_task for options.



48
49
50
51
52
# File 'lib/background_queue/client.rb', line 48

def add_tasks(worker, owner_id, job_id, tasks, priority, shared_parameters={}, options={}, server=nil )
  result, server = send_command(BackgroundQueue::ClientLib::Command.add_tasks_command(worker, owner_id, job_id, tasks, priority, shared_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

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



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

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



54
55
56
57
# File 'lib/background_queue/client.rb', line 54

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