Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

marius/workerd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Workerd
=======

Workerd is a Ruby on Rails plugin which helps running tasks in the background.
It is inspired by Bart ten Brinke's worker_queue.

Installation
============

cd your_rails_app
rails plugin install git://github.com/marius/workerd.git
rails generate workerd_migration
rake db:migrate

Example
=======

Create a background job:
Workerd::Workpiece.create(:class_name => 'Model', :method_name => 'method')

This new job will get picked up by a worker and he will execute Model.method
with no arguments. You can add arguments with the :method_arguments
option, e.g. :method_arguments => [17, 'foo', Time.now] or
:method_arguments => [[42, :symbol]] or :method_arguments => [1].
The method_arguments array will be converted into the actual method arguments
with the splat operator, so it has to be an array.

Run one worker in foreground during development:
rake workerd:run

Start one worker in background:
rake workerd:start
Stop it:
rake workerd:stop

Customization
=============

You can easily create your own jobs with advanced features by inheriting from
Workerd::Workpiece and adding a `type` column.
For example you can then define a column `progress` as an integer in your
database. After this you can use it from your foreground and background code:

# in a normal rails request
job = MyJob.create(:class_name => 'Foo', :method_name => 'bar')

# in an AJAX request
render :text => job.progress

# in Foo.bar
Workerd.current_workpiece.progess = 77
Workerd.current_workpiece.save!

Todo
====
 * Add pidfile management to support more than one worker
 * Convert to gem

Copyright (c) 2010 Marius Nuennerich, released under the MIT license

About

A simple background worker for ruby on rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages