简体   繁体   English

如何在IRB控制台中调试在delayed_job任务中运行的代码?

[英]How can I debug code running in a delayed_job task in the IRB console?

I have a background task that runs using delayed_job. 我有一个使用delayed_job运行的后台任务。

I can see that it does run from the logging statements. 我可以看到它确实从日志记录语句中运行。 It does not seem to have the correct result, compared to running it in the foreground, so I want to debug it in the IRB console. 与在前台运行相比,它似乎没有正确的结果,所以我想在IRB控制台中调试它。

I am running the background task with 我正在运行后台任务

rake jobs:work

and it does not trigger the debugger statement. 并且它不会触发调试器语句。

How can I load the debugger? 如何加载调试器?

Start a standard rails console 启动标准rails控制台

ruby script/console

And start a worker inside here, this will see and trigger the debugger statement. 在这里启动一个worker,这将看到并触发调试器语句。

worker = Delayed::Worker.new
worker.start

I use pry as my console and remote debugger. 我使用pry作为我的控制台和远程调试器。 Pry website here , Pry rails gem here . 撬网站在这里Pry rails gem在这里 In your code, you add binding.pry statements to have your app stop executing and open the console. 在您的代码中,添加binding.pry语句以使您的应用程序停止执行并打开控制台。 It works the same with delayed_job as it does with your rails app. 它与delayed_job的工作方式与rails应用程序相同。 Make sure you are running delayed_job in the foreground though, so it is still attached to the terminal. 确保您在前台运行delayed_job,因此它仍然连接到终端。 Eg, start delayed_job with: 例如,启动delayed_job:

rake jobs:work

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM