我有一个与 Redis 一起工作的 Celery 任务:
@app.task(bind=True, name='task_a', max_retries=4, soft_time_limit_exception=300)
def task_a(self, a, b):
try:
# some code here
except Exception as e:
raise self.retry(exc=e, countdown=exponential_backoff(self))
def exponential_backoff(task_self):
minutes = task_self.default_retry_delay / 60
rand = random.uniform(minutes, minutes * 1.5)
return int(rand ** task_self.request.retries) * 60
我有以下问题:
如果 Redis 不工作或 celery worker 停止/失败,代码将“等待”而不是继续执行代码。
如果我将 try except block 放在任务中,或者在 try except 中调用的任务,它什么也抓不到,我得到一个 ConnectionAbortedError。
在这种情况下,我想要的是捕获此特定错误并执行其他操作,或者忽略而不调用重试。
@Pavel Minenkov 回答建议使用 sentry.io,但问题是我不知道要捕获它。
查看回溯:
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49301)
Traceback (most recent call last):
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "D:\DevEnv\Python\lib\socketserver.py", line 796, in write
self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "D:\DevEnv\PythonVENV\DjangoDev\lib\site-packages\django\core\servers\basehttp.py", line 86, in handle_error
super().handle_error()
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\DevEnv\Python\lib\socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "D:\DevEnv\Python\lib\socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "D:\DevEnv\Python\lib\socketserver.py", line 717, in __init__
self.handle()
File "D:\DevEnv\PythonVENV\DjangoDev\lib\site-packages\django\core\servers\basehttp.py", line 154, in handle
handler.run(self.server.get_app())
File "D:\DevEnv\Python\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "D:\DevEnv\Python\lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
最佳答案
首先实现监控系统。我喜欢哨兵:https://sentry.io/welcome/ 1 位用户免费
from raven import Client
...
@app.task(bind=True, name='task_a', max_retries=4, soft_time_limit_exception=300)
def task_a(self, a, b):
sentry = Client(dsn=<your>)
with sentry.capture_exceptions():
# some code here
然后您将能够找出引发的异常,然后您将能够解决问题
关于django - ConnectionAbortedError - 如果 Celery 停止/失败或 Redis 未启动。我如何捕获/除此错误/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51454403/
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
如果我使用ruby版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更
一、引擎主循环UE版本:4.27一、引擎主循环的位置:Launch.cpp:GuardedMain函数二、、GuardedMain函数执行逻辑:1、EnginePreInit:加载大多数模块int32ErrorLevel=EnginePreInit(CmdLine);PreInit模块加载顺序:模块加载过程:(1)注册模块中定义的UObject,同时为每个类构造一个类默认对象(CDO,记录类的默认状态,作为模板用于子类实例创建)(2)调用模块的StartUpModule方法2、FEngineLoop::Init()1、检查Engine的配置文件找出使用了哪一个GameEngine类(UGame
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
我需要一个非常简单的字符串验证器来显示第一个符号与所需格式不对应的位置。我想使用正则表达式,但在这种情况下,我必须找到与表达式相对应的字符串停止的位置,但我找不到可以做到这一点的方法。(这一定是一种相当简单的方法……也许没有?)例如,如果我有正则表达式:/^Q+E+R+$/带字符串:"QQQQEEE2ER"期望的结果应该是7 最佳答案 一个想法:你可以做的是标记你的模式并用可选的嵌套捕获组编写它:^(Q+(E+(R+($)?)?)?)?然后你只需要计算你获得的捕获组的数量就可以知道正则表达式引擎在模式中停止的位置,你可以确定匹配结束
我正在尝试在配备ARMv7处理器的SynologyDS215j上安装ruby2.2.4或2.3.0。我用了optware-ng安装gcc、make、openssl、openssl-dev和zlib。我根据README中的说明安装了rbenv(版本1.0.0-19-g29b4da7)和ruby-build插件。.这些是随optware-ng安装的软件包及其版本binutils-2.25.1-1gcc-5.3.0-6gconv-modules-2.21-3glibc-opt-2.21-4libc-dev-2.21-1libgmp-6.0.0a-1libmpc-1.0.2-1libm