Skip to content

Commit

Permalink
auto-unique-value-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
beliveyourdream committed Nov 6, 2013
1 parent 1808289 commit f7b9184
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('job_prefix')
->defaultValue(null)
->scalarNode('generate-unique-key')
->defaultValue(true)
->end()
->end()
->end()
Expand Down
20 changes: 20 additions & 0 deletions Service/GearmanClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ private function enqueue($jobName, $params = '', $method = null, $unique = null)
{
$worker = $this->getJob($jobName);

if ($this->settings['generate-unique-key']) {
$unique = $this->generateUniqueKey($jobName, $params);
}

if (false !== $worker) {

return $this->doEnqueue($worker, $params, $method, $unique);
Expand Down Expand Up @@ -529,6 +533,10 @@ public function addTaskLowBackground($name, $params = '', &$context = null, $uni
*/
private function enqueueTask($name, $params, $context, $unique, $method)
{
if ($this->settings['generate-unique-key']) {
$unique = $this->generateUniqueKey($name, $params);
}

$task = array(
'name' => $name,
'params' => $params,
Expand Down Expand Up @@ -590,4 +598,16 @@ public function runTasks()

return $gearmanClient->runTasks();
}

/**
* Generates a unique string if null
*
* @param string $name
* @param string $params
* @return null|string
*/
private function generateUniqueKey($name, $params = '')
{
return md5($name.$params);
}
}

0 comments on commit f7b9184

Please sign in to comment.