Question

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!

Was it helpful?

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

OTHER TIPS

I've not familiar with the bundle, but the doNormal() method of the \Gearmanclient expects a string payload (normally in the form of a serialized entity), but your interface is expecting an array.

The part you are not showing us (the "enqueue" method) may attempt to serialize the content, or maybe it's just delegating. Without seeing the code we cannot be certain.

From what you've given us, it looks like you have the following options

  1. Update the interface to not default to an array, but null instead
  2. Pass a null value as the second parameter (hacky).

It's interesting why they are defaulting to an array in the first place, more commonly it's objects that are used as payloads.

Post the rest of the code and we can say with more certainty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top