0

次のコードを実行すると:

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

私のコードは次の例外をスローします:

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

スタック:

#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}

コードに進むと、この関数で例外がスローされます。

/**
 * 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);
}

のせいで:

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

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

ここでは のデフォルト値です$params = array()。チェーンの残りの部分では、このパラメーターは変更されないため、配列が doNormal メソッドに渡されます。

誰でもこれを修正する方法を教えてもらえますか? これはバグですか?設定ミス?他の何か?

前もって感謝します!

4

2 に答える 2

1

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.

ご提供いただいた情報によると、次のオプションがあるようです

  1. デフォルトの配列ではなく null になるようにインターフェイスを更新します。
  2. 2 番目のパラメーターとして null 値を渡します (ハッキー)。

そもそも配列がデフォルトである理由は興味深いです。より一般的には、ペイロードとして使用されるのはオブジェクトです。

残りのコードを投稿すると、より確実に言うことができます.

于 2013-09-24T22:39:31.190 に答える