当我的Beanstalkd作业出现错误时,如"exception 'ErrorException' with message 'Notice: Undefined index: id in /var/www/mysite/app/libraries/lib.php line 248' in /var/www/mysite/app/libraries/lib.php:248
,Beanstalkd应该如何知道发生了错误并将其标记为失败,以便可以再次重试?如何处理发生错误的Beanstalkd作业
4
A
回答
6
在开发/测试您的应用程序时,安装beanstalkd监视器可能很有用。使用PHP的一些替代品:http://mnapoli.github.io/phpBeanstalkdAdmin/和https://github.com/ptrofimov/beanstalk_console
至于处理错误,你可以定义自己的错误处理程序beanstalkd工作,在该处理程序,如果你想决定:
- 埋葬(把工作搁置后检查)
- 踢(把它放回队列)
- 删除(删除它,如果这是安全的,您的应用程序)
编辑 - 您是否设法解决您的问题? 最好的方法可能是在工作中使用try/catch来捕捉异常,然后在工作人员提出异常时将其埋掉。如果在生产者中引发异常,它可能永远不会被添加到队列中,因此不需要埋葬()然后使用监视器来确定。
如果你想尝试为你的对象定义一个自己的错误处理程序,我之前通过为你的类设置了一个自定义的错误处理程序来做类似的事情。这可能是一个丑陋的黑客试图通过$ errcontext获得pheanstalk(工作)对象 - 但可能是尝试的东西..这里是一些伪代码,如果你想尝试一下,我很快就把它们放在一起(创建一个子类来避免将代码放入pheanstalk类中):
class MyPheanstalk extends Pheanstalk {
function __construct() {
//register your custom error_handler for objects of this class
set_error_handler(array($this, 'myPheanstalk_error_handler'));
//call parent constructor
parent::__construct();
}
function myPheanstalk_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
// get the current job that failed
foreach($errcontext as $val) //print_r($errcontext) to find info on the object(job) you are looking for
{
if(is_object($val)) {
if(get_class($val) == 'Pheanstalk') { //and replace with correct class here
//optionally check errstr to decide if you want to delete() or kick() instead of bury()
$this->bury($val);
}
}
}
}
}
0
它的脚本有错误,而不是beanstalkd。
try {
//your code from Line 248 here
} catch (ErrorException $e) { //this section catches the error.
//you can print the error
echo 'An error occurred'. $e->getMessage();
//or do something else like try reporting the ID is bad.
if (!isset($id)) {
echo 'The id was not set!';
}
} //end of try/catch
相关问题
- 1. 如何处理SQL Agent作业错误?
- 2. 处理延迟作业错误
- 3. 发生未处理的低级错误
- 4. JDBC在发生错误时批处理
- 5. 如何发送域的错误处理
- 6. 运行Rust程序时如何处理“发生未知错误”?
- 7. 如何在JavaScript中发生错误后继续处理代码?
- 8. Dos批处理脚本错误?时发生错误,而处理:.EXE
- 9. Beanstalkd作业切换到“就绪”状态
- 10. Spss(mrScriptBasic)错误处理获取代码,其中发生错误
- 11. 处理Cron作业
- 12. 大型机批处理作业触发
- 13. ASP.NET:激发批处理作业
- 14. 注销时bash如何处理作业?
- 15. 队列:如何处理相关作业
- 16. SQL作业错误:查询处理器未能生成查询计划
- 17. 如何从Spring Batch Admin触发远程批处理作业?
- 18. 在特定行处发生预处理器错误
- 19. 如何处理错误
- 20. 如何处理'simplexml_load_string'错误?
- 21. 如何处理CLI错误
- 22. 如何处理404错误
- 23. 如何处理错误(AbstractRestfulController)?
- 24. 如何处理jsonp错误?
- 25. ServiceStack:如何处理错误?
- 26. 如何处理RapidXml错误?
- 27. 如何处理错误
- 28. 如何处理错误
- 29. 如何处理IE错误
- 30. 如何处理错误1064?
这是不是错误它是通知。当您尝试使用未分配的变量时会发生这种情况。 – 2013-04-08 05:24:27
在这种情况下,函数将退出,但有一个例外。工作是否已完成?或者返回到就绪状态? – Nyxynyx 2013-04-08 05:28:05