Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gearman PHP, sendComplete has no effect

Have successfully connected Gearman to an existing PHP project. Using supervisord to ensure that the workers are running, it has produced pretty good results!

I have a critical issue, however, in that the "setCompleteCallback" is not working at all.

Split up somewhat like this:

Client

$client = new GearmanClient();
$client->addServer();
$client->setCompleteCallback( 
    array( 'LDPE_Service_AWSConnect_Transfer_Target', 'transferComplete' ) );

// push core to S3 bucket
$target = new LDPE_Service_AWSConnect_Transfer_Target( $transaction->id,
    "/usr/local/include/LDP/", LDPE_Service_S3::BUCKET_CORE );

// push S3 bucket to instances
foreach( $aws_target_list as $dns )
{
    $target->addChildRequest( 
        new LDPE_Service_AWSConnect_Transfer_Target( $transaction->id, 
                null, LDPE_Service_S3::BUCKET_CORE, $dns )
    );
}


$client->addTaskBackground( 'transferStart', serialize( $target ) );        
$client->runTasks();

Worker

(basically bootstraps a Zend Framework environment, and loads the exec functions)

include 'bootstrap.php';    

ini_set('memory_limit', -1);


$worker = new GearmanWorker();
$worker->addServer();

$worker->addFunction( 'transferStart', array( 
        'LDPE_Service_AWSConnect_Transfer_Target', 'transferStart' ) );

while ($worker->work())
{
    switch( $worker->returnCode() )
    {
        case GEARMAN_SUCCESS:
        break;

        default:
            echo "ERROR RET: " . $worker->returnCode() . "\n";
            exit;   
    }
}

Finally, here's the LDPE_Service_AWSConnect_Transfer_Target class that contains all of the heavy lifting. I've pruned out all of the logic, and it doesn't fire at all.

Implementation Methods

class LDPE_Service_AWSConnect_Transfer_Target {

    public static function transferStart( GearmanJob $job )
    {

        $workload   = $job->workload();
        $target     = unserialize( $workload );

        echo "transferStart/begin [ " . 
                $target->getShortRepresentation() . " ]\n";
        // perform a series of actions

        echo "transferStart/complete [ " . 
                $target->getShortRepresentation() . " ]\n"; 
        return serialize( $target );
    }


    public static function transferComplete( GearmanTask $task )
    {
        echo "transferComplete/begin\n";

        $workload       = $task->data();
        $parent_target  = unserialize( $workload );


        echo "transferComplete/complete\n";
    }
}

To be clear then, the "transferStart/begin" and "transferStart/complete" strings are correctly printed to logs, however, transferComplete/begin is never fired. What's going on?

Thanks! Alex


Seems as though the callbacks don't fire when run in background mode..

like image 992
Alex Avatar asked Mar 22 '26 20:03

Alex


1 Answers

Try setting the callback after your call to the process function

$client->addTaskBackground('my_task', 'payload');
$client->setCompleteCallback('complete');
$client->runTasks();
like image 152
Yarek T Avatar answered Mar 24 '26 09:03

Yarek T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!