Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e2cdffce
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,发现更多精彩内容 >>
提交
e2cdffce
编写于
12月 09, 2019
作者:
C
Cliff Pruitt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add config option for ActiveJob::Base.default_retry_jitter
上级
774e77c2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
2 deletion
+51
-2
activejob/lib/active_job/exceptions.rb
activejob/lib/active_job/exceptions.rb
+8
-2
activejob/test/cases/exceptions_test.rb
activejob/test/cases/exceptions_test.rb
+25
-0
railties/lib/rails/application/configuration.rb
railties/lib/rails/application/configuration.rb
+4
-0
railties/test/application/configuration_test.rb
railties/test/application/configuration_test.rb
+14
-0
未找到文件。
activejob/lib/active_job/exceptions.rb
浏览文件 @
e2cdffce
...
...
@@ -7,6 +7,11 @@ module ActiveJob
module
Exceptions
extend
ActiveSupport
::
Concern
included
do
class_attribute
:default_retry_jitter
,
instance_accessor:
false
,
instance_predicate:
false
self
.
default_retry_jitter
=
0.15
end
module
ClassMethods
# Catch the exception and reschedule job for re-execution after so many seconds, for a specific number of attempts.
# If the exception keeps getting raised beyond the specified number of attempts, the exception is allowed to
...
...
@@ -49,7 +54,7 @@ module ClassMethods
# # Might raise Net::OpenTimeout or Timeout::Error when the remote service is down
# end
# end
def
retry_on
(
*
exceptions
,
wait:
3
.
seconds
,
attempts:
5
,
queue:
nil
,
priority:
nil
,
jitter:
0.15
)
def
retry_on
(
*
exceptions
,
wait:
3
.
seconds
,
attempts:
5
,
queue:
nil
,
priority:
nil
,
jitter:
nil
)
rescue_from
(
*
exceptions
)
do
|
error
|
executions
=
executions_for
(
exceptions
)
if
executions
<
attempts
...
...
@@ -122,7 +127,8 @@ def retry_job(options = {})
end
private
def
determine_delay
(
seconds_or_duration_or_algorithm
:,
executions
:,
jitter
:)
def
determine_delay
(
seconds_or_duration_or_algorithm
:,
executions
:,
jitter:
nil
)
jitter
||=
self
.
class
.
default_retry_jitter
case
seconds_or_duration_or_algorithm
when
:exponentially_longer
((
executions
**
4
)
+
(
Kernel
.
rand
((
executions
**
4
)
*
jitter
)))
+
2
...
...
activejob/test/cases/exceptions_test.rb
浏览文件 @
e2cdffce
...
...
@@ -129,6 +129,31 @@ class ExceptionsTest < ActiveSupport::TestCase
end
end
test
"retry jitter uses value from ActiveJob::Base.default_retry_jitter by default"
do
old_jitter
=
ActiveJob
::
Base
.
default_retry_jitter
ActiveJob
::
Base
.
default_retry_jitter
=
4.0
travel_to
Time
.
now
Kernel
.
stub
(
:rand
,
->
(
arg
)
{
arg
})
do
RetryJob
.
perform_later
"ExponentialWaitTenAttemptsError"
,
5
,
:log_scheduled_at
assert_equal
[
"Raised ExponentialWaitTenAttemptsError for the 1st time"
,
"Next execution scheduled at
#{
(
Time
.
now
+
7
.
seconds
).
to_f
}
"
,
"Raised ExponentialWaitTenAttemptsError for the 2nd time"
,
"Next execution scheduled at
#{
(
Time
.
now
+
82
.
seconds
).
to_f
}
"
,
"Raised ExponentialWaitTenAttemptsError for the 3rd time"
,
"Next execution scheduled at
#{
(
Time
.
now
+
407
.
seconds
).
to_f
}
"
,
"Raised ExponentialWaitTenAttemptsError for the 4th time"
,
"Next execution scheduled at
#{
(
Time
.
now
+
1282
.
seconds
).
to_f
}
"
,
"Successfully completed job"
],
JobBuffer
.
values
end
ensure
ActiveJob
::
Base
.
default_retry_jitter
=
old_jitter
end
test
"custom wait retrying job"
do
travel_to
Time
.
now
...
...
railties/lib/rails/application/configuration.rb
浏览文件 @
e2cdffce
...
...
@@ -156,6 +156,10 @@ def load_defaults(target_version)
when
"6.1"
load_defaults
"6.0"
if
respond_to?
(
:active_job
)
active_job
.
default_retry_jitter
=
0.15
end
if
respond_to?
(
:active_record
)
active_record
.
has_many_inversing
=
true
end
...
...
railties/test/application/configuration_test.rb
浏览文件 @
e2cdffce
...
...
@@ -2262,6 +2262,20 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
end
end
test
"ActiveJob::Base.default_retry_jitter is 0.15 by default"
do
app
"development"
assert_equal
0.15
,
ActiveJob
::
Base
.
default_retry_jitter
end
test
"ActiveJob::Base.default_retry_jitter can be set by config"
do
app
"development"
Rails
.
application
.
config
.
active_job
.
default_retry_jitter
=
0.22
assert_equal
0.22
,
ActiveJob
::
Base
.
default_retry_jitter
end
test
"ActiveJob::Base.return_false_on_aborted_enqueue is true by default"
do
app
"development"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录