Skip to content

Commit 1ee99e0

Browse files
authored
Refactored & factorized the way jobs are executed (#59)
* Refactored & factorized the way jobs are executed * Fixed PHP 8.0 array with keys unpack * Fixed checkstyle * Add missing JobContainer class comment * Add test case to prove status can be changed by event listeners * Fixed summary log array_merge * Simplified integration tests jobs building * Use PHP 8 promoted properties in JobContainer * Fixed docs after refactoring
1 parent d70acaa commit 1ee99e0

File tree

8 files changed

+52
-44
lines changed

8 files changed

+52
-44
lines changed

src/Resources/services/global/alias.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
<service id="Yokai\Batch\Registry\JobRegistry"
1414
alias="yokai_batch.job_registry"/>
1515

16+
<service id="Yokai\Batch\Job\JobExecutionAccessor"
17+
alias="yokai_batch.job_execution_accessor"/>
18+
19+
<service id="Yokai\Batch\Job\JobExecutor"
20+
alias="yokai_batch.job_executor"/>
21+
1622
<service id="Yokai\Batch\Factory\JobExecutionIdGeneratorInterface"
1723
alias="yokai_batch.job_execution_id_generator.uniqid"/>
1824
</services>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
<defaults public="false"/>
9+
10+
<service id="yokai_batch.job_execution_factory"
11+
class="Yokai\Batch\Factory\JobExecutionFactory">
12+
<argument type="service" id="Yokai\Batch\Factory\JobExecutionIdGeneratorInterface"/>
13+
</service>
14+
15+
<service id="yokai_batch.job_registry"
16+
class="Yokai\Batch\Registry\JobRegistry">
17+
<argument/>
18+
</service>
19+
20+
<service id="yokai_batch.job_execution_accessor"
21+
class="Yokai\Batch\Job\JobExecutionAccessor">
22+
<argument type="service" id="yokai_batch.job_execution_factory"/>
23+
<argument type="service" id="Yokai\Batch\Storage\JobExecutionStorageInterface"/>
24+
</service>
25+
26+
<service id="yokai_batch.job_executor"
27+
class="Yokai\Batch\Job\JobExecutor">
28+
<argument type="service" id="yokai_batch.job_registry"/>
29+
<argument type="service" id="Yokai\Batch\Storage\JobExecutionStorageInterface"/>
30+
<argument type="service" id="event_dispatcher" on-invalid="null"/>
31+
</service>
32+
33+
<service id="yokai_batch.job_execution_id_generator.uniqid"
34+
class="Yokai\Batch\Factory\UniqidJobExecutionIdGenerator"/>
35+
</services>
36+
</container>

src/Resources/services/global/factory.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Resources/services/global/launcher.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
<service id="yokai_batch.job_launcher.simple"
1111
class="Yokai\Batch\Launcher\SimpleJobLauncher">
12-
<argument type="service" id="yokai_batch.job_registry"/>
13-
<argument type="service" id="yokai_batch.job_execution_factory"/>
14-
<argument type="service" id="Yokai\Batch\Storage\JobExecutionStorageInterface"/>
15-
<argument type="service" id="event_dispatcher" on-invalid="null"/>
12+
<argument type="service" id="yokai_batch.job_execution_accessor"/>
13+
<argument type="service" id="yokai_batch.job_executor"/>
1614
</service>
1715
</services>
1816
</container>

src/Resources/services/global/registry.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Resources/services/symfony/console/command.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
<service id="yokai_batch.run_job_command"
1111
class="Yokai\Batch\Bridge\Symfony\Console\RunJobCommand">
12-
<argument type="service" id="yokai_batch.job_launcher.simple"/>
12+
<argument type="service" id="yokai_batch.job_execution_accessor"/>
13+
<argument type="service" id="yokai_batch.job_executor"/>
1314
<tag name="console.command"/>
1415
</service>
1516
</services>

tests/Fixtures/DummyJob.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Yokai\Batch\Tests\Bridge\Symfony\Framework\Fixtures;
66

7-
use Yokai\Batch\Job\AbstractJob;
7+
use Yokai\Batch\Job\JobInterface;
88
use Yokai\Batch\JobExecution;
99

10-
final class DummyJob extends AbstractJob
10+
final class DummyJob implements JobInterface
1111
{
12-
protected function doExecute(JobExecution $jobExecution): void
12+
public function execute(JobExecution $jobExecution): void
1313
{
1414
// dummy
1515
}

tests/Fixtures/DummyJobWithName.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
namespace Yokai\Batch\Tests\Bridge\Symfony\Framework\Fixtures;
66

77
use Yokai\Batch\Bridge\Symfony\Framework\JobWithStaticNameInterface;
8-
use Yokai\Batch\Job\AbstractJob;
8+
use Yokai\Batch\Job\JobInterface;
99
use Yokai\Batch\JobExecution;
1010

11-
final class DummyJobWithName extends AbstractJob implements JobWithStaticNameInterface
11+
final class DummyJobWithName implements JobInterface, JobWithStaticNameInterface
1212
{
1313
public static function getJobName(): string
1414
{
1515
return 'export_orders_job';
1616
}
1717

18-
protected function doExecute(JobExecution $jobExecution): void
18+
public function execute(JobExecution $jobExecution): void
1919
{
2020
// dummy
2121
}

0 commit comments

Comments
 (0)