No commit activity in last 3 years
No release in over 3 years
Organise background tasks so they will not overload the machine(s) running the tasks, while still giving a fair, balanced allocation of running time to members in the queue
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.8.3
~> 3.12
~> 2.1.1
>= 2.9.0
~> 0.7

Runtime

~> 0.5.0
~> 0.12.10
~> 0.8.0
>= 0
 Project Readme

background_queue

This is a gem to manage background tasks. The primary focus is organising the tasks so they will not overload the machine(s) running the tasks, while still giving a fair, balanced allocation of running time to members in the queue.

Usage

Initializing

In your environment, initialize a constant BackgroundQueue::Client

 BG_QUEUE = BackgroundQueue::Client.new(_PATH_TO_CONFIG_)

Starting a single task

Now you can use your BG_QUEUE to add a single task. Note: the "task_id" should be unique, even between owners/jobs. If there is an existing task with the same id in any queue, even if its a different owner/job, the existing task will be removed before this task is added the the ownerjob queue.

 job_handle = BG_QUEUE.add_task(:worker_name, "owner identifier", "job identifier", "task_id", priority, {:some_task=>:params}, {:priority=>1})

Starting multiple tasks

Or you can queue multiple tasks at once.

 job_handle = BG_QUEUE.add_tasks(:worker_name, "owner identifier", "job identifier", [["task1_id" , {:some_task=>:params}], ["task2_id" , {:some_task=>:params}]], priority, {:shared=>:params}, {:priority=>1})

Job Status

Get the status of the job

status = BG_QUEUE.get_status(job_handle)

Queue Management

  • Each task on the queue is associated with an 'owner', 'job' and 'id'
  • Each job has a priority (0=highest).
  • An 'owner' has a queue of 'job' which is a list of tasks.
  • Status is tracked per job.
  • Tasks within a job can be weighted.

Finding the next task to run

  1. Get the next owner with the highest priority subject
  2. Get the next job within the above owner with the highest priority
  3. Pop the next task off the job queue.
  4. Push the job to the end of the owners job queue.
  5. Push the owner to the end of the queue.

Worker Managment

  • The actual workers are implimented using passenger.
  • The queue calls the passenger server(s) through HTTP.
  • The queue limits the number of simultaneous workers at any one time.
  • Using passenger to manage the workers means workers are efficiently re-used, with a full Rails enviroment loaded and ready to go.
  • The status of the task is streamed to the queue manager.

Contributing to background_queue

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2012 MarkPent. See LICENSE.txt for further details.