Gearman 与 PHP/Net_Gearman,执行从其他工作人员调用的作业的工作人员变得无响应
我正在使用 gearman 在多个工作服务器之间分配长时间运行的任务。对于我的一个工作任务,我尝试调用另一个后台作业。后台作业已由另一个工作进程成功执行...但该工作进程不会响应随后添加到 gearman 的任何新作业。
有人知道会发生什么吗?这是gearman的特色吗?
编辑:
此外,如果我重新启动我的工作人员,他们会重复其他工作人员排队的任务。吉尔曼似乎没有意识到工作已经完成。
编辑2:
尝试:
var_dump($this->conn);
var_dump($this->handle);
从我的其他工作人员调用的工作人员功能内。这是我收到的输出:
NULL
string(0) ""
编辑 3:
好吧,我想出了一个巧妙的方法来解决这个问题。以下是相关代码片段。我在我的项目中使用 codeigniter,我的 gearman 服务器存储为数组。我只是在我的作业代码中测试连接是否为空,如果是,则使用随机 gearman 服务器重新建立它。我确信这很糟糕,所以如果有人有一些改进的见解,我将非常感激。
class Net_Gearman_Job_notification_vc_friends_new_user extends Net_Gearman_Job_Common{
private $CI;
function __construct(){
$this->CI =& get_instance();
if(!$this->conn){
$gearman = $this->CI->config->item('gearman');
$servers = $gearman['servers'];
$key = array_rand($servers);
$this->conn = Net_Gearman_Connection::connect($servers[$key]);
}
}
I'm using gearman to distribute long running tasks across multiple worker servers. For one of my worker tasks, I attempt to invoke another background job. The background job is performed by another worker successfully... but that worker process doesn't respond to any new jobs that are added to gearman afterwards.
Anyone know what might be going on? Is this a feature of gearman?
EDIT:
Also, if I restart my workers they repeat the task that was queued by the other worker. Gearman appears to not be recognizing the job has completed.
EDIT 2:
tried:
var_dump($this->conn);
var_dump($this->handle);
From within the worker function that's called from my other worker. This is the output I receive:
NULL
string(0) ""
EDIT 3:
Well I came up with a hackey way to solve this. The following is the relevant snippet of code. I'm using codeigniter for my project, and my gearman servers are stored in as an array. I simply test in my job code if the connection is null, and if so reestablish it using a random gearman server. I'm sure this sucks so if anyone has some improved insight I would very much appreciate it.
class Net_Gearman_Job_notification_vc_friends_new_user extends Net_Gearman_Job_Common{
private $CI;
function __construct(){
$this->CI =& get_instance();
if(!$this->conn){
$gearman = $this->CI->config->item('gearman');
$servers = $gearman['servers'];
$key = array_rand($servers);
$this->conn = Net_Gearman_Connection::connect($servers[$key]);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了!其实很蠢,忘了打电话
父级::__construct();在我的构造函数中...哎呀。
Figured it out! pretty stupid actually, forgot to call
parent::__construct(); in my constructor... oops.