Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8cbf8254
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,发现更多精彩内容 >>
提交
8cbf8254
编写于
10月 14, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename Orchestra to Notifications [#3321 state:resolved]
上级
bf9819f7
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
61 addition
and
61 deletion
+61
-61
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+10
-10
actionpack/lib/abstract_controller/logger.rb
actionpack/lib/abstract_controller/logger.rb
+1
-1
actionpack/lib/action_controller/caching/fragments.rb
actionpack/lib/action_controller/caching/fragments.rb
+4
-4
actionpack/lib/action_controller/caching/pages.rb
actionpack/lib/action_controller/caching/pages.rb
+2
-2
actionpack/lib/action_view/template/template.rb
actionpack/lib/action_view/template/template.rb
+1
-1
actionpack/test/controller/caching_test.rb
actionpack/test/controller/caching_test.rb
+2
-2
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+1
-1
activesupport/lib/active_support/autoload.rb
activesupport/lib/active_support/autoload.rb
+1
-1
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+1
-1
activesupport/lib/active_support/notifications.rb
activesupport/lib/active_support/notifications.rb
+8
-8
activesupport/test/notifications_test.rb
activesupport/test/notifications_test.rb
+30
-30
未找到文件。
actionmailer/lib/action_mailer/base.rb
浏览文件 @
8cbf8254
...
...
@@ -394,7 +394,7 @@ def mailer_name=(value)
def
controller_path
self
.
class
.
controller_path
end
def
formats
@template
.
formats
end
...
...
@@ -481,7 +481,7 @@ def initialize(method_name=nil, *parameters) #:nodoc:
# Initialize the mailer via the given +method_name+. The body will be
# rendered and a new TMail::Mail object created.
def
create!
(
method_name
,
*
parameters
)
#:nodoc:
ActiveSupport
::
Orchestra
.
instrument
(
:create_mail
,
:name
=>
method_name
)
do
ActiveSupport
::
Notifications
.
instrument
(
:create_mail
,
:name
=>
method_name
)
do
initialize_defaults
(
method_name
)
__send__
(
method_name
,
*
parameters
)
...
...
@@ -550,7 +550,7 @@ def deliver!(mail = @mail)
logger
.
debug
"
\n
#{
mail
.
encoded
}
"
end
ActiveSupport
::
Orchestra
.
instrument
(
:deliver_mail
,
:mail
=>
@mail
)
do
ActiveSupport
::
Notifications
.
instrument
(
:deliver_mail
,
:mail
=>
@mail
)
do
begin
__send__
(
"perform_delivery_
#{
delivery_method
}
"
,
mail
)
if
perform_deliveries
rescue
Exception
=>
e
# Net::SMTP errors or sendmail pipe errors
...
...
@@ -583,9 +583,9 @@ def render_template(template, body)
if
template
.
respond_to?
(
:mime_type
)
@current_template_content_type
=
template
.
mime_type
&&
template
.
mime_type
.
to_sym
.
to_s
end
@template
=
initialize_template_class
(
body
)
layout
=
_pick_layout
(
layout
,
true
)
unless
layout
=
_pick_layout
(
layout
,
true
)
unless
ActionController
::
Base
.
exempt_from_layout
.
include?
(
template
.
handler
)
@template
.
_render_template
(
template
,
layout
,
{})
ensure
...
...
@@ -600,16 +600,16 @@ def render_message(method_name, body)
def
render
(
opts
)
layout
,
file
=
opts
.
delete
(
:layout
),
opts
[
:file
]
begin
@template
=
initialize_template_class
(
opts
.
delete
(
:body
))
if
file
prefix
=
mailer_name
unless
file
=~
/\//
template
=
view_paths
.
find
(
file
,
{
:formats
=>
formats
},
prefix
)
end
layout
=
_pick_layout
(
layout
,
layout
=
_pick_layout
(
layout
,
!
template
||
ActionController
::
Base
.
exempt_from_layout
.
include?
(
template
.
handler
))
if
template
...
...
@@ -648,7 +648,7 @@ def initialize_template_class(assigns)
def
sort_parts
(
parts
,
order
=
[])
order
=
order
.
collect
{
|
s
|
s
.
downcase
}
parts
=
parts
.
sort
do
|
a
,
b
|
a_ct
=
a
.
content_type
.
downcase
b_ct
=
b
.
content_type
.
downcase
...
...
@@ -689,7 +689,7 @@ def create_mail
headers
.
each
{
|
k
,
v
|
m
[
k
]
=
v
}
real_content_type
,
ctype_attrs
=
parse_content_type
if
@parts
.
empty?
m
.
set_content_type
(
real_content_type
,
nil
,
ctype_attrs
)
m
.
body
=
normalize_new_lines
(
body
)
...
...
actionpack/lib/abstract_controller/logger.rb
浏览文件 @
8cbf8254
...
...
@@ -47,7 +47,7 @@ def method_missing(*args, &block)
# Override process_action in the AbstractController::Base
# to log details about the method.
def
process_action
(
action
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:process_action
,
event
=
ActiveSupport
::
Notifications
.
instrument
(
:process_action
,
:controller
=>
self
,
:action
=>
action
)
do
super
end
...
...
actionpack/lib/action_controller/caching/fragments.rb
浏览文件 @
8cbf8254
...
...
@@ -53,7 +53,7 @@ def write_fragment(key, content, options = nil)
return
content
unless
cache_configured?
key
=
fragment_cache_key
(
key
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:write_fragment
,
:key
=>
key
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:write_fragment
,
:key
=>
key
)
do
cache_store
.
write
(
key
,
content
,
options
)
end
...
...
@@ -66,7 +66,7 @@ def read_fragment(key, options = nil)
return
unless
cache_configured?
key
=
fragment_cache_key
(
key
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:read_fragment
,
:key
=>
key
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:read_fragment
,
:key
=>
key
)
do
cache_store
.
read
(
key
,
options
)
end
...
...
@@ -79,7 +79,7 @@ def fragment_exist?(key, options = nil)
return
unless
cache_configured?
key
=
fragment_cache_key
(
key
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:fragment_exist?
,
:key
=>
key
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:fragment_exist?
,
:key
=>
key
)
do
cache_store
.
exist?
(
key
,
options
)
end
...
...
@@ -110,7 +110,7 @@ def expire_fragment(key, options = nil)
key
=
fragment_cache_key
(
key
)
unless
key
.
is_a?
(
Regexp
)
message
=
nil
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:expire_fragment
,
:key
=>
key
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:expire_fragment
,
:key
=>
key
)
do
if
key
.
is_a?
(
Regexp
)
message
=
"Expired fragments matching:
#{
key
.
source
}
"
cache_store
.
delete_matched
(
key
,
options
)
...
...
actionpack/lib/action_controller/caching/pages.rb
浏览文件 @
8cbf8254
...
...
@@ -64,7 +64,7 @@ def expire_page(path)
return
unless
perform_caching
path
=
page_cache_path
(
path
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:expire_page
,
:path
=>
path
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:expire_page
,
:path
=>
path
)
do
File
.
delete
(
path
)
if
File
.
exist?
(
path
)
end
...
...
@@ -78,7 +78,7 @@ def cache_page(content, path)
return
unless
perform_caching
path
=
page_cache_path
(
path
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:cache_page
,
:path
=>
path
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:cache_page
,
:path
=>
path
)
do
FileUtils
.
makedirs
(
File
.
dirname
(
path
))
File
.
open
(
path
,
"wb+"
)
{
|
f
|
f
.
write
(
content
)
}
end
...
...
actionpack/lib/action_view/template/template.rb
浏览文件 @
8cbf8254
...
...
@@ -27,7 +27,7 @@ def initialize(source, identifier, handler, details)
end
def
render
(
view
,
locals
,
&
block
)
ActiveSupport
::
Orchestra
.
instrument
(
:render_template
,
:identifier
=>
identifier
)
do
ActiveSupport
::
Notifications
.
instrument
(
:render_template
,
:identifier
=>
identifier
)
do
method_name
=
compile
(
locals
,
view
)
view
.
send
(
method_name
,
locals
,
&
block
)
end
.
result
...
...
actionpack/test/controller/caching_test.rb
浏览文件 @
8cbf8254
...
...
@@ -626,7 +626,7 @@ def test_fragment_for_logging
fragment_computed
=
false
listener
=
[]
ActiveSupport
::
Orchestra
.
register
listener
ActiveSupport
::
Notifications
.
register
listener
buffer
=
'generated till now -> '
@controller
.
fragment_for
(
buffer
,
'expensive'
)
{
fragment_computed
=
true
}
...
...
@@ -637,7 +637,7 @@ def test_fragment_for_logging
assert
fragment_computed
assert_equal
'generated till now -> '
,
buffer
ensure
ActiveSupport
::
Orchestra
.
unregister
listener
ActiveSupport
::
Notifications
.
unregister
listener
end
end
...
...
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
8cbf8254
...
...
@@ -201,7 +201,7 @@ def log_info(sql, name, ms)
protected
def
log
(
sql
,
name
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:sql
,
:sql
=>
sql
,
:name
=>
name
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:sql
,
:sql
=>
sql
,
:name
=>
name
)
do
yield
if
block_given?
end
@runtime
+=
event
.
duration
...
...
activesupport/lib/active_support/autoload.rb
浏览文件 @
8cbf8254
...
...
@@ -18,7 +18,7 @@ module ActiveSupport
autoload
:MessageVerifier
,
'active_support/message_verifier'
autoload
:Multibyte
,
'active_support/multibyte'
autoload
:OptionMerger
,
'active_support/option_merger'
autoload
:
Orchestra
,
'active_support/orchestra
'
autoload
:
Notifications
,
'active_support/notifications
'
autoload
:OrderedHash
,
'active_support/ordered_hash'
autoload
:OrderedOptions
,
'active_support/ordered_options'
autoload
:Rescuable
,
'active_support/rescuable'
...
...
activesupport/lib/active_support/cache.rb
浏览文件 @
8cbf8254
...
...
@@ -247,7 +247,7 @@ def instrument(operation, key, options, &block)
payload
=
{
:key
=>
key
}
payload
.
merge!
(
options
)
if
options
.
is_a?
(
Hash
)
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:"cache_
#{
operation
}
"
,
payload
,
&
block
)
event
=
ActiveSupport
::
Notifications
.
instrument
(
:"cache_
#{
operation
}
"
,
payload
,
&
block
)
log
(
"
#{
operation
}
(%.1fms)"
%
event
.
duration
,
key
,
options
)
event
.
result
end
...
...
activesupport/lib/active_support/
orchestra
.rb
→
activesupport/lib/active_support/
notifications
.rb
浏览文件 @
8cbf8254
require
'thread'
module
ActiveSupport
#
Orchestra
provides an instrumentation API for Ruby. To instrument an action
#
Notifications
provides an instrumentation API for Ruby. To instrument an action
# in Ruby you just need to:
#
# ActiveSupport::
Orchestra
.instrument(:render, :extra => :information) do
# ActiveSupport::
Notifications
.instrument(:render, :extra => :information) do
# render :text => "Foo"
# end
#
...
...
@@ -12,23 +12,23 @@ module ActiveSupport
# to push. You can even register an array:
#
# @listener = []
# ActiveSupport::
Orchestra
.register @listener
# ActiveSupport::
Notifications
.register @listener
#
# ActiveSupport::
Orchestra
.instrument(:render, :extra => :information) do
# ActiveSupport::
Notifications
.instrument(:render, :extra => :information) do
# render :text => "Foo"
# end
#
# event #=> ActiveSupport::
Orchestra
::Event
# event #=> ActiveSupport::
Notifications
::Event
# event.name #=> :render
# event.duration #=> 10 (in miliseconds)
# event.result #=> "Foo"
# event.payload #=> { :extra => :information }
#
#
Orchestra
ships with a default listener implementation which puts events in
#
Notifications
ships with a default listener implementation which puts events in
# a stream and consume them in a Thread. This implementation is thread safe
# and is available at ActiveSupport::
Orchestra
::Listener.
# and is available at ActiveSupport::
Notifications
::Listener.
#
module
Orchestra
module
Notifications
@stacked_events
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
[]
}
@listeners
=
[]
...
...
activesupport/test/
orchestra
_test.rb
→
activesupport/test/
notifications
_test.rb
浏览文件 @
8cbf8254
require
'abstract_unit'
class
Orchestra
EventTest
<
Test
::
Unit
::
TestCase
class
Notifications
EventTest
<
Test
::
Unit
::
TestCase
def
setup
@parent
=
ActiveSupport
::
Orchestra
::
Event
.
new
(
:parent
)
@parent
=
ActiveSupport
::
Notifications
::
Event
.
new
(
:parent
)
end
def
test_initialization_with_name_and_parent_and_payload
event
=
ActiveSupport
::
Orchestra
::
Event
.
new
(
:awesome
,
@parent
,
:payload
=>
"orchestra
"
)
event
=
ActiveSupport
::
Notifications
::
Event
.
new
(
:awesome
,
@parent
,
:payload
=>
"notifications
"
)
assert_equal
(
:awesome
,
event
.
name
)
assert_equal
(
@parent
,
event
.
parent
)
assert_equal
({
:payload
=>
"
orchestra
"
},
event
.
payload
)
assert_equal
({
:payload
=>
"
notifications
"
},
event
.
payload
)
end
def
test_thread_id_is_set_on_initialization
event
=
ActiveSupport
::
Orchestra
::
Event
.
new
(
:awesome
)
event
=
ActiveSupport
::
Notifications
::
Event
.
new
(
:awesome
)
assert_equal
Thread
.
current
.
object_id
,
event
.
thread_id
end
def
test_current_time_is_set_on_initialization
previous_time
=
Time
.
now
.
utc
event
=
ActiveSupport
::
Orchestra
::
Event
.
new
(
:awesome
)
event
=
ActiveSupport
::
Notifications
::
Event
.
new
(
:awesome
)
assert_kind_of
Time
,
event
.
time
assert
event
.
time
.
to_f
>=
previous_time
.
to_f
end
def
test_duration_is_set_when_event_finishes
event
=
ActiveSupport
::
Orchestra
::
Event
.
new
(
:awesome
)
event
=
ActiveSupport
::
Notifications
::
Event
.
new
(
:awesome
)
sleep
(
0.1
)
event
.
finish!
assert_in_delta
100
,
event
.
duration
,
30
end
end
class
Orchestra
MainTest
<
Test
::
Unit
::
TestCase
class
Notifications
MainTest
<
Test
::
Unit
::
TestCase
def
setup
@listener
=
[]
ActiveSupport
::
Orchestra
.
register
@listener
ActiveSupport
::
Notifications
.
register
@listener
end
def
teardown
ActiveSupport
::
Orchestra
.
unregister
@listener
ActiveSupport
::
Notifications
.
unregister
@listener
end
def
test_
orchestra
_allows_any_action_to_be_instrumented
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:awesome
,
"orchestra
"
)
do
def
test_
notifications
_allows_any_action_to_be_instrumented
event
=
ActiveSupport
::
Notifications
.
instrument
(
:awesome
,
"notifications
"
)
do
sleep
(
0.1
)
end
assert_equal
:awesome
,
event
.
name
assert_equal
"
orchestra
"
,
event
.
payload
assert_equal
"
notifications
"
,
event
.
payload
assert_in_delta
100
,
event
.
duration
,
30
end
def
test_block_result_is_stored
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:awesome
,
"orchestra
"
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:awesome
,
"notifications
"
)
do
1
+
1
end
...
...
@@ -61,18 +61,18 @@ def test_block_result_is_stored
end
def
test_events_are_published_to_a_listener
event
=
ActiveSupport
::
Orchestra
.
instrument
(
:awesome
,
"orchestra
"
)
do
event
=
ActiveSupport
::
Notifications
.
instrument
(
:awesome
,
"notifications
"
)
do
1
+
1
end
assert_equal
1
,
@listener
.
size
assert_equal
:awesome
,
@listener
.
last
.
name
assert_equal
"
orchestra
"
,
@listener
.
last
.
payload
assert_equal
"
notifications
"
,
@listener
.
last
.
payload
end
def
test_nested_events_can_be_instrumented
ActiveSupport
::
Orchestra
.
instrument
(
:awesome
,
"orchestra
"
)
do
ActiveSupport
::
Orchestra
.
instrument
(
:wot
,
"child"
)
do
ActiveSupport
::
Notifications
.
instrument
(
:awesome
,
"notifications
"
)
do
ActiveSupport
::
Notifications
.
instrument
(
:wot
,
"child"
)
do
sleep
(
0.1
)
end
...
...
@@ -86,23 +86,23 @@ def test_nested_events_can_be_instrumented
assert_equal
2
,
@listener
.
size
assert_equal
:awesome
,
@listener
.
last
.
name
assert_equal
"
orchestra
"
,
@listener
.
last
.
payload
assert_equal
"
notifications
"
,
@listener
.
last
.
payload
assert_in_delta
100
,
@listener
.
first
.
parent
.
duration
,
30
end
def
test_event_is_pushed_even_if_block_fails
ActiveSupport
::
Orchestra
.
instrument
(
:awesome
,
"orchestra
"
)
do
ActiveSupport
::
Notifications
.
instrument
(
:awesome
,
"notifications
"
)
do
raise
"OMG"
end
rescue
RuntimeError
assert_equal
1
,
@listener
.
size
assert_equal
:awesome
,
@listener
.
last
.
name
assert_equal
"
orchestra
"
,
@listener
.
last
.
payload
assert_equal
"
notifications
"
,
@listener
.
last
.
payload
end
end
class
Orchestra
ListenerTest
<
Test
::
Unit
::
TestCase
class
MyListener
<
ActiveSupport
::
Orchestra
::
Listener
class
Notifications
ListenerTest
<
Test
::
Unit
::
TestCase
class
MyListener
<
ActiveSupport
::
Notifications
::
Listener
attr_reader
:consumed
def
consume
(
event
)
...
...
@@ -113,11 +113,11 @@ def consume(event)
def
setup
@listener
=
MyListener
.
new
ActiveSupport
::
Orchestra
.
register
@listener
ActiveSupport
::
Notifications
.
register
@listener
end
def
teardown
ActiveSupport
::
Orchestra
.
unregister
@listener
ActiveSupport
::
Notifications
.
unregister
@listener
end
def
test_thread_is_exposed_by_listener
...
...
@@ -125,7 +125,7 @@ def test_thread_is_exposed_by_listener
end
def
test_event_is_consumed_when_an_action_is_instrumented
ActiveSupport
::
Orchestra
.
instrument
(
:sum
)
do
ActiveSupport
::
Notifications
.
instrument
(
:sum
)
do
1
+
1
end
sleep
0.1
...
...
@@ -136,10 +136,10 @@ def test_event_is_consumed_when_an_action_is_instrumented
def
test_with_sevaral_consumers_and_several_events
@another
=
MyListener
.
new
ActiveSupport
::
Orchestra
.
register
@another
ActiveSupport
::
Notifications
.
register
@another
1
.
upto
(
100
)
do
|
i
|
ActiveSupport
::
Orchestra
.
instrument
(
:value
)
do
ActiveSupport
::
Notifications
.
instrument
(
:value
)
do
i
end
end
...
...
@@ -156,6 +156,6 @@ def test_with_sevaral_consumers_and_several_events
assert_equal
1
,
@another
.
consumed
.
first
.
result
assert_equal
100
,
@another
.
consumed
.
last
.
result
ensure
ActiveSupport
::
Orchestra
.
unregister
@another
ActiveSupport
::
Notifications
.
unregister
@another
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录