activequeue 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +28 -0
- data/lib/active_queue/adapters/delayed_job_adapter.rb +15 -0
- data/lib/active_queue/adapters/dummy_adapter.rb +16 -0
- data/lib/active_queue/adapters/resque_adapter.rb +17 -0
- data/lib/active_queue/jobs.rb +10 -0
- data/lib/activequeue.rb +23 -0
- data/test/helper.rb +10 -0
- metadata +60 -0
data/README.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ActiveQueue
|
2
|
+
======
|
3
|
+
|
4
|
+
ActiveQueue is a Rails abstraction of queue configuration and background job creation/specification.
|
5
|
+
|
6
|
+
Queues and Background Job Runners are becoming as ubiquitous to Rails applications as Databases. Why not treat each of them as the same generic component, conforming to an interface and convention that is well understood.
|
7
|
+
|
8
|
+
Overview
|
9
|
+
--------
|
10
|
+
ActiveQueue allows you to create jobs and place them on whatever queue you have set as a requirement in
|
11
|
+
environment.rb. The first cut of this gem only supports DelayedJob and Resque. Background jobs can be any Ruby class or module that responds to perform. Your existing classes can easily be converted to background jobs or you can create new classes specifically to do work. Or, you can do both.
|
12
|
+
|
13
|
+
I place job classes withina Jobs module in models/jobs.rb and like so:
|
14
|
+
|
15
|
+
module Jobs
|
16
|
+
class ExampleJob < Struct.new(:foo)
|
17
|
+
def perform
|
18
|
+
# perform magically delicious task
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
With ActiveQueue you can send any job to the configured queue like so
|
24
|
+
|
25
|
+
ActiveQueue::Queue.enqueue(Jobs::ExampleJob,'bar')
|
26
|
+
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module ActiveQueue::Adapters::DelayedJobAdapter
|
3
|
+
#Background jobs can be any Ruby class or module that responds to perform.
|
4
|
+
#Your existing classes can easily be converted to background jobs or
|
5
|
+
#you can create new classes specifically to do work.
|
6
|
+
#Or, you can do both.
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
module ClassMethods
|
11
|
+
def enqueue(job_runner_klass, options = { })
|
12
|
+
Delayed::Job.enqueue(job_runner_klass.new(options))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveQueue::Adapters::DummyAdapter
|
2
|
+
|
3
|
+
#Background jobs can be any Ruby class or module that responds to perform.
|
4
|
+
#Your existing classes can easily be converted to background jobs or
|
5
|
+
#you can create new classes specifically to do work.
|
6
|
+
#Or, you can do both.
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
module ClassMethods
|
11
|
+
def enqueue(job_runner_klass, options = { })
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
module ActiveQueue::Adapters::ResqueAdapter
|
3
|
+
|
4
|
+
#Background jobs can be any Ruby class or module that responds to perform.
|
5
|
+
#Your existing classes can easily be converted to background jobs or
|
6
|
+
#you can create new classes specifically to do work.
|
7
|
+
#Or, you can do both.
|
8
|
+
def self.included(base)
|
9
|
+
base.extend(ClassMethods)
|
10
|
+
end
|
11
|
+
module ClassMethods
|
12
|
+
def enqueue(job_runner_klass, options = { })
|
13
|
+
Resque.enqueue(job_runner_klass, options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/activequeue.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
Dir[File.join(File.dirname(__FILE__), 'active_queue','*.rb')].each{|f| require f }
|
3
|
+
|
4
|
+
module ActiveQueue
|
5
|
+
def self.adapters
|
6
|
+
ActiveQueue::Adapters
|
7
|
+
end
|
8
|
+
module Adapters
|
9
|
+
|
10
|
+
end
|
11
|
+
Dir[File.join(File.dirname(__FILE__), 'active_queue', '*','*.rb')].each{|f| require f }
|
12
|
+
class Queue
|
13
|
+
|
14
|
+
if defined? Resque
|
15
|
+
include ActiveQueue::Adapters::ResqueAdapter
|
16
|
+
elsif defined? Delayed
|
17
|
+
include ActiveQueue::Adapters::DelayedJobAdapter
|
18
|
+
else
|
19
|
+
include ActiveQueue::Adapters::DummyAdapter
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activequeue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Jording
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-31 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Queues and Background Job Runners are becoming as ubiquitous to Rails applications as Databases. Why not treat each of them as the same generic component, conforming to an interface and convention that is well understood.
|
17
|
+
email: mjording@opengotham.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- lib/active_queue/adapters/delayed_job_adapter.rb
|
26
|
+
- lib/active_queue/adapters/dummy_adapter.rb
|
27
|
+
- lib/active_queue/adapters/resque_adapter.rb
|
28
|
+
- lib/active_queue/jobs.rb
|
29
|
+
- lib/activequeue.rb
|
30
|
+
- README.markdown
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/opengotham/active_queue
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.3.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: ActiveQueue is a Rails abstraction of queue configuration and background job creation/specification.
|
59
|
+
test_files:
|
60
|
+
- test/helper.rb
|