Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bupy7 committed Nov 22, 2017
1 parent cab280a commit 7af86b1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php
php:
- '7.1'
- '7.2'

before_script:
- composer install --no-interaction
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
zf-queue
========

1.0.1 [2017-11-22]
------------------

- Fix: Skiped the param in the `Bupy7\Queue\Manager\EntityManagerInterface::flush()` method.
- Enh: Small enhancements.
- Add: `executed` event in the `Bupy7\Queue\Service\QueueService`.

1.0.0 [2017-09-13]
------------------

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bupy7/zf-queue",
"description": "Queue module for Zend Framework 3.",
"version": "1.0.0",
"version": "1.0.1",
"license": "BSD-3-Clause",
"keywords": [
"zend",
Expand Down
7 changes: 6 additions & 1 deletion src/Manager/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ interface EntityManagerInterface
* @return object|null
*/
public function newInstance(string $name);

/**
* @param object $entity
*/
public function persist($entity): void;
public function flush(): void;

/**
* @param object|null $entity
*/
public function flush($entity = null): void;
}
5 changes: 3 additions & 2 deletions src/Repository/TaskRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
interface TaskRepositoryInterface
{
/**
* Returns entities has status Task::STATUS_RUN or Task::STATUS_ERROR for run.
* @return \Bupy7\Queue\Entity\Task[]
* Returns entities has status \Bupy7\Queue\Entity\TaskInterface::STATUS_RUN or
* \Bupy7\Queue\Entity\TaskInterface::STATUS_ERROR for run.
* @return \Bupy7\Queue\Entity\TaskInterface[]
*/
public function findForRun(int $limit = null): array;
}
14 changes: 13 additions & 1 deletion src/Service/QueueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
class QueueService implements EventManagerAwareInterface
{
public const EVENT_ERROR_EXECUTE = 'errorExecute';
/**
* @since 1.0.1
*/
public const EVENT_EXECUTED = 'executed';
public const EVENT_BEFORE_ADD = 'beforeAdd';

use EventManagerAwareTrait;
Expand Down Expand Up @@ -101,13 +105,14 @@ protected function executeTask(TaskEntityInterface $entity): void
$task = $this->queueManager->get($entity->getName());

try {
if ($task->execute($entity->getParams())) {
if ($task->execute(clone $entity->getParams())) {
$entity->setStatusId(TaskEntityInterface::STATUS_OK);
} else {
$entity->setStatusId(TaskEntityInterface::STATUS_ERROR);
}
} catch (Exception $e) {
$entity->setStatusId(TaskEntityInterface::STATUS_ERROR);

// event trigger
$this->getEventManager()->trigger(self::EVENT_ERROR_EXECUTE, $this, [
'exception' => $e,
Expand All @@ -125,5 +130,12 @@ protected function executeTask(TaskEntityInterface $entity): void
$entity->setStopAt(new DateTime);
$this->entityManager->flush($entity);
}

if ($entity->getStatusId() === TaskEntityInterface::STATUS_OK) {
$this->getEventManager()->trigger(self::EVENT_EXECUTED, $this, [
'name' => $entity->getName(),
'params' => clone $entity->getParams(),
]);
}
}
}
2 changes: 1 addition & 1 deletion test/Assert/Manager/DummyEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function persist($entity): void
$this->persist[] = $entity;
}

public function flush(): void
public function flush($entity = null): void
{
foreach ($this->persist as $entity) {
$this->saved[spl_object_hash($entity)] = $entity;
Expand Down
26 changes: 26 additions & 0 deletions test/Functional/Service/QueueServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Zend\EventManager\EventInterface;
use Exception;
use Bupy7\Queue\Test\Assert\Entity\Task;
use Zend\Stdlib\ParametersInterface;

/**
* @author Belosludcev Vasily <https://github.com/bupy7>
Expand Down Expand Up @@ -134,4 +135,29 @@ public function testErrorExecuteEvent()
$this->assertInstanceOf(Exception::class, $eventException);
}
}

/**
* @since 1.0.1
*/
public function testExecutedEvent()
{
$sm = $this->getSm($this->memoryConfig);

$sm->get('MemoryTaskRepository')->entities = [
(new Task)->setId(1)->setName('Bupy7\Queue\Test\Assert\Task\SuccessHelloTask'),
];

$name = null;
$params = null;
$sm->get('MemoryQueueService')->getEventManager()
->attach(QueueService::EVENT_EXECUTED, function (EventInterface $event) use (&$name, &$params) {
$name = $event->getParam('name');
$params = $event->getParam('params');
});

$sm->get('MemoryQueueService')->run();

$this->assertInstanceOf(ParametersInterface::class, $params);
$this->assertEquals('Bupy7\Queue\Test\Assert\Task\SuccessHelloTask', $name);
}
}

0 comments on commit 7af86b1

Please sign in to comment.