Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
91461dc7
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,发现更多精彩内容 >>
提交
91461dc7
编写于
5月 18, 2014
作者:
A
Abdelkader Boudih
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Lazy-load adapters, fixes #6
上级
68543de8
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
67 addition
and
8 deletion
+67
-8
lib/active_job/base.rb
lib/active_job/base.rb
+19
-4
lib/active_job/errors.rb
lib/active_job/errors.rb
+12
-0
lib/active_job/job_wrappers/resque_wrapper.rb
lib/active_job/job_wrappers/resque_wrapper.rb
+1
-1
test/adapters/inline.rb
test/adapters/inline.rb
+1
-0
test/adapters/resque.rb
test/adapters/resque.rb
+1
-1
test/adapters/sidekiq.rb
test/adapters/sidekiq.rb
+1
-1
test/adapters/sucker_punch.rb
test/adapters/sucker_punch.rb
+1
-1
test/cases/adapter_test.rb
test/cases/adapter_test.rb
+31
-0
未找到文件。
lib/active_job/base.rb
浏览文件 @
91461dc7
require
'active_job/errors'
require
'active_job/queue_adapters/inline_adapter'
require
'active_job/queue_adapters/resque_adapter'
require
'active_job/queue_adapters/sidekiq_adapter'
require
'active_job/queue_adapters/sucker_punch_adapter'
require
'active_support/core_ext/string/inflections'
module
ActiveJob
class
Base
cattr_accessor
(
:queue_adapter
)
{
ActiveJob
::
QueueAdapters
::
InlineAdapter
}
cattr_accessor
(
:queue_base_name
)
{
"active_jobs"
}
...
...
@@ -13,10 +13,25 @@ class << self
def
enqueue
(
*
args
)
queue_adapter
.
queue
self
,
*
args
end
def
queue_as
(
part_name
)
self
.
queue_name
=
"
#{
queue_base_name
}
_
#{
part_name
}
"
end
def
adapter
=
(
adapter_name
)
adapter_name
=
adapter_name
.
to_s
unless
%w(inline resque sidekiq sucker_punch)
.
include?
(
adapter_name
)
fail
ActiveJob
::
NotImplementedError
end
begin
require_relative
"queue_adapters/
#{
adapter_name
}
_adapter"
ActiveJob
::
Base
.
queue_adapter
=
"ActiveJob::QueueAdapters::
#{
adapter_name
.
camelize
}
Adapter"
.
constantize
rescue
fail
ActiveJob
::
Error
.
new
(
"
#{
adapter_name
}
is missing"
)
end
end
end
end
end
\ No newline at end of file
lib/active_job/errors.rb
0 → 100644
浏览文件 @
91461dc7
module
ActiveJob
class
NotImplementedError
<
::
NotImplementedError
#:nodoc:
end
class
Error
<
::
StandardError
#:nodoc:
def
initialize
(
message
=
nil
)
super
(
message
)
end
end
end
\ No newline at end of file
lib/active_job/job_wrappers/resque_wrapper.rb
浏览文件 @
91461dc7
...
...
@@ -2,7 +2,7 @@
require
'active_support/core_ext/enumerable'
require
'active_support/core_ext/array/access'
require
'active_support/core_ext/string/inflections'
module
ActiveJob
...
...
test/adapters/inline.rb
浏览文件 @
91461dc7
ActiveJob
::
Base
.
adapter
=
:inline
\ No newline at end of file
test/adapters/resque.rb
浏览文件 @
91461dc7
ActiveJob
::
Base
.
queue_adapter
=
ActiveJob
::
QueueAdapters
::
ResqueAdapter
ActiveJob
::
Base
.
adapter
=
:resque
Resque
.
inline
=
true
test/adapters/sidekiq.rb
浏览文件 @
91461dc7
require
'sidekiq/testing/inline'
ActiveJob
::
Base
.
queue_adapter
=
ActiveJob
::
QueueAdapters
::
SidekiqAdapter
ActiveJob
::
Base
.
adapter
=
:sidekiq
test/adapters/sucker_punch.rb
浏览文件 @
91461dc7
require
'sucker_punch/testing/inline'
ActiveJob
::
Base
.
queue_adapter
=
ActiveJob
::
QueueAdapters
::
SuckerPunchAdapter
ActiveJob
::
Base
.
adapter
=
:sucker_punch
test/cases/adapter_test.rb
0 → 100644
浏览文件 @
91461dc7
require
'helper'
class
AdapterTest
<
ActiveSupport
::
TestCase
def
setup
@old_adapter
=
ActiveJob
::
Base
.
queue_adapter
end
test
'should load inline adapter'
do
ActiveJob
::
Base
.
adapter
=
:inline
assert_equal
ActiveJob
::
QueueAdapters
::
InlineAdapter
,
ActiveJob
::
Base
.
queue_adapter
end
test
'should load resque adapter'
do
ActiveJob
::
Base
.
adapter
=
:resque
assert_equal
ActiveJob
::
QueueAdapters
::
ResqueAdapter
,
ActiveJob
::
Base
.
queue_adapter
end
test
'should load sidekiq adapter'
do
ActiveJob
::
Base
.
adapter
=
:sidekiq
assert_equal
ActiveJob
::
QueueAdapters
::
SidekiqAdapter
,
ActiveJob
::
Base
.
queue_adapter
end
test
'should load sucker punch adapter'
do
ActiveJob
::
Base
.
adapter
=
:sucker_punch
assert_equal
ActiveJob
::
QueueAdapters
::
SuckerPunchAdapter
,
ActiveJob
::
Base
.
queue_adapter
end
def
teardown
ActiveJob
::
Base
.
queue_adapter
=
@old_adapter
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录