Skip to content

Commit 888ce0f

Browse files
added selective flush to repositories (#28)
1 parent d64594f commit 888ce0f

File tree

5 files changed

+9
-32
lines changed

5 files changed

+9
-32
lines changed

src/Command/RunCommand.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Task\TaskBundle\Command;
1313

14-
use Doctrine\ORM\EntityManagerInterface;
1514
use Symfony\Component\Console\Command\Command;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Output\OutputInterface;
@@ -33,28 +32,17 @@ class RunCommand extends Command
3332
*/
3433
private $scheduler;
3534

36-
/**
37-
* @var EntityManagerInterface
38-
*/
39-
private $entityManager;
40-
4135
/**
4236
* @param string $name
4337
* @param TaskRunnerInterface $runner
4438
* @param TaskSchedulerInterface $scheduler
45-
* @param EntityManagerInterface $entityManager
4639
*/
47-
public function __construct(
48-
$name,
49-
TaskRunnerInterface $runner,
50-
TaskSchedulerInterface $scheduler,
51-
EntityManagerInterface $entityManager = null
52-
) {
40+
public function __construct($name, TaskRunnerInterface $runner, TaskSchedulerInterface $scheduler)
41+
{
5342
parent::__construct($name);
5443

5544
$this->runner = $runner;
5645
$this->scheduler = $scheduler;
57-
$this->entityManager = $entityManager;
5846
}
5947

6048
/**
@@ -72,9 +60,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
7260
{
7361
$this->runner->runTasks();
7462
$this->scheduler->scheduleTasks();
75-
76-
if ($this->entityManager) {
77-
$this->entityManager->flush();
78-
}
7963
}
8064
}

src/Command/RunHandlerCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function __construct($name, TaskHandlerFactoryInterface $handlerFactory)
4343
*/
4444
protected function configure()
4545
{
46-
$this->setDescription('Run pending tasks')
46+
$this
47+
->setDescription('Run pending tasks')
4748
->addArgument('handlerClass', InputArgument::REQUIRED)
4849
->addArgument('workload', InputArgument::OPTIONAL);
4950
}

src/Command/ScheduleTaskCommand.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Task\TaskBundle\Command;
1313

14-
use Doctrine\ORM\EntityManagerInterface;
1514
use Symfony\Component\Console\Command\Command;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputInterface;
@@ -29,22 +28,15 @@ class ScheduleTaskCommand extends Command
2928
*/
3029
private $scheduler;
3130

32-
/**
33-
* @var EntityManagerInterface
34-
*/
35-
private $entityManager;
36-
3731
/**
3832
* @param string $name
3933
* @param TaskSchedulerInterface $runner
40-
* @param EntityManagerInterface $entityManager
4134
*/
42-
public function __construct($name, TaskSchedulerInterface $runner, EntityManagerInterface $entityManager = null)
35+
public function __construct($name, TaskSchedulerInterface $runner)
4336
{
4437
parent::__construct($name);
4538

4639
$this->scheduler = $runner;
47-
$this->entityManager = $entityManager;
4840
}
4941

5042
/**
@@ -92,9 +84,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
9284
}
9385

9486
$taskBuilder->schedule();
95-
96-
if ($this->entityManager) {
97-
$this->entityManager->flush();
98-
}
9987
}
10088
}

src/Entity/TaskExecutionRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function create(TaskInterface $task, \DateTime $scheduleTime)
3737
public function save(TaskExecutionInterface $execution)
3838
{
3939
$this->_em->persist($execution);
40+
$this->_em->flush($execution);
4041

4142
return $this;
4243
}
@@ -47,6 +48,7 @@ public function save(TaskExecutionInterface $execution)
4748
public function remove(TaskExecutionInterface $execution)
4849
{
4950
$this->_em->remove($execution);
51+
$this->_em->flush($execution);
5052

5153
return $this;
5254
}

src/Entity/TaskRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function findByUuid($uuid)
4242
public function save(TaskInterface $task)
4343
{
4444
$this->_em->persist($task);
45+
$this->_em->flush($task);
4546

4647
return $this;
4748
}
@@ -52,6 +53,7 @@ public function save(TaskInterface $task)
5253
public function remove(TaskInterface $task)
5354
{
5455
$this->_em->remove($task);
56+
$this->_em->flush($task);
5557

5658
return $this;
5759
}

0 commit comments

Comments
 (0)