Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Classes/Job/Aspect/DeferMethodCallAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class DeferMethodCallAspect
protected $reflectionService;

/**
* @var boolean
* @var string
*/
protected $processingJob = false;
protected string $processingMethodCallHash = '';

/**
* @param JoinPointInterface $joinPoint The current join point
Expand All @@ -50,7 +50,7 @@ class DeferMethodCallAspect
*/
public function queueMethodCallAsJob(JoinPointInterface $joinPoint)
{
if ($this->processingJob) {
if ($this->processingMethodCallHash === StaticMethodCallJob::methodCallHash($joinPoint->getClassName(), $joinPoint->getMethodName())) {
return $joinPoint->getAdviceChain()->proceed($joinPoint);
}
/** @var Defer $deferAnnotation */
Expand All @@ -62,10 +62,10 @@ public function queueMethodCallAsJob(JoinPointInterface $joinPoint)
}

/**
* @param boolean $processingJob
* @param string $processingMethodCallHash
*/
public function setProcessingJob($processingJob)
public function setProcessingMethodCallHash(string $processingMethodCallHash): void
{
$this->processingJob = $processingJob;
$this->processingMethodCallHash = $processingMethodCallHash;
}
}
9 changes: 7 additions & 2 deletions Classes/Job/StaticMethodCallJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public function __construct($className, $methodName, array $arguments)
public function execute(QueueInterface $queue, Message $message): bool
{
$service = $this->objectManager->get($this->className);
$this->deferMethodCallAspect->setProcessingJob(true);
$this->deferMethodCallAspect->setProcessingMethodCallHash(static::methodCallHash($this->className, $this->methodName));
try {
$methodName = $this->methodName;
call_user_func_array([$service, $methodName], $this->arguments);
return true;
} catch (\Exception $exception) {
throw $exception;
} finally {
$this->deferMethodCallAspect->setProcessingJob(false);
$this->deferMethodCallAspect->setProcessingMethodCallHash('');
}
}

Expand All @@ -95,4 +95,9 @@ public function getLabel(): string
$arguments = array_map([VariableDumper::class, 'dumpValue'], $this->arguments);
return sprintf('%s::%s(%s)', $this->className, $this->methodName, implode(', ', $arguments));
}

public static function methodCallHash($className, $methodName): string
{
return md5($className . '::' . $methodName);
}
}