Skip to content
forked from cblavier/jobbr

Rails engine to manage and supervise your batch jobs. Based on sidekiq.

License

Notifications You must be signed in to change notification settings

cprodhomme/jobbr

 
 

Repository files navigation

Jobbr

Jobbr is a Rails engine for supervising your delayed jobs and scheduled jobs (think Cron). Delayed jobs will run using sidekiq.

It provides a framework to abstract creation and execution of such jobs and a user interface to supervise jobs and read their logs.

<img src=“https://api.travis-ci.org/cblavier/jobbr.svg?branch=master” />

<img src=“https://codeclimate.com/github/cblavier/jobbr.png” />

<img src=“https://codeclimate.com/github/cblavier/jobbr/coverage.png” />

Screenshots

<img src=“http://f.cl.ly/items/0N0G3A3c2A1X2l2s3b3p/Capture%20d%E2%80%99%C3%A9cran%202013-02-12%20%C3%A0%2010.52.05.png” width=‘400’> <img src=“http://cl.ly/image/21433N411G01/Capture%20d%E2%80%99%C3%A9cran%202013-02-12%20%C3%A0%2010.55.13.png” width=‘400’>

Dependencies

Jobbr has strong dependencies on following components:

  • Sidekiq: the background processing framework used to run delayed jobs.

  • Redis: all jobs & logs are stored in Redis for supervision.

  • Whenever: Jobbr uses Whenever gem to automatically updates Crontab during deployment.

Setup

Start by adding Jobbr to your Gemfile:

gem 'jobbr'

User interface

Then mount Jobbr engine to your ‘routes.rb` file.

mount Jobbr::Engine => "/jobbr"

Scheduled Jobs

Use provided generators to create a first scheduled job

$> rails g jobbr:scheduled_job dummy

It will create a namespaced model as a well as a Whenever configuration file.

Provided you fill in description and scheduling attributes in the model, you will be able to see it in jobbr tasks:

$> bundle exec jobbr --list
bundle exec jobbr dummy_job  # A dummy Job

And to see it in your crontab preview:

$> whenever
30 5 * * * /bin/bash -l -c 'cd /Users/cblavier/code/my_app && RAILS_ENV=production bundle exec jobbr dummy_job >> /Users/cblavier/code/my_app/log/cron.log 2>&1'

Heroku Scheduled Jobs

You can also use Heroku Scheduler to run jobs. Unfortunately Heroku does not provide Cron-scheduling, but let you run jobs every 10 minutes, every hour or every day.

Jobbr provides you with 3 tasks ‘bundle exec jobbr heroku:minutely’, ‘bundle exec jobbr heroku:hourly’ and ‘bundle exec jobbr heroku:daily’, that will run any Job with ‘heroku_run` directive.

Then you will need to manually add jobs to the Heroku scheduler console

<img src=“http://cl.ly/image/2N1T1l1w2c28/Capture%20d%E2%80%99%C3%A9cran%202013-07-09%20%C3%A0%2022.18.40.png” width=‘400’>

Delayed Jobs

Use generators to get a new job model:

$> rails g jobbr:delayed_job dummy

You will get a new model with a perform method. Perform parameters are:

  • params: is a hash of parameters for your job.

  • run: is the object that will be persisted (and polled) for this job execution. Your delayed job can use it to provide progress information (to display a progress bar) and a final result.

    run.progress = 100
    run.result = 'my job result'
    

You can now run your delayed job as following:

run_id = DelayedJobs::DummyJob.run_delayed(some_param: 37)

And then get job status like this:

Jobbr::Run.find(run_id).status # returns :waiting / :running / :failed / :success

Jobbr also provides a controller to run and poll delayed_jobs :

  • Post on following url to run your job: delayed_job_creation_path(DelayedJobs::DummyJob, { some_param: 37 })

  • And then poll this url (using the id returned in previous post) to get your job status: delayed_job_polling_path(run_id)

This project rocks and uses MIT-LICENSE.

About

Rails engine to manage and supervise your batch jobs. Based on sidekiq.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 82.6%
  • Haml 6.8%
  • HTML 5.2%
  • CoffeeScript 1.7%
  • SCSS 1.5%
  • JavaScript 1.2%
  • CSS 1.0%