• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

simple background execution of model methods

Build Status

Backgrounded

The cleanest way to integrate background processing into your application.

Backgrounded provides a thin wrapper around any background processing framework that implements the Backgrounded handler API which makes it trivial to swap out processing frameworks with no impact to your code.

Features

  • clean and concise API which removes any dependency on external โ€œworkerโ€ jobs and allows you to execute any model method in the background
  • integrates with any background processing framework (DelayedJob, Resque, JobFu, Workling, etc)
  • background methods can be actually unit tested by using an "in process" runner
  • custom callbacks to execute ActiveRecord callbacks in the background after being committed to the database

General Usage

class User
  def do_stuff
  end
  def self.do_something_else
  end
end

user = User.new
# execute instance method in background
user.backgrounded.do_stuff

# execute class method in background
User.backgrounded.do_something_else

after_commit_backgrounded Callback

Automatically execute a callback in the background after a model has been saved to the database. All of the standard after_commit options are available as well as an optional :backgrounded option which will be passed to the Backgrounded::Handler.

class User < ActiveRecord::Base
  # execute :do_something in the background after committed
  after_commit_backgrounded :do_something

  # execute :do_something_else in the background after committed
  # passing custom options to the backgrounded handler
  after_commit_backgrounded :do_something_else, :backgrounded => {:priority => :high}
end

Installation

$ gem install backgrounded

Configuration

Backgrounded handlers are available for popular libraries in separate gems. Just drop in the gem for your particular framework or write your own!

Resque

see github.com/wireframe/backgrounded-resque

JobFu

see github.com/jnstq/job_fu/tree

Custom Handlers

Writing a custom handler is as simple as:

# config/initializers/backgrounded.rb
class MyHandler
  # @param object is the target object to invoke the method upon
  # @param method is the requested method to call
  # @param args is the optional list of arguments to pass to the method
  # @param options is the optional hash of options passed to the backgrounded call
  def request(object, method, args, options={})
    # process the call however you want!
  end
end

# configure backgrounded to use your handler like so:
Backgrounded.configure do |config|
  config.handler = MyHandler.new
end

Copyright

Copyright ยฉ 2012 Ryan Sonnek. See LICENSE for details.

More Repositories

1

multitenant

making cross tenant data leaks a thing of the past.
Ruby
162
star
2

bundler-updater

Interactively update your outdated gems
Ruby
102
star
3

email_prefixer

Ruby
41
star
4

email_preview

preview emails from within your web browser
Ruby
28
star
5

callback_skipper

skip activerecord callbacks
Ruby
18
star
6

factory_girl_rspec

integrate factory_girl directly into the RSpec DSL
Ruby
16
star
7

good_touch

Update timestamps without invoking ActiveRecord callbacks
Ruby
12
star
8

guard-jslint-on-rails

jslint-on-rails guard plugin
Ruby
12
star
9

rails-console-tweaks

Tweak rails console with more useful defaults
Ruby
9
star
10

iphoto_backup

export photos out of iPhoto for backups/archiving
Ruby
8
star
11

dotfiles

my dot files
Emacs Lisp
8
star
12

gitx

Git eXtensions for improved development workflows
Ruby
8
star
13

detect_browser_os

Ruby
7
star
14

delicious-chrome-extension

Google Chrome extension that integrates with Delicious bookmarks
JavaScript
7
star
15

zillow-chrome-extension

google chrome extension integrating with the Zillow real estate API along with google maps
JavaScript
7
star
16

bundler-reorganizer

Ruby
6
star
17

acts_as_stripped

simple utility to strip whitespace from model's string attributes
Ruby
6
star
18

twitteralerts

demo of twitter style alert messages for Ruby on Rails
Ruby
4
star
19

power-card-viewer

iPhone app for browsing DnD 4e power cards
JavaScript
4
star
20

testdox-maven-plugin

maven plugin for generating testdox report
Java
3
star
21

growl-air

growl-like notifications for adobe air applications
JavaScript
3
star
22

sublime-spec-focuser

Sublime Text plugin for toggling focus on currently selected spec
Python
3
star
23

canvas-mapper

4e mapping utility built on Javascript and Canvas
JavaScript
3
star
24

css_browser_selector

Gives the ability to write specific CSS code for each operating system and each browser from the backend or through JS.
Ruby
3
star
25

webstart-maven-plugin

Java
3
star
26

has_preferences

Ruby
2
star
27

wicketstuff-rome

Wicket component for integrating with ROME RSS/Atom feeds
2
star
28

shard

open gaming engine
Java
2
star
29

jruby-redcloth

Ruby
2
star
30

rspec-respect_selector_limit

RSpec matcher for validating number of CSS selectors
Ruby
2
star
31

jquery-relative-timestamp

clientside rendering of relative timestamps
2
star
32

wicketstuff-scriptaculous

Wicket integration with the Scriptaculous javascript library
2
star
33

backgrounded_mail

send email in background
Ruby
2
star
34

backgrounded-resque

Backgrounded handler for enqueing jobs into resque
Ruby
2
star
35

wicketstuff-hibernate-behavior

Wicket component for autowiring based on Hibernate annotations
1
star
36

jquery-disable

jquery extension to enable/disable elements
JavaScript
1
star
37

true_test

Ruby
1
star
38

ensure_connected

ensure database connection is valid before performing work
Ruby
1
star
39

email-validator

validate email attribute on activerecord object
Ruby
1
star
40

wireframe.github.com

JavaScript
1
star
41

yard-restfuldoc-plugin

YARD Documentation plugin for generating docs for REST API's
Ruby
1
star
42

rspec-lintable

Ruby
1
star
43

mailinator-chrome-extension

Google Chrome extension for generating one-time use email addresses
JavaScript
1
star
44

tokentracker

realtime collaboration app for tracking board game tokens
JavaScript
1
star