resque-queueable 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +27 -0
- data/lib/resque-queueable/version.rb +3 -0
- data/lib/resque-queueable.rb +49 -0
- metadata +124 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= Resque Queueable
|
2
|
+
|
3
|
+
== Overview
|
4
|
+
|
5
|
+
This gem extends ActiveRecord and Resque to add an automatic queue to any persisted model. Simply mark the model as 'queueable' and then call methods on the queue.
|
6
|
+
|
7
|
+
Assumption is that you have a working knowledge of Resque, because it is awesome:
|
8
|
+
|
9
|
+
http://github.com/defunkt/resque
|
10
|
+
|
11
|
+
To get it, just drop in the gem and you're good to go:
|
12
|
+
|
13
|
+
gem 'resque-queueable', :git => "http://github.com/kimos/resque-queueable"
|
14
|
+
|
15
|
+
|
16
|
+
== Example Usage
|
17
|
+
|
18
|
+
The following is the old boring way:
|
19
|
+
|
20
|
+
class Pie < ActiveRecord::Base
|
21
|
+
def describe(adj)
|
22
|
+
"This pie is #{adj}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def async_describe(adj)
|
26
|
+
Resque.enque(self.class, self.id, :describe, adj)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.perform(id, method, *args)
|
30
|
+
self.find(id).send(method, args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Pie.last.async_describe "delicious"
|
35
|
+
|
36
|
+
It can be replaced with:
|
37
|
+
|
38
|
+
class Pie < ActiveRecord::Base
|
39
|
+
resqueable
|
40
|
+
|
41
|
+
def describe(adj)
|
42
|
+
"This pie is #{adj}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Pie.last.queue.describe "delicious"
|
47
|
+
|
48
|
+
Shiny.
|
49
|
+
|
50
|
+
|
51
|
+
== The Usual
|
52
|
+
|
53
|
+
Author: Kevin McPhillips - github@kevinmcphillips.ca
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ResqueQueueable'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ResqueQueueable
|
2
|
+
|
3
|
+
class InvalidQueue < StandardError ; end
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def resqueable(queue)
|
11
|
+
@queue = queue
|
12
|
+
|
13
|
+
include InstanceMethods
|
14
|
+
extend SingletonMethods
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
def queue
|
21
|
+
raise InvalidQueue, "Cannot access a queue for an unsaved record" unless self.id
|
22
|
+
Queue.new(self.class, self.id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module SingletonMethods
|
27
|
+
def perform(id, method, *args)
|
28
|
+
# Idle workers lose their DB connection sometimes. This makes sure we have a good connection for each run.
|
29
|
+
ActiveRecord::Base.reconnect! if ActiveRecord::Base.respond_to? :reconnect!
|
30
|
+
find(id).send(method, *args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Queue
|
35
|
+
attr_accessor :klass, :id
|
36
|
+
|
37
|
+
def initialize(klass, id)
|
38
|
+
@klass = klass
|
39
|
+
@id = id
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(method, *args)
|
43
|
+
Resque.enqueue(klass, id, method, *args)
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
ActiveRecord::Base.send :include, ResqueQueueable
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-queueable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kevin McPhillips
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &81788500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *81788500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activerecord
|
27
|
+
requirement: &81787870 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *81787870
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
requirement: &81787140 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *81787140
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: resque
|
49
|
+
requirement: &81786390 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.15.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *81786390
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: &81785810 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *81785810
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: &81785240 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *81785240
|
80
|
+
description: An Active Record model can be defined as 'queueable'. That adds extensions
|
81
|
+
to add any method to the queue that exists on the method instance.
|
82
|
+
email:
|
83
|
+
- github@kevinmcphillips.ca
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- lib/resque-queueable.rb
|
89
|
+
- lib/resque-queueable/version.rb
|
90
|
+
- MIT-LICENSE
|
91
|
+
- Rakefile
|
92
|
+
- README.rdoc
|
93
|
+
homepage: http://github.com/kimos/resque-queueable
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
hash: -956583807
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -956583807
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.17
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Adds an easy interface to an Active Record model defined as queueable to
|
123
|
+
enque any methods.
|
124
|
+
test_files: []
|