[ANN] bj-0.0.2

NAME
bj

SYNOPSIS
bj (migration_code|generate_migration|migrate|setup|run|submit|list|
set|config|pid) [options]+

DESCRIPTION


Overview

Backgroundjob (Bj) is a simple to use background priority queue

for rails.
Although not yet tested on windows, the design of bj is such that
operation
should be possible on any operating system, including M$.

Jobs can be submitted to the queue directly using the api or from

the
commandline using the ‘bj’ script. For example

code:
    Bj.submit 'cat /etc/password'

  cli:
    bj submit cat /etc/password

When used from inside a rails application bj arranges that another

process
will always be running in the background to process the jobs that
you submit.
By using a separate process to run jobs bj does not impact the
resource
utilization of your rails application at all and enables several
very cool
features:

  1) Bj allows you to sumbit jobs to any of your configured

databases and,
in each case, spawns a separate background process to run jobs
from that
queue

    Bj.in :production do
      Bj.submit 'production_job.exe'
    end

    Bj.in :development do
      Bj.submit 'development_job.exe'
    end

  2) Although bj ensures that a process is always running to

process
your jobs, you can start a proces manually. This means that any
machine
capable of seeing your RAILS_ROOT can run jobs for your
application, allowing
one to setup a cluster of machines doing the work of a single
front end rails
applicaiton.


Install

Bj can be installed two ways: as a gem or as a plugin.

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

  plugin:
    1) ./script/plugin install 

http://codeforpeople.rubyforge.org/svn/rails/plugins/bj
2) ./script/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.

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/

PARAMETERS
–rails_root=rails_root, -R (0 ~> rails_root=/Users/ahoward/
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
[email protected]

URIS
http://codeforpeople.com/lib/ruby/
http://rubyforge.org/projects/codeforpeople/
http://codeforpeople.rubyforge.org/svn/rails/plugins/

On Wed, 12 Dec 2007, ara.t.howard wrote:

NAME
bj

Not exactly the best name… :slight_smile:

ara.t.howard,

I need to spawn uploading very large file uploads for a Rails app and
this looks like it would work for my purposes.

Could you confirm that? Thank you.

Cody S.

Eno wrote:

On Wed, 12 Dec 2007, ara.t.howard wrote:

NAME
bj

Not exactly the best name… :slight_smile:

Hey, if it works though you feel good, relaxed, you lean back in our
chair happy, with a stupid smile on your face just like. . .I think it’s
a great name

On Dec 13, 12:36 pm, Cody S. [email protected]
wrote:

ara.t.howard,

I need to spawn uploading very large file uploads for a Rails app and
this looks like it would work for my purposes.

Could you confirm that? Thank you.

Cody S.

Posted viahttp://www.ruby-forum.com/.
.
not really. spawn, backgrounddrb, and bj all serve very different
purposes. for better or worse the rail conversation seems to be
happening over here

http://groups.google.com/group/ruby-talk-google/browse_frm/thread/144e9b3644ffe88e#38b99ec30098b956

join in! :wink:

On 12/12/07, ara.t.howard [email protected] wrote:

NAME
bj

Hey Ara, sorry to post a ticket like this… rubyforge has been down
for me all day (local internet issues, no clue…) I had a few issues
using the plugin I wanted to mention before I forgot.

One is that freezing in the gems doesn’t really work because they try
to load each other. The ‘main’ gem has tries to load the ‘attributes’
gem, even if its frozen inside the bj plugin. Not a big deal since I
can just load the gems…

The more important issue is that your definition of #instance_methods
differs from the ruby core api (which includes an extra argument).
This breaks gems like aws-s3. Here’s a patch
(Parked at Loopia), but I’m not sure if it’ll break for
users on older versions of ruby. At any rate, just thought I’d let
you know.

Thanks for the library though. It seems like it’ll work a lot better
than my own job queue service…


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

On Dec 19, 4:44 pm, “Rick O.” [email protected] wrote:

On 12/12/07, ara.t.howard [email protected] wrote:

NAME
bj

Hey Ara, sorry to post a ticket like this… rubyforge has been down
for me all day (local internet issues, no clue…) I had a few issues
using the plugin I wanted to mention before I forgot.

thanks for tip rick!

One is that freezing in the gems doesn’t really work because they try
to load each other. The ‘main’ gem has tries to load the ‘attributes’
gem, even if its frozen inside the bj plugin. Not a big deal since I
can just load the gems…

yeah this bums me out and i haven’t found a good work around. i’m
playing with setting GEM_PATH now, but even that doesn’t really seem
to work ;-(

The more important issue is that your definition of #instance_methods
differs from the ruby core api (which includes an extra argument).
This breaks gems like aws-s3. Here’s a patch
(Parked at Loopia), but I’m not sure if it’ll break for
users on older versions of ruby. At any rate, just thought I’d let
you know.

thanks - that, and bunch of other stuff, is fixed in the new version -
due out today or tomorrow.

Thanks for the library though. It seems like it’ll work a lot better
than my own job queue service…

glad to hear you are liking it!

-a