Project

jobit

0.0
No commit activity in last 3 years
No release in over 3 years
Process background jobs in queue.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Jobit Build Status

Jobit helps to manage background jobs processing with job status and progress monitoring.

Installation

Add to your Gemfile and run the bundle command to install it.

gem "jobit"

Requires Ruby 1.9.2 or later.

Usage

Create jobs file app/model/jobit_items.rb and put your tasks there:

method JobitItems

  def job_without_output_task(arg)
    sleep 60
  end

  def job_with_output_task(arg1, arg2)
    add_message("job #{name} started\n")
    set_progress(10)
    sleep 60
    set_progress(80)
    add_message("job #{name} half complete\n")
    sleep 10
    add_message("job #{name} complete\n")
  end

end

Jobs should be defined as "job_name" + "_task" suffix:

def new_job_task
end

###Running worker to process the jobs queue

rake jobit:work

###Adding jobs to queue

#job will be added to queue and processed. After successful processing it will be destroyed
new_job = Jobit::Job.add("job_name", :job_without_output, 'val1')

#job will be added to queue and processed. After processing wont be destroyed so you can see outputs from it
new_job = Jobit::Job.add("job_name", :job_with_output, 'val1', 'val2'){{ :keep => true }}

###Monitoring job progress and responses

#returns nil if job not in queue
job = Jobit::Job.find_by_name('job_name')

job.status #current job status
job.message #job responses if job sent any
job.progress #job progress
job.error #job error if status is "failed"

###Monitoring job progress from your rails application

in routes.rb add:

mount Jobit::Engine => "/jobs"

now your can see a status of the job in your browser

http://127.0.0.1:3000/jobs/job_name

It will return the job with name "job_name" in json format

##Cleaning jobs

rake jobit:clear # destroying all jobs in the queue.
rake jobit:clear_failed # destroying only failed jobs in the queue.

More details coming soon