停止 sidekiq worker 执行方法
stop sidekiq worker perform method
我的工作人员的 perform
方法中有一个 begin rescue
块,就像这样
begin
HTTParty.get(url)
rescue
## call failed for some reason, log and stop performing
break
end
## do more stuff here with the result of the call if it didn't fail
## this can fail too so a further
begin
##would be cumbersome
rescue
end
但是我得到了 Invalid break (SyntaxError)
是否有其他方式告诉 sidekiq 这项工作基本完成?我不希望它重试,而是完全退出。
你不需要休息。如果 begin 中的代码失败,将停止执行并执行 rescue
块中的内容。要默默忽略和return,只需将救援内容留空即可。
def perform
begin
HTTParty.get(url)
rescue
## call failed for some reason, log and stop performing
end
end
你也可以缩短方法
def perform
HTTParty.get(url)
rescue
## call failed for some reason, log and stop performing
end
您可能只想明确地挽救某些异常。我不确定你想挽救什么(这取决于 HTTParty 可以提出什么)。
def perform
HTTParty.get(url)
rescue WhateverError
## call failed for some reason, log and stop performing
end
这是一个例子
def perform
HTTParty.get(url)
rescue WhateverError => e
Rails.logger.error "Kaboom! #{e.message}"
end
就return:
begin
HTTParty.get(url)
rescue => e
logger.warn(e.message)
return
end
我的工作人员的 perform
方法中有一个 begin rescue
块,就像这样
begin
HTTParty.get(url)
rescue
## call failed for some reason, log and stop performing
break
end
## do more stuff here with the result of the call if it didn't fail
## this can fail too so a further
begin
##would be cumbersome
rescue
end
但是我得到了 Invalid break (SyntaxError)
是否有其他方式告诉 sidekiq 这项工作基本完成?我不希望它重试,而是完全退出。
你不需要休息。如果 begin 中的代码失败,将停止执行并执行 rescue
块中的内容。要默默忽略和return,只需将救援内容留空即可。
def perform
begin
HTTParty.get(url)
rescue
## call failed for some reason, log and stop performing
end
end
你也可以缩短方法
def perform
HTTParty.get(url)
rescue
## call failed for some reason, log and stop performing
end
您可能只想明确地挽救某些异常。我不确定你想挽救什么(这取决于 HTTParty 可以提出什么)。
def perform
HTTParty.get(url)
rescue WhateverError
## call failed for some reason, log and stop performing
end
这是一个例子
def perform
HTTParty.get(url)
rescue WhateverError => e
Rails.logger.error "Kaboom! #{e.message}"
end
就return:
begin
HTTParty.get(url)
rescue => e
logger.warn(e.message)
return
end