Code Monkey home page Code Monkey logo

workerd's Introduction

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

workerd's People

Contributors

marius avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gauda

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.