Casey Flynn
Casey Flynn

Reputation: 14038

Gearman with PHP/Net_Gearman, workers that perform jobs that are invoked from other workers become unresponsive

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]);

    }
}

Upvotes: 1

Views: 482

Answers (1)

Casey Flynn
Casey Flynn

Reputation: 14038

Figured it out! pretty stupid actually, forgot to call parent::__construct(); in my constructor... oops.

Upvotes: 0

Related Questions