Search code examples
symfonyphp-5.3gearmansymfony-2.3

mmoreram/GearmanBundle throws exception on calling \GearmanClient method


When I execute the following code:

$Gearman = $this->get('gearman');
$Gearman->doNormalJob('BundleName~test');

My code throws the following exception:

GearmanClient::doNormal() expects parameter 2 to be string, array given

Stack:

#0 [internal function]: Symfony\Component\Debug\ErrorHandler->handle(2, 'GearmanClient::...', '/Users/reneters...', 178, Array)
#1 /Users/reneterstegen/Sites/core.xxx.nl/vendor/mmoreram/gearman-bundle/Mmoreram/GearmanBundle/Service/GearmanClient.php(178): GearmanClient->doNormal('XXXBundleCoreBu...', Array, NULL)
#2 /Users/reneterstegen/Sites/core.xxx.nl/vendor/mmoreram/gearman-bundle/Mmoreram/GearmanBundle/Service/GearmanClient.php(153): Mmoreram\GearmanBundle\Service\GearmanClient->doEnqueue(Array, Array, 'doNormal', NULL)
#3 /Users/reneterstegen/Sites/core.xxx.nl/vendor/mmoreram/gearman-bundle/Mmoreram/GearmanBundle/Service/GearmanClient.php(266): Mmoreram\GearmanBundle\Service\GearmanClient->enqueue('XXXBundleCoreBu...', Array, 'doNormal', NULL)
#4 /Users/reneterstegen/Sites/core.xxx.nl/src/XXX/Bundle/CoreBundle/Controller/TestController.php(32): Mmoreram\GearmanBundle\Service\GearmanClient->doNormalJob('XXXBundleCoreBu...')
#5 [internal function]: XXX\Bundle\CoreBundle\Controller\TestController->testAction()
#6 /Users/reneterstegen/Sites/core.xxx.nl/app/bootstrap.php.cache(2815): call_user_func_array(Array, Array)
#7 /Users/reneterstegen/Sites/core.xxx.nl/app/bootstrap.php.cache(2789): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#8 /Users/reneterstegen/Sites/core.xxx.nl/app/bootstrap.php.cache(2918): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#9 /Users/reneterstegen/Sites/core.xxx.nl/app/bootstrap.php.cache(2220): Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#10 /Users/reneterstegen/Sites/core.xxx.nl/web/app_dev.php(19): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#11 {main}

When I go down to the code the exception is thrown in this function:

/**
 * Execute a GearmanClient call given a worker, params and a method.
 *
 * If he GarmanClient call is asyncronous, result value will be a handler.
 * Otherwise, will return job result.
 *
 * @param array  $worker Worker definition
 * @param mixed  $params Parameters to send to job
 * @param string $method Method to execute
 * @param string $unique A unique ID used to identify a particular task
 *
 * @return mixed  Return result of the GearmanClient call
 */
private function doEnqueue(Array $worker, $params = '', $method = null, $unique = null)
{
    $gearmanClient = new \GearmanClient();
    $this->assignServers($gearmanClient);

    return $gearmanClient->$method($worker['job']['realCallableName'], $params, $unique);
}

Caused by:

public function doNormalJob($name, $params = array(), $unique = null)
{

    return $this->enqueue($name, $params, GearmanMethods::GEARMAN_METHOD_DONORMAL, $unique);
}

Here the default value for $params = array(). In the rest of the chain this parameter is not altered so an array will be given to de doNormal method.

Can anybody tell me how to fix this? Is this a bug? A misconfiguration? Something else?

Thanks in advance!


Solution

  • I posted this as issue to the developers of the bundle. They confirmed this is a bug a fixed it immediately.

    See: https://github.com/mmoreram/GearmanBundle/issues/45