Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c9a4c2a5
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c9a4c2a5
编写于
9月 21, 2014
作者:
C
Cristian Bica
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added RDoc for each Active Job adapter
上级
3f39ac4e
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
194 addition
and
71 deletion
+194
-71
activejob/README.md
activejob/README.md
+5
-14
activejob/lib/active_job/queue_adapters.rb
activejob/lib/active_job/queue_adapters.rb
+34
-0
activejob/lib/active_job/queue_adapters/backburner_adapter.rb
...vejob/lib/active_job/queue_adapters/backburner_adapter.rb
+12
-2
activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb
...ejob/lib/active_job/queue_adapters/delayed_job_adapter.rb
+12
-2
activejob/lib/active_job/queue_adapters/inline_adapter.rb
activejob/lib/active_job/queue_adapters/inline_adapter.rb
+10
-2
activejob/lib/active_job/queue_adapters/qu_adapter.rb
activejob/lib/active_job/queue_adapters/qu_adapter.rb
+15
-2
activejob/lib/active_job/queue_adapters/que_adapter.rb
activejob/lib/active_job/queue_adapters/que_adapter.rb
+14
-2
activejob/lib/active_job/queue_adapters/queue_classic_adapter.rb
...ob/lib/active_job/queue_adapters/queue_classic_adapter.rb
+16
-2
activejob/lib/active_job/queue_adapters/resque_adapter.rb
activejob/lib/active_job/queue_adapters/resque_adapter.rb
+13
-2
activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb
activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb
+14
-2
activejob/lib/active_job/queue_adapters/sneakers_adapter.rb
activejob/lib/active_job/queue_adapters/sneakers_adapter.rb
+14
-2
activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb
...job/lib/active_job/queue_adapters/sucker_punch_adapter.rb
+17
-2
activejob/lib/active_job/queue_adapters/test_adapter.rb
activejob/lib/active_job/queue_adapters/test_adapter.rb
+11
-2
guides/source/active_job_basics.md
guides/source/active_job_basics.md
+7
-35
未找到文件。
activejob/README.md
浏览文件 @
c9a4c2a5
...
...
@@ -24,9 +24,9 @@ Set the queue adapter for Active Job:
```
ruby
ActiveJob
::
Base
.
queue_adapter
=
:inline
# default queue adapter
# Adapters currently supported: :backburner, :delayed_job, :qu, :que, :queue_classic,
# :resque, :sidekiq, :sneakers, :sucker_punch
```
Note: To learn how to use your preferred queueing backend see its adapter
documentation at ActiveJob::QueueAdapters.
Declare a job like so:
...
...
@@ -88,18 +88,9 @@ by default has been mixed into Active Record classes.
## Supported queueing systems
We currently have adapters for:
*
[
Backburner
](
https://github.com/nesquena/backburner
)
*
[
Delayed Job
](
https://github.com/collectiveidea/delayed_job
)
*
[
Qu
](
https://github.com/bkeepers/qu
)
*
[
Que
](
https://github.com/chanks/que
)
*
[
QueueClassic
](
https://github.com/ryandotsmith/queue_classic
)
*
[
Resque 1.x
](
https://github.com/resque/resque
)
*
[
Sidekiq
](
https://github.com/mperham/sidekiq
)
*
[
Sneakers
](
https://github.com/jondot/sneakers
)
*
[
Sucker Punch
](
https://github.com/brandonhilkert/sucker_punch
)
Active Job has built-in adapters for multiple queueing backends (Sidekiq,
Resque, Delayed Job and others). To get an up-to-date list of the adapters
see the API Documentation for
[
ActiveJob::QueueAdapters
](
http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html
)
.
## Auxiliary gems
...
...
activejob/lib/active_job/queue_adapters.rb
浏览文件 @
c9a4c2a5
module
ActiveJob
# == Active Job adapters
#
# Active Job has adapters for the following queueing backends:
#
# * {Backburner}[https://github.com/nesquena/backburner]
# * {Delayed Job}[https://github.com/collectiveidea/delayed_job]
# * {Qu}[https://github.com/bkeepers/qu]
# * {Que}[https://github.com/chanks/que]
# * {QueueClassic 2.x}[https://github.com/ryandotsmith/queue_classic/tree/v2.2.3]
# * {Resque 1.x}[https://github.com/resque/resque/tree/1-x-stable]
# * {Sidekiq}[http://sidekiq.org]
# * {Sneakers}[https://github.com/jondot/sneakers]
# * {Sucker Punch}[https://github.com/brandonhilkert/sucker_punch]
#
# #### Backends Features
#
# | | Async | Queues | Delayed | Priorities | Timeout | Retries |
# |-------------------|-------|--------|-----------|------------|---------|---------|
# | Backburner | Yes | Yes | Yes | Yes | Job | Global |
# | Delayed Job | Yes | Yes | Yes | Job | Global | Global |
# | Que | Yes | Yes | Yes | Job | No | Job |
# | Queue Classic | Yes | Yes | No* | No | No | No |
# | Resque | Yes | Yes | Yes (Gem) | Queue | Global | Yes |
# | Sidekiq | Yes | Yes | Yes | Queue | No | Job |
# | Sneakers | Yes | Yes | No | Queue | Queue | No |
# | Sucker Punch | Yes | Yes | No | No | No | No |
# | Active Job Inline | No | Yes | N/A | N/A | N/A | N/A |
# | Active Job | Yes | Yes | Yes | No | No | No |
#
# NOTE:
# Queue Classic does not support Job scheduling. However you can implement this
# yourself or you can use the queue_classic-later gem. See the documentation for
# ActiveJob::QueueAdapters::QueueClassicAdapter.
#
module
QueueAdapters
extend
ActiveSupport
::
Autoload
...
...
activejob/lib/active_job/queue_adapters/backburner_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -2,13 +2,23 @@
module
ActiveJob
module
QueueAdapters
# == Backburner adapter for Active Job
#
# Backburner is a beanstalkd-powered job queue that can handle a very
# high volume of jobs. You create background jobs and place them on
# multiple work queues to be processed later. Read more about
# Backburner {here}[https://github.com/nesquena/backburner].
#
# To use Backburner set the queue_adapter config to +:backburner+.
#
# Rails.application.config.active_job.queue_adapter = :backburner
class
BackburnerAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
Backburner
::
Worker
.
enqueue
JobWrapper
,
[
job
.
serialize
],
queue:
job
.
queue_name
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
delay
=
timestamp
-
Time
.
current
.
to_f
Backburner
::
Worker
.
enqueue
JobWrapper
,
[
job
.
serialize
],
queue:
job
.
queue_name
,
delay:
delay
end
...
...
activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -2,13 +2,23 @@
module
ActiveJob
module
QueueAdapters
# == Delayed Job adapter for Active Job
#
# Delayed::Job (or DJ) encapsulates the common pattern of asynchronously
# executing longer tasks in the background. Although DJ can have many
# storage backends one of the most used is based on Active Record.
# Read more about Delayed Job {here}[https://github.com/collectiveidea/delayed_job].
#
# To use Delayed Job set the queue_adapter config to +:delayed_job+.
#
# Rails.application.config.active_job.queue_adapter = :delayed_job
class
DelayedJobAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
JobWrapper
.
new
.
delay
(
queue:
job
.
queue_name
).
perform
(
job
.
serialize
)
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
JobWrapper
.
new
.
delay
(
queue:
job
.
queue_name
,
run_at:
Time
.
at
(
timestamp
)).
perform
(
job
.
serialize
)
end
end
...
...
activejob/lib/active_job/queue_adapters/inline_adapter.rb
浏览文件 @
c9a4c2a5
module
ActiveJob
module
QueueAdapters
# == Active Job Inline adapter
#
# When enqueueing jobs with the Inline adapter the job will be executed
# immediately.
#
# To use the Inline set the queue_adapter config to +:inline+.
#
# Rails.application.config.active_job.queue_adapter = :inline
class
InlineAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
Base
.
execute
(
job
.
serialize
)
end
def
enqueue_at
(
*
)
def
enqueue_at
(
*
)
#:nodoc:
raise
NotImplementedError
.
new
(
"Use a queueing backend to enqueue jobs in the future. Read more at https://github.com/rails/activejob"
)
end
end
...
...
activejob/lib/active_job/queue_adapters/qu_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -2,15 +2,28 @@
module
ActiveJob
module
QueueAdapters
# == Qu adapter for Active Job
#
# Qu is a Ruby library for queuing and processing background jobs. It is
# heavily inspired by delayed_job and Resque. Qu was created to overcome
# some shortcomings in the existing queuing libraries that we experienced.
# The advantages of Qu are: Multiple backends (redis, mongo), jobs are
# requeued when worker is killed, resque-like API.
#
# Read more about Que {here}[https://github.com/bkeepers/qu].
#
# To use Qu set the queue_adapter config to +:qu+.
#
# Rails.application.config.active_job.queue_adapter = :qu
class
QuAdapter
class
<<
self
def
enqueue
(
job
,
*
args
)
def
enqueue
(
job
,
*
args
)
#:nodoc:
Qu
::
Payload
.
new
(
klass:
JobWrapper
,
args:
[
job
.
serialize
]).
tap
do
|
payload
|
payload
.
instance_variable_set
(
:@queue
,
job
.
queue_name
)
end
.
push
end
def
enqueue_at
(
job
,
timestamp
,
*
args
)
def
enqueue_at
(
job
,
timestamp
,
*
args
)
#:nodoc:
raise
NotImplementedError
end
end
...
...
activejob/lib/active_job/queue_adapters/que_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -2,13 +2,25 @@
module
ActiveJob
module
QueueAdapters
# == Que adapter for Active Job
#
# Que is a high-performance alternative to DelayedJob or QueueClassic that
# improves the reliability of your application by protecting your jobs with
# the same ACID guarantees as the rest of your data. Que is a queue for
# Ruby and PostgreSQL that manages jobs using advisory locks.
#
# Read more about Que {here}[https://github.com/chanks/que].
#
# To use Que set the queue_adapter config to +:que+.
#
# Rails.application.config.active_job.queue_adapter = :que
class
QueAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
JobWrapper
.
enqueue
job
.
serialize
,
queue:
job
.
queue_name
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
JobWrapper
.
enqueue
job
.
serialize
,
queue:
job
.
queue_name
,
run_at:
Time
.
at
(
timestamp
)
end
end
...
...
activejob/lib/active_job/queue_adapters/queue_classic_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -2,13 +2,27 @@
module
ActiveJob
module
QueueAdapters
# == Queue Classic adapter for Active Job
#
# queue_classic provides a simple interface to a PostgreSQL-backed message
# queue. queue_classic specializes in concurrent locking and minimizing
# database load while providing a simple, intuitive developer experience.
# queue_classic assumes that you are already using PostgreSQL in your
# production environment and that adding another dependency (e.g. redis,
# beanstalkd, 0mq) is undesirable.
#
# Read more about Queue Classic {here}[https://github.com/ryandotsmith/queue_classic].
#
# To use Queue Classic set the queue_adapter config to +:queue_classic+.
#
# Rails.application.config.active_job.queue_adapter = :queue_classic
class
QueueClassicAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
build_queue
(
job
.
queue_name
).
enqueue
(
"
#{
JobWrapper
.
name
}
.perform"
,
job
.
serialize
)
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
queue
=
build_queue
(
job
.
queue_name
)
unless
queue
.
respond_to?
(
:enqueue_at
)
raise
NotImplementedError
,
'To be able to schedule jobs with Queue Classic '
\
...
...
activejob/lib/active_job/queue_adapters/resque_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -14,13 +14,24 @@
module
ActiveJob
module
QueueAdapters
# == Resque adapter for Active Job
#
# Resque (pronounced like "rescue") is a Redis-backed library for creating
# background jobs, placing those jobs on multiple queues, and processing
# them later.
#
# Read more about Resque {here}[https://github.com/resque/resque].
#
# To use Resque set the queue_adapter config to +:resque+.
#
# Rails.application.config.active_job.queue_adapter = :resque
class
ResqueAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
Resque
.
enqueue_to
job
.
queue_name
,
JobWrapper
,
job
.
serialize
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
unless
Resque
.
respond_to?
(
:enqueue_at_with_queue
)
raise
NotImplementedError
,
"To be able to schedule jobs with Resque you need the "
\
"resque-scheduler gem. Please add it to your Gemfile and run bundle install"
...
...
activejob/lib/active_job/queue_adapters/sidekiq_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -2,9 +2,21 @@
module
ActiveJob
module
QueueAdapters
# == Sidekiq adapter for Active Job
#
# Simple, efficient background processing for Ruby. Sidekiq uses threads to
# handle many jobs at the same time in the same process. It does not
# require Rails but will integrate tightly with Rails 3/4 to make
# background processing dead simple.
#
# Read more about Sidekiq {here}[http://sidekiq.org].
#
# To use Sidekiq set the queue_adapter config to +:sidekiq+.
#
# Rails.application.config.active_job.queue_adapter = :sidekiq
class
SidekiqAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
#Sidekiq::Client does not support symbols as keys
Sidekiq
::
Client
.
push
\
'class'
=>
JobWrapper
,
...
...
@@ -13,7 +25,7 @@ def enqueue(job)
'retry'
=>
true
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
Sidekiq
::
Client
.
push
\
'class'
=>
JobWrapper
,
'queue'
=>
job
.
queue_name
,
...
...
activejob/lib/active_job/queue_adapters/sneakers_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -3,18 +3,30 @@
module
ActiveJob
module
QueueAdapters
# == Sneakers adapter for Active Job
#
# A high-performance RabbitMQ background processing framework for Ruby.
# Sneakers is being used in production for both I/O and CPU intensive
# workloads, and have achieved the goals of high-performance and
# 0-maintenance, as designed.
#
# Read more about Sneakers {here}[https://github.com/jondot/sneakers].
#
# To use Sneakers set the queue_adapter config to +:sneakers+.
#
# Rails.application.config.active_job.queue_adapter = :sneakers
class
SneakersAdapter
@monitor
=
Monitor
.
new
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
@monitor
.
synchronize
do
JobWrapper
.
from_queue
job
.
queue_name
JobWrapper
.
enqueue
ActiveSupport
::
JSON
.
encode
(
job
.
serialize
)
end
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
raise
NotImplementedError
end
end
...
...
activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rb
浏览文件 @
c9a4c2a5
...
...
@@ -2,13 +2,28 @@
module
ActiveJob
module
QueueAdapters
# == Sucker Punch adapter for Active Job
#
# Sucker Punch is a single-process Ruby asynchronous processing library.
# It's girl_friday and DSL sugar on top of Celluloid. With Celluloid's
# actor pattern, we can do asynchronous processing within a single process.
# This reduces costs of hosting on a service like Heroku along with the
# memory footprint of having to maintain additional jobs if hosting on
# a dedicated server. All queues can run within a single Rails/Sinatra
# process.
#
# Read more about Sucker Punch {here}[https://github.com/brandonhilkert/sucker_punch].
#
# To use Sucker Punch set the queue_adapter config to +:sucker_punch+.
#
# Rails.application.config.active_job.queue_adapter = :sucker_punch
class
SuckerPunchAdapter
class
<<
self
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
JobWrapper
.
new
.
async
.
perform
job
.
serialize
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
raise
NotImplementedError
end
end
...
...
activejob/lib/active_job/queue_adapters/test_adapter.rb
浏览文件 @
c9a4c2a5
module
ActiveJob
module
QueueAdapters
# == Test adapter for Active Job
#
# The test adapter should be used only in testing. Along with
# <tt>ActiveJob::TestCase</tt> and <tt>ActiveJob::TestHelper</tt>
# it makes a great tool to test your Rails application.
#
# To use the test adapter set queue_adapter config to +:test+.
#
# Rails.application.config.active_job.queue_adapter = :test
class
TestAdapter
delegate
:name
,
to: :class
attr_accessor
(
:perform_enqueued_jobs
,
:perform_enqueued_at_jobs
)
...
...
@@ -15,7 +24,7 @@ def performed_jobs
@performed_jobs
||=
[]
end
def
enqueue
(
job
)
def
enqueue
(
job
)
#:nodoc:
if
perform_enqueued_jobs
performed_jobs
<<
{
job:
job
.
class
,
args:
job
.
arguments
,
queue:
job
.
queue_name
}
job
.
perform_now
...
...
@@ -24,7 +33,7 @@ def enqueue(job)
end
end
def
enqueue_at
(
job
,
timestamp
)
def
enqueue_at
(
job
,
timestamp
)
#:nodoc:
if
perform_enqueued_at_jobs
performed_jobs
<<
{
job:
job
.
class
,
args:
job
.
arguments
,
queue:
job
.
queue_name
,
at:
timestamp
}
job
.
perform_now
...
...
guides/source/active_job_basics.md
浏览文件 @
c9a4c2a5
...
...
@@ -99,41 +99,13 @@ If no adapter is set, the job is immediately executed.
### Backends
Active Job has adapters for the following queueing backends:
*
[
Backburner
](
https://github.com/nesquena/backburner
)
*
[
Delayed Job
](
https://github.com/collectiveidea/delayed_job
)
*
[
Qu
](
https://github.com/bkeepers/qu
)
*
[
Que
](
https://github.com/chanks/que
)
*
[
QueueClassic 2.x
](
https://github.com/ryandotsmith/queue_classic/tree/v2.2.3
)
*
[
Resque 1.x
](
https://github.com/resque/resque/tree/1-x-stable
)
*
[
Sidekiq
](
https://github.com/mperham/sidekiq
)
*
[
Sneakers
](
https://github.com/jondot/sneakers
)
*
[
Sucker Punch
](
https://github.com/brandonhilkert/sucker_punch
)
#### Backends Features
| | Async | Queues | Delayed | Priorities | Timeout | Retries |
|-----------------------|-------|--------|-----------|------------|---------|---------|
|
**Backburner**
| Yes | Yes | Yes | Yes | Job | Global |
|
**Delayed Job**
| Yes | Yes | Yes | Job | Global | Global |
|
**Que**
| Yes | Yes | Yes | Job | No | Job |
|
**Queue Classic**
| Yes | Yes | No
*
| No | No | No |
|
**Resque**
| Yes | Yes | Yes (Gem) | Queue | Global | Yes |
|
**Sidekiq**
| Yes | Yes | Yes | Queue | No | Job |
|
**Sneakers**
| Yes | Yes | No | Queue | Queue | No |
|
**Sucker Punch**
| Yes | Yes | No | No | No | No |
|
**Active Job Inline**
| No | Yes | N/A | N/A | N/A | N/A |
|
**Active Job**
| Yes | Yes | Yes | No | No | No |
NOTE:
*
Queue Classic does not support Job scheduling. However you can implement this
yourself or you can use the queue_classic-later gem. See the documentation for
ActiveJob::QueueAdapters::QueueClassicAdapter.
### Change Backends
You can easily change your adapter:
Active Job has built-in adapters for multiple queueing backends (Sidekiq,
Resque, Delayed Job and others). To get an up-to-date list of the adapters
see the API Documentation for
[
ActiveJob::QueueAdapters
](
http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html
)
.
### Changing the Backend
You can easily change your queueing backend:
```
ruby
# be sure to have the adapter gem in your Gemfile and follow the adapter specific
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录