# Bj-1.0.0

**URL:** <https://www.ruby-forum.com/t/bj-1-0-0/124485>\
**Category:** Ruby\
**Created:** [December 29, 2007, 4:08am UTC](https://www.ruby-forum.com/t/bj-1-0-0/124485 "2007-12-29T04:08:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 29, 2007, 4:08am UTC](https://www.ruby-forum.com/t/bj-1-0-0/124485/1 "2007-12-29T04:08:06Z")

</div>

NAME  
bj

SYNOPSIS  
bj (migration\_code|generate\_migration|migrate|setup|plugin|run|  
submit|list|set|config|pid) [options]+

HISTORY  
1.0.0:  
- use full path to ruby for plugin mode  
- plugin correctly installs bin --\>\> script  
- plugin install uses --force  
- properly quote paths in windows (spaces)  
- switch win signal to ABRT (was INT)  
- background job regrestration now uses ppid to pin the  
subprocess to a  
parent  
- use ppid to detect parent death and exit in event loop  
- don’t use gem dependanices in plugin as they are broken when  
loading from  
muliple gem repos  
- added a small amount of drb magic that allows signals to work  
across  
processes even on windows (see [http://drawohara.com/post/](http://drawohara.com/post/)  
22540307)

DESCRIPTION

* * *

## Overview

Backgroundjob (Bj) is a brain dead simple zero admin background  
priority queue  
for Rails. Bj is robust, platform independent (including  
windows), and  
supports internal or external manangement of the background runner  
process.

Jobs can be submitted to the queue directly using the api or from  
the command  
line using the ./script/bj:

```
 api:
   Bj.submit 'cat /etc/password'

 command line:
   bj submit cat /etc/password

```

Bj’s priority queue lives in the database and is therefore durable

- your jobs  
will live across an app crash or machine reboot. The job  
management is  
comprehensive capturing stdout, stderr, exit\_status, and temporal  
statistics  
about each job:

[codeforpeople.rubyforge.org/svn/rails/plugins/bj](http://codeforpeople.rubyforge.org/svn/rails/plugins/bj)  
2) ./script/bj setup

```
   gem:
     1) $sudo gem install bj
     2) add "require 'bj'" to config/environment.rb
     3) bj setup

```

* * *

## Api

submit jobs for background processing. ‘jobs’ can be a string or  
array of  
strings. options are applied to each job in the ‘jobs’, and the  
list of  
submitted jobs is always returned. options (string or symbol) can be

```
 :rails_env => production|development|key_in_database_yml
               when given this keyword causes bj to submit jobs

```

to the  
specified database. default is RAILS\_ENV.

```
 :priority => any number, including negative ones. default is zero.

 :tag => a tag added to the job. simply makes searching easier.

 :env => a hash specifying any additional environment vars the

```

background  
process should have.

```
 :stdin => any stdin the background process should have. must

```

respond\_to  
to\_s

eg:

```
 jobs = Bj.submit 'echo foobar', :tag => 'simple job'

 jobs = Bj.submit '/bin/cat', :stdin => 'in the hat', :priority

```

=\> 42

```
 jobs = Bj.submit './script/runner ./scripts/a.rb', :rails_env =>

```

‘production’

```
 jobs = Bj.submit './script/runner /dev/stdin',
                  :stdin => 'p RAILS_ENV',
                  :tag => 'dynamic ruby code'

 jobs Bj.submit array_of_commands, :priority => 451

```

when jobs are run, they are run in RAILS\_ROOT. various attributes  
are  
available _only_ once the job has finished. you can check whether  
or not a  
job is finished by using the #finished method, which simple does a  
reload and  
checks to see if the exit\_status is non-nil.

```
 eg:

   jobs = Bj.submit list_of_jobs, :tag => 'important'
   ...

   jobs.each do |job|
     if job.finished?
       p job.exit_status
       p job.stdout
       p job.stderr
     end
   end

```

See lib/bj/api.rb for more details.

* * *

## Sponsors

```
 http://www.engineyard.com/
 http://quintess.com/
 http://eparklabs.com/

 http://your_company.com/ <<-- (targeted marketing aimed at

```

_you_)

* * *

## Version

1.0.0

PARAMETERS  
–rails\_root=rails\_root, -R (0 ~\> rails\_root=)  
the rails\_root will be guessed unless you set this  
–rails\_env=rails\_env, -E (0 ~\> rails\_env=development)  
set the rails\_env  
–log=log, -l (0 ~\> log=STDERR)  
set the logfile  
–help, -h

AUTHOR  
removed\_email\_address@domain.invalid

URIS  
[http://codeforpeople.com/lib/ruby/](http://codeforpeople.com/lib/ruby/)  
[http://rubyforge.org/projects/codeforpeople/](http://rubyforge.org/projects/codeforpeople/)  
[http://codeforpeople.rubyforge.org/svn/rails/plugins/](http://codeforpeople.rubyforge.org/svn/rails/plugins/)

enjoy.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)
