|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of forecast.it.fill project. |
|
7
|
|
|
* (c) Patrick Jaja <[email protected]> |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ForecastAutomation\ForecastDataImport\Business; |
|
13
|
|
|
|
|
14
|
|
|
use ForecastAutomation\Activity\ActivityFacade; |
|
15
|
|
|
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection; |
|
16
|
|
|
use ForecastAutomation\ForecastClient\Shared\Config\ForecastClientQueueConstants; |
|
17
|
|
|
use ForecastAutomation\QueueClient\QueueClientFacade; |
|
18
|
|
|
use ForecastAutomation\QueueClient\Shared\Dto\MessageCollectionDto; |
|
19
|
|
|
use ForecastAutomation\QueueClient\Shared\Dto\MessageDto; |
|
20
|
|
|
|
|
21
|
|
|
class ForecastDataImportProcess |
|
22
|
|
|
{ |
|
23
|
1 |
|
public function __construct( |
|
24
|
|
|
private ActivityFacade $activityFacade, |
|
25
|
|
|
private QueueClientFacade $queueClientFacade, |
|
26
|
|
|
) { |
|
27
|
1 |
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
public function start(): int |
|
30
|
|
|
{ |
|
31
|
1 |
|
$activityDtoCollection = $this->activityFacade->collect(); |
|
32
|
1 |
|
$this->queueClientFacade->sendMessages( |
|
33
|
1 |
|
ForecastClientQueueConstants::QUEUE_NAME, |
|
34
|
1 |
|
$this->createMessageCollectionDto($activityDtoCollection) |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
1 |
|
return \count($activityDtoCollection->activityDtos); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
private function createMessageCollectionDto(ActivityDtoCollection $activityDtoCollection): MessageCollectionDto |
|
41
|
|
|
{ |
|
42
|
1 |
|
$messages = []; |
|
43
|
1 |
|
foreach ($activityDtoCollection as $activityDto) { |
|
44
|
|
|
$messages[] = |
|
45
|
1 |
|
new MessageDto( |
|
46
|
1 |
|
['created' => $activityDto->created->format('c')] + (array) $activityDto, |
|
47
|
1 |
|
ForecastClientQueueConstants::QUEUE_NAME, |
|
48
|
1 |
|
ForecastClientQueueConstants::IMPORT_EVENT |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
return new MessageCollectionDto(...$messages); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|