backgrounded 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/README.md +94 -0
- data/Rakefile +4 -7
- data/backgrounded.gemspec +24 -25
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/backgrounded.rb +21 -10
- data/lib/backgrounded/active_record_extension.rb +3 -4
- data/lib/backgrounded/{concern.rb → object_extensions.rb} +11 -9
- data/lib/backgrounded/proxy.rb +3 -3
- data/lib/backgrounded/railtie.rb +11 -0
- data/lib/backgrounded/version.rb +1 -1
- metadata +47 -91
- data/README.rdoc +0 -76
- data/test/active_record_extension_test.rb +0 -37
- data/test/backgrounded_test.rb +0 -45
- data/test/database.yml +0 -3
- data/test/proxy_test.rb +0 -51
- data/test/setup_database.rb +0 -13
- data/test/test_helper.rb +0 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a6f5f3fe616528faeebfbf52c4c954c022a7d37a
|
4
|
+
data.tar.gz: 1ffc6d954ba191ab3e8150620461d361d3672950
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab1d8af191a86879995c843c36000f46c7f7ec1a41a661db4b2ab47228061edf1e8e635a11caa67883df4477dd1599e3e8c71e809df74ed632b403c4113840cb
|
7
|
+
data.tar.gz: 41ac8e66f7a5eb18a7722688553e380e4f9acf1dc24e2f0ea8ffbca43b4e506b10186fc4df5a9af86c32d01d241db5921c7b445a7620c0d244884560f876a907
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/wireframe/backgrounded.png?branch=master)](https://travis-ci.org/wireframe/backgrounded)
|
2
|
+
# Backgrounded
|
3
|
+
|
4
|
+
> The cleanest way to integrate background processing into your application.
|
5
|
+
|
6
|
+
Backgrounded provides a thin wrapper around any background processing
|
7
|
+
framework that implements the Backgrounded handler API which makes it
|
8
|
+
trivial to swap out processing frameworks with no impact to your code.
|
9
|
+
|
10
|
+
# Features
|
11
|
+
|
12
|
+
* clean and concise API which removes any dependency on external “worker”
|
13
|
+
jobs and allows you to execute any model method in the background
|
14
|
+
* integrates with any background processing framework (DelayedJob, Resque,
|
15
|
+
JobFu, Workling, etc)
|
16
|
+
* background methods can be actually unit tested by using an "in
|
17
|
+
process" runner
|
18
|
+
* custom callbacks to execute ActiveRecord callbacks in the background after
|
19
|
+
being committed to the database
|
20
|
+
|
21
|
+
# General Usage
|
22
|
+
|
23
|
+
|
24
|
+
class User
|
25
|
+
def do_stuff
|
26
|
+
end
|
27
|
+
def self.do_something_else
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
user = User.new
|
32
|
+
# execute instance method in background
|
33
|
+
user.backgrounded.do_stuff
|
34
|
+
|
35
|
+
# execute class method in background
|
36
|
+
User.backgrounded.do_something_else
|
37
|
+
|
38
|
+
# after_commit_backgrounded Callback
|
39
|
+
|
40
|
+
Automatically execute a callback in the background after a model has been
|
41
|
+
saved to the database. All of the standard after_commit options are
|
42
|
+
available as well as an optional :backgrounded option which will be passed
|
43
|
+
to the Backgrounded::Handler.
|
44
|
+
|
45
|
+
class User < ActiveRecord::Base
|
46
|
+
# execute :do_something in the background after committed
|
47
|
+
after_commit_backgrounded :do_something
|
48
|
+
|
49
|
+
# execute :do_something_else in the background after committed
|
50
|
+
# passing custom options to the backgrounded handler
|
51
|
+
after_commit_backgrounded :do_something_else, :backgrounded => {:priority => :high}
|
52
|
+
end
|
53
|
+
|
54
|
+
# Installation
|
55
|
+
|
56
|
+
$ gem install backgrounded
|
57
|
+
|
58
|
+
# Configuration
|
59
|
+
|
60
|
+
Backgrounded handlers are available for popular libraries in separate gems.
|
61
|
+
Just drop in the gem for your particular framework or write your own!
|
62
|
+
|
63
|
+
## Resque
|
64
|
+
|
65
|
+
see [github.com/wireframe/backgrounded-resque](http://github.com/wireframe/backgrounded-resque)
|
66
|
+
|
67
|
+
## JobFu
|
68
|
+
|
69
|
+
see [github.com/jnstq/job_fu/tree](http://github.com/jnstq/job_fu/tree)
|
70
|
+
|
71
|
+
## Custom Handlers
|
72
|
+
|
73
|
+
Writing a custom handler is as simple as:
|
74
|
+
|
75
|
+
# config/initializers/backgrounded.rb
|
76
|
+
class MyHandler
|
77
|
+
# @param object is the target object to invoke the method upon
|
78
|
+
# @param method is the requested method to call
|
79
|
+
# @param args is the optional list of arguments to pass to the method
|
80
|
+
# @param options is the optional hash of options passed to the backgrounded call
|
81
|
+
def request(object, method, args, options={})
|
82
|
+
# process the call however you want!
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# configure backgrounded to use your handler like so:
|
87
|
+
Backgrounded.configure do |config|
|
88
|
+
config.handler = MyHandler.new
|
89
|
+
end
|
90
|
+
|
91
|
+
## Copyright
|
92
|
+
|
93
|
+
Copyright © 2012 Ryan Sonnek. See LICENSE for details.
|
94
|
+
|
data/Rakefile
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
test.verbose = true
|
9
|
-
end
|
10
|
-
task :default => :test
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
task :default => :spec
|
data/backgrounded.gemspec
CHANGED
@@ -1,30 +1,29 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'backgrounded/version'
|
4
5
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
s.email = ["ryan@codecrate.com"]
|
11
|
-
s.homepage = "http://github.com/wireframe/backgrounded"
|
12
|
-
s.summary = %q{Simple API to perform work in the background}
|
13
|
-
s.description = %q{Execute any ActiveRecord Model method in the background}
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'backgrounded'
|
8
|
+
spec.version = Backgrounded::VERSION
|
9
|
+
spec.authors = ['Ryan Sonnek']
|
10
|
+
spec.email = ['ryan@codecrate.com']
|
14
11
|
|
15
|
-
|
12
|
+
spec.summary = %q{Simple API to perform work in the background}
|
13
|
+
spec.description = %q{Execute any ActiveRecord Model method in the background}
|
14
|
+
spec.homepage = 'http://github.com/wireframe/backgrounded'
|
16
15
|
|
17
|
-
|
18
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.10"])
|
19
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
20
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
21
|
-
s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.3.2"])
|
22
|
-
s.add_development_dependency(%q<rake>, [">= 0.9.2.2"])
|
23
|
-
s.add_development_dependency(%q<pry>, [">= 0.9.12"])
|
24
|
-
s.add_development_dependency(%q<test_after_commit>, [">= 0"])
|
16
|
+
spec.add_runtime_dependency 'rails', '>= 3.0.0'
|
25
17
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
19
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
20
|
+
spec.add_development_dependency 'rspec', "~> 3.0"
|
21
|
+
spec.add_development_dependency 'sqlite3-ruby', '>= 1.3.2'
|
22
|
+
spec.add_development_dependency 'pry', '>= 0.9.12'
|
23
|
+
spec.add_development_dependency 'test_after_commit'
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
30
29
|
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "backgrounded"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/backgrounded.rb
CHANGED
@@ -1,18 +1,29 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require File.join(File.dirname(__FILE__), 'backgrounded', 'active_record_extension')
|
1
|
+
require 'logger'
|
2
|
+
require_relative 'backgrounded/handler/inprocess_handler'
|
3
|
+
require_relative 'backgrounded/object_extensions'
|
4
|
+
require_relative 'backgrounded/railtie' if defined?(Rails)
|
6
5
|
|
7
6
|
module Backgrounded
|
8
7
|
class << self
|
9
8
|
attr_accessor :logger, :handler
|
9
|
+
|
10
|
+
def configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
self
|
16
|
+
end
|
10
17
|
end
|
11
18
|
end
|
12
19
|
|
13
|
-
# default
|
14
|
-
Backgrounded.
|
20
|
+
# default library configuration
|
21
|
+
Backgrounded.configure do |config|
|
22
|
+
# default handler to the basic in process handler
|
23
|
+
config.handler = Backgrounded::Handler::InprocessHandler.new
|
15
24
|
|
16
|
-
# configure default logger to standard out with info log level
|
17
|
-
|
18
|
-
|
25
|
+
# configure default logger to standard out with info log level
|
26
|
+
logger = Logger.new(STDOUT)
|
27
|
+
logger.level = Logger::INFO
|
28
|
+
config.logger = logger
|
29
|
+
end
|
@@ -1,19 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support/concern'
|
2
2
|
|
3
3
|
module Backgrounded
|
4
4
|
module ActiveRecordExtension
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
|
7
|
+
class_methods do
|
8
8
|
# execute a method in the background after the object is committed to the database
|
9
9
|
# @option options [Hash] :backgrounded (optional) options to pass into the backgrounded handler
|
10
10
|
# @see after_commit
|
11
11
|
def after_commit_backgrounded(method_name, options={})
|
12
|
-
|
12
|
+
after_commit options.except(:backgrounded) do |instance|
|
13
13
|
instance.backgrounded(options[:backgrounded]).send(method_name)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
ActiveRecord::Base.send(:include, Backgrounded::ActiveRecordExtension)
|
@@ -1,20 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require 'active_support/concern'
|
2
|
+
require_relative 'proxy'
|
2
3
|
|
3
4
|
module Backgrounded
|
4
|
-
|
5
|
+
# mixin to add backgrounded proxy builder to all ruby objects
|
6
|
+
module ObjectExtensions
|
5
7
|
extend ActiveSupport::Concern
|
6
8
|
|
7
|
-
|
9
|
+
# @param options (optional) options to pass into the backgrounded handler
|
10
|
+
def backgrounded(options={})
|
11
|
+
Backgrounded::Proxy.new self, options
|
12
|
+
end
|
13
|
+
|
14
|
+
class_methods do
|
8
15
|
# @see Backgrounded::Concern#backgrounded
|
9
16
|
def backgrounded(options={})
|
10
17
|
Backgrounded::Proxy.new self, options
|
11
18
|
end
|
12
19
|
end
|
13
|
-
|
14
|
-
# @param options (optional) options to pass into the backgrounded handler
|
15
|
-
def backgrounded(options={})
|
16
|
-
Backgrounded::Proxy.new self, options
|
17
|
-
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
Object.send(:include, Backgrounded::
|
22
|
+
Object.send(:include, Backgrounded::ObjectExtensions)
|
data/lib/backgrounded/proxy.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Backgrounded
|
2
|
-
attr_reader :delegate, :options
|
3
2
|
class Proxy
|
3
|
+
attr_reader :delegate, :options
|
4
4
|
def initialize(delegate, options={})
|
5
5
|
@delegate = delegate
|
6
6
|
@options = options || {}
|
7
7
|
end
|
8
8
|
|
9
9
|
def method_missing(method_name, *args)
|
10
|
-
Backgrounded.logger.debug("Requesting #{Backgrounded.handler} backgrounded method: #{method_name} for instance #{
|
11
|
-
Backgrounded.handler.request(
|
10
|
+
Backgrounded.logger.debug("Requesting #{Backgrounded.handler} backgrounded method: #{method_name} for instance #{delegate} with options: #{options}")
|
11
|
+
Backgrounded.handler.request(delegate, method_name, args, options)
|
12
12
|
nil
|
13
13
|
end
|
14
14
|
end
|
data/lib/backgrounded/version.rb
CHANGED
metadata
CHANGED
@@ -1,142 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backgrounded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ryan Sonnek
|
9
8
|
autorequire:
|
10
|
-
bindir:
|
9
|
+
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 3.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 3.0.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
38
|
-
type: :
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: '1.11'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
47
|
+
version: '10.0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
54
|
+
version: '10.0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
56
|
+
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
61
|
+
version: '3.0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
68
|
+
version: '3.0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: sqlite3-ruby
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: 1.3.2
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: 1.3.2
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: rake
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 0.9.2.2
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 0.9.2.2
|
110
83
|
- !ruby/object:Gem::Dependency
|
111
84
|
name: pry
|
112
85
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
86
|
requirements:
|
115
|
-
- -
|
87
|
+
- - ">="
|
116
88
|
- !ruby/object:Gem::Version
|
117
89
|
version: 0.9.12
|
118
90
|
type: :development
|
119
91
|
prerelease: false
|
120
92
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
93
|
requirements:
|
123
|
-
- -
|
94
|
+
- - ">="
|
124
95
|
- !ruby/object:Gem::Version
|
125
96
|
version: 0.9.12
|
126
97
|
- !ruby/object:Gem::Dependency
|
127
98
|
name: test_after_commit
|
128
99
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
100
|
requirements:
|
131
|
-
- -
|
101
|
+
- - ">="
|
132
102
|
- !ruby/object:Gem::Version
|
133
103
|
version: '0'
|
134
104
|
type: :development
|
135
105
|
prerelease: false
|
136
106
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
107
|
requirements:
|
139
|
-
- -
|
108
|
+
- - ">="
|
140
109
|
- !ruby/object:Gem::Version
|
141
110
|
version: '0'
|
142
111
|
description: Execute any ActiveRecord Model method in the background
|
@@ -146,60 +115,47 @@ executables: []
|
|
146
115
|
extensions: []
|
147
116
|
extra_rdoc_files: []
|
148
117
|
files:
|
149
|
-
- .gitignore
|
150
|
-
- .
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rvmrc"
|
121
|
+
- ".travis.yml"
|
151
122
|
- Gemfile
|
152
123
|
- LICENSE
|
153
|
-
- README.
|
124
|
+
- README.md
|
154
125
|
- Rakefile
|
155
126
|
- backgrounded.gemspec
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
156
129
|
- lib/backgrounded.rb
|
157
130
|
- lib/backgrounded/active_record_extension.rb
|
158
|
-
- lib/backgrounded/concern.rb
|
159
131
|
- lib/backgrounded/handler/inprocess_handler.rb
|
160
132
|
- lib/backgrounded/handler/no_op_handler.rb
|
133
|
+
- lib/backgrounded/object_extensions.rb
|
161
134
|
- lib/backgrounded/proxy.rb
|
135
|
+
- lib/backgrounded/railtie.rb
|
162
136
|
- lib/backgrounded/version.rb
|
163
|
-
- test/active_record_extension_test.rb
|
164
|
-
- test/backgrounded_test.rb
|
165
|
-
- test/database.yml
|
166
|
-
- test/proxy_test.rb
|
167
|
-
- test/setup_database.rb
|
168
|
-
- test/test_helper.rb
|
169
137
|
homepage: http://github.com/wireframe/backgrounded
|
170
138
|
licenses: []
|
139
|
+
metadata: {}
|
171
140
|
post_install_message:
|
172
141
|
rdoc_options: []
|
173
142
|
require_paths:
|
174
143
|
- lib
|
175
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
-
none: false
|
177
145
|
requirements:
|
178
|
-
- -
|
146
|
+
- - ">="
|
179
147
|
- !ruby/object:Gem::Version
|
180
148
|
version: '0'
|
181
|
-
segments:
|
182
|
-
- 0
|
183
|
-
hash: -3451700657100239997
|
184
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
-
none: false
|
186
150
|
requirements:
|
187
|
-
- -
|
151
|
+
- - ">="
|
188
152
|
- !ruby/object:Gem::Version
|
189
153
|
version: '0'
|
190
|
-
segments:
|
191
|
-
- 0
|
192
|
-
hash: -3451700657100239997
|
193
154
|
requirements: []
|
194
|
-
rubyforge_project:
|
195
|
-
rubygems_version:
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.5.1
|
196
157
|
signing_key:
|
197
|
-
specification_version:
|
158
|
+
specification_version: 4
|
198
159
|
summary: Simple API to perform work in the background
|
199
|
-
test_files:
|
200
|
-
|
201
|
-
- test/backgrounded_test.rb
|
202
|
-
- test/database.yml
|
203
|
-
- test/proxy_test.rb
|
204
|
-
- test/setup_database.rb
|
205
|
-
- test/test_helper.rb
|
160
|
+
test_files: []
|
161
|
+
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
= Backgrounded
|
2
|
-
|
3
|
-
The cleanest way to integrate background processing into your application.
|
4
|
-
|
5
|
-
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.
|
6
|
-
|
7
|
-
= Features
|
8
|
-
* clean and concise API which removes any dependency on external "worker" jobs and allows you to execute any model method in the background
|
9
|
-
* integrates with any background processing framework (DelayedJob, Resque, JobFu, Workling, etc)
|
10
|
-
* background methods can be actually unit tested by using an 'in process' runner
|
11
|
-
* custom callbacks to execute ActiveRecord callbacks in the background after being committed to the database
|
12
|
-
|
13
|
-
= General Usage
|
14
|
-
|
15
|
-
class User
|
16
|
-
def do_stuff
|
17
|
-
end
|
18
|
-
def self.do_something_else
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
user = User.new
|
23
|
-
# execute instance method in background
|
24
|
-
user.backgrounded.do_stuff
|
25
|
-
|
26
|
-
# execute class method in background
|
27
|
-
User.backgrounded.do_something_else
|
28
|
-
|
29
|
-
= after_commit_backgrounded Callback
|
30
|
-
|
31
|
-
Automatically execute a callback in the background after a model has been saved to the database. All of the standard after_commit options are
|
32
|
-
available as well as an optional :backgrounded option which will be passed to the Backgrounded::Handler.
|
33
|
-
|
34
|
-
class User < ActiveRecord::Base
|
35
|
-
# execute :do_something in the background after committed
|
36
|
-
after_commit_backgrounded :do_something
|
37
|
-
|
38
|
-
# execute :do_something_else in the background after committed
|
39
|
-
# passing custom options to the backgrounded handler
|
40
|
-
after_commit_backgrounded :do_something_else, :backgrounded => {:priority => :high}
|
41
|
-
end
|
42
|
-
|
43
|
-
= Installation
|
44
|
-
|
45
|
-
Bundler Gemfile configuration
|
46
|
-
|
47
|
-
gem 'backgrounded'
|
48
|
-
|
49
|
-
= Configuration
|
50
|
-
|
51
|
-
Backgrounded handlers are available for popular libraries in separate gems. Just drop in the gem for your particular framework or write your own!
|
52
|
-
|
53
|
-
== Resque
|
54
|
-
see http://github.com/wireframe/backgrounded-resque
|
55
|
-
|
56
|
-
== JobFu
|
57
|
-
see http://github.com/jnstq/job_fu/tree
|
58
|
-
|
59
|
-
== Custom Handlers
|
60
|
-
Writing a custom handler is as simple as:
|
61
|
-
|
62
|
-
# config/initializers/backgrounded.rb
|
63
|
-
class MyHandler
|
64
|
-
# @param object is the target object to invoke the method upon
|
65
|
-
# @param method is the requested method to call
|
66
|
-
# @param args is the optional list of arguments to pass to the method
|
67
|
-
# @param options is the optional hash of options passed to the backgrounded call
|
68
|
-
def request(object, method, args, options={})
|
69
|
-
# process the call however you want!
|
70
|
-
end
|
71
|
-
end
|
72
|
-
Backgrounded.handler = MyHandler.new
|
73
|
-
|
74
|
-
== Copyright
|
75
|
-
|
76
|
-
Copyright (c) 2012 Ryan Sonnek. See LICENSE for details.
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class ActiveRecordExtensionTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
class Blog < ActiveRecord::Base
|
6
|
-
after_commit_backgrounded :do_something_else
|
7
|
-
def do_something_else
|
8
|
-
end
|
9
|
-
end
|
10
|
-
class User < ActiveRecord::Base
|
11
|
-
after_commit_backgrounded :do_stuff, :backgrounded => {:priority => :high}
|
12
|
-
def do_stuff
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context '.after_commit_backgrounded' do
|
17
|
-
should 'be defined on ActiveRecord::Base' do
|
18
|
-
assert ActiveRecord::Base.respond_to?(:after_commit_backgrounded)
|
19
|
-
end
|
20
|
-
context 'without options' do
|
21
|
-
setup do
|
22
|
-
@blog = Blog.new
|
23
|
-
Backgrounded.handler.expects(:request).with(@blog, :do_something_else, [], {})
|
24
|
-
@blog.save!
|
25
|
-
end
|
26
|
-
should 'invoke Backgrounded.handler with no options' do end # see expectations
|
27
|
-
end
|
28
|
-
context 'with options[:backgrounded]' do
|
29
|
-
setup do
|
30
|
-
@user = User.new
|
31
|
-
Backgrounded.handler.expects(:request).with(@user, :do_stuff, [], {:priority => :high})
|
32
|
-
@user.save!
|
33
|
-
end
|
34
|
-
should 'pass options[:backgrounded] to Backgrounded.handler' do end # see expectations
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/test/backgrounded_test.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class BackgroundedTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
class Dog
|
6
|
-
def do_stuff
|
7
|
-
end
|
8
|
-
def self.do_something_else
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context '#backgrounded' do
|
13
|
-
should 'be defined for class' do
|
14
|
-
assert Dog.respond_to?(:backgrounded)
|
15
|
-
end
|
16
|
-
should 'be defined for instance' do
|
17
|
-
assert Dog.new.respond_to?(:backgrounded)
|
18
|
-
end
|
19
|
-
context 'invoking on class' do
|
20
|
-
setup do
|
21
|
-
@result = Dog.backgrounded
|
22
|
-
end
|
23
|
-
should 'return instance of Backgrounded::Proxy' do
|
24
|
-
assert @result.is_a?(Backgrounded::Proxy)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
context 'invoking on an instance' do
|
28
|
-
setup do
|
29
|
-
@dog = Dog.new
|
30
|
-
@result = @dog.backgrounded
|
31
|
-
end
|
32
|
-
should 'return instance of Backgrounded::Proxy' do
|
33
|
-
assert @result.is_a?(Backgrounded::Proxy)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
context 'invoking with options' do
|
37
|
-
setup do
|
38
|
-
@dog = Dog.new
|
39
|
-
Backgrounded.handler.expects(:request).with(@dog, :do_stuff, [], {:priority => :high})
|
40
|
-
@dog.backgrounded(:priority => :high).do_stuff
|
41
|
-
end
|
42
|
-
should 'pass options onto Backgrounded.handler' do end # see expectations
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/test/database.yml
DELETED
data/test/proxy_test.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class ProxyTest < Test::Unit::TestCase
|
4
|
-
class Person
|
5
|
-
def self.do_something_else
|
6
|
-
end
|
7
|
-
def do_stuff(name, place, location)
|
8
|
-
end
|
9
|
-
def do_stuff_without_arguments
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'invoking delegate method' do
|
14
|
-
context 'with arguments and options' do
|
15
|
-
setup do
|
16
|
-
@delegate = Person.new
|
17
|
-
Backgrounded.handler.expects(:request).with(@delegate, :do_stuff, ['foo', 1, 'bar'], {:option_one => 'alpha'})
|
18
|
-
@proxy = Backgrounded::Proxy.new @delegate, :option_one => 'alpha'
|
19
|
-
@result = @proxy.do_stuff 'foo', 1, 'bar'
|
20
|
-
end
|
21
|
-
should "invokes Backgrounded.handler with delegate, method and args" do end #see expectations
|
22
|
-
should 'return nil' do
|
23
|
-
assert_nil @result
|
24
|
-
end
|
25
|
-
end
|
26
|
-
context 'with arguments' do
|
27
|
-
setup do
|
28
|
-
@delegate = Person.new
|
29
|
-
Backgrounded.handler.expects(:request).with(@delegate, :do_stuff, ['foo', 1, 'bar'], {})
|
30
|
-
@proxy = Backgrounded::Proxy.new @delegate
|
31
|
-
@result = @proxy.do_stuff 'foo', 1, 'bar'
|
32
|
-
end
|
33
|
-
should "invokes Backgrounded.handler with delegate, method and args" do end #see expectations
|
34
|
-
should 'return nil' do
|
35
|
-
assert_nil @result
|
36
|
-
end
|
37
|
-
end
|
38
|
-
context 'with no arguments' do
|
39
|
-
setup do
|
40
|
-
@delegate = Person.new
|
41
|
-
Backgrounded.handler.expects(:request).with(@delegate, :do_stuff_without_arguments, [], {})
|
42
|
-
@proxy = Backgrounded::Proxy.new @delegate
|
43
|
-
@result = @proxy.do_stuff_without_arguments
|
44
|
-
end
|
45
|
-
should "invokes Backgrounded.handler with delegate, method and args" do end #see expectations
|
46
|
-
should 'return nil' do
|
47
|
-
assert_nil @result
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/test/setup_database.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
|
2
|
-
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
3
|
-
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
|
4
|
-
|
5
|
-
ActiveRecord::Schema.define(:version => 1) do
|
6
|
-
create_table :blogs, :force => true do |t|
|
7
|
-
t.column :title, :string
|
8
|
-
t.column :body, :string
|
9
|
-
end
|
10
|
-
create_table :users, :force => true do |t|
|
11
|
-
t.column :name, :string
|
12
|
-
end
|
13
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
require 'pry'
|
13
|
-
require 'mocha'
|
14
|
-
require 'active_record'
|
15
|
-
|
16
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
18
|
-
require 'backgrounded'
|
19
|
-
require 'setup_database'
|
20
|
-
|
21
|
-
Backgrounded.logger.level = Logger::DEBUG
|
22
|
-
|
23
|
-
class Test::Unit::TestCase
|
24
|
-
end
|