|
@@ -13,6 +13,7 @@ namespace Mmoreram\GearmanBundle\Generator;
|
|
|
* Job Unique Key generator
|
|
|
*
|
|
|
* @author Marc Morera <yuhu@mmoreram.com>
|
|
|
+ * @see https://github.com/mmoreram/GearmanBundle/issues/66
|
|
|
*/
|
|
|
class UniqueJobIdentifierGenerator
|
|
|
{
|
|
@@ -40,6 +41,8 @@ class UniqueJobIdentifierGenerator
|
|
|
* Generate unique key if generateUniqueKey is enabled
|
|
|
*
|
|
|
* Even some parameters are not used, are passed to allow user overwrite method
|
|
|
+ *
|
|
|
+ * Also, if name and unique value exceeds 114 bytes, an exception is thrown
|
|
|
*
|
|
|
* @param string $name A GermanBundle registered function to be executed
|
|
|
* @param string $params Parameters to send to task as string
|
|
@@ -47,11 +50,20 @@ class UniqueJobIdentifierGenerator
|
|
|
* @param string $method Method to perform
|
|
|
*
|
|
|
* @return string Generated Unique Key
|
|
|
+ *
|
|
|
+ * @throws WorkerNameTooLongException If name is too large
|
|
|
*/
|
|
|
public function generateUniqueKey($name, $params, $unique, $method)
|
|
|
{
|
|
|
- return ( !$unique && $this->generateUniqueKey )
|
|
|
+ $unique = !$unique && $this->generateUniqueKey
|
|
|
? md5($name . $params)
|
|
|
: $unique;
|
|
|
+
|
|
|
+ if (strlen($name . $unique) > 114) {
|
|
|
+
|
|
|
+ throw new WorkerNameTooLongException;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $unique;
|
|
|
}
|
|
|
}
|