Skip to content

Commit

Permalink
Job processor updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasHermanek committed Sep 26, 2024
1 parent 16dea16 commit da4ffc2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
21 changes: 19 additions & 2 deletions src/Domain/Job/Processor/JobPodcastSynchronizerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use AnzuSystems\SerializerBundle\Exception\SerializerException;
use DateTimeInterface;
use Generator;
use Throwable;

final class JobPodcastSynchronizerProcessor extends AbstractJobProcessor
{
Expand Down Expand Up @@ -45,10 +46,26 @@ public static function getSupportedJob(): string

/**
* @param JobPodcastSynchronizer $job
*
* @throws SerializerException
*/
public function process(JobInterface $job): void
{
try {
$this->start($job);
$this->entityManager->beginTransaction();
$this->processPodcasts($job);
$this->entityManager->commit();
} catch (Throwable $throwable) {
if ($this->entityManager->getConnection()->isTransactionActive()) {
$this->entityManager->rollback();
}
$this->finishFail($job, $throwable);
}
}

/**
* @throws SerializerException
*/
private function processPodcasts(JobPodcastSynchronizer $job): void
{
if ($job->isFullSync()) {
$this->importFull(
Expand Down
17 changes: 9 additions & 8 deletions src/Domain/Podcast/PodcastImportIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AnzuSystems\CoreDamBundle\Domain\Podcast;

use AnzuSystems\CoreDamBundle\App;
use AnzuSystems\CoreDamBundle\Entity\Podcast;
use AnzuSystems\CoreDamBundle\Exception\InvalidArgumentException;
use AnzuSystems\CoreDamBundle\HttpClient\RssClient;
Expand All @@ -18,6 +19,8 @@

final readonly class PodcastImportIterator
{
private const string MIN_IMPORT_FROM_MODIFIER = '- 3 months';

public function __construct(
private RssClient $client,
private PodcastRssReader $reader,
Expand Down Expand Up @@ -74,7 +77,7 @@ public function iteratePodcast(PodcastSynchronizerPointer $pointer, Podcast $pod

return;
}
$startFromDate = $this->getImportFrom($pointer, $podcastToImport);
$startFromDate = $this->getImportFrom($pointer);

foreach ($this->reader->readItems($startFromDate) as $podcastItem) {
yield new PodcastImportIteratorDto(
Expand All @@ -85,18 +88,16 @@ public function iteratePodcast(PodcastSynchronizerPointer $pointer, Podcast $pod
}
}

private function getImportFrom(PodcastSynchronizerPointer $pointer, Podcast $podcast): ?DateTimeImmutable
private function getImportFrom(PodcastSynchronizerPointer $pointer): ?DateTimeImmutable
{
if (null === $podcast->getDates()->getImportFrom()) {
return $pointer->getPubDate();
}
$minImportFrom = App::getAppDate()->modify(self::MIN_IMPORT_FROM_MODIFIER);

if (null === $pointer->getPubDate()) {
return $podcast->getDates()->getImportFrom();
return $minImportFrom;
}

return $podcast->getDates()->getImportFrom() > $pointer->getPubDate()
? $podcast->getDates()->getImportFrom()
return $minImportFrom > $pointer->getPubDate()
? $minImportFrom
: $pointer->getPubDate();
}

Expand Down
2 changes: 0 additions & 2 deletions src/Elasticsearch/IndexFactory/AssetIndexFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
use AnzuSystems\CoreDamBundle\Entity\Asset;
use AnzuSystems\CoreDamBundle\Entity\AssetSlot;
use AnzuSystems\CoreDamBundle\Entity\AudioFile;
use AnzuSystems\CoreDamBundle\Entity\Author;
use AnzuSystems\CoreDamBundle\Entity\DocumentFile;
use AnzuSystems\CoreDamBundle\Entity\ImageFile;
use AnzuSystems\CoreDamBundle\Entity\Interfaces\ExtSystemIndexableInterface;
use AnzuSystems\CoreDamBundle\Entity\Keyword;
use AnzuSystems\CoreDamBundle\Entity\PodcastEpisode;
use AnzuSystems\CoreDamBundle\Entity\VideoFile;
use AnzuSystems\CoreDamBundle\Helper\CollectionHelper;
Expand Down
3 changes: 2 additions & 1 deletion src/Elasticsearch/QueryFactory/AssetQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ protected function getFilter(SearchDtoInterface $searchDto): array

if (UuidHelper::isUuid($searchDto->getText())) {
$filter[] = $this->getAssetIdAndMainFileIdFilter([$searchDto->getText()]);

// other filters should not be applied
return $filter;
}


if (false === empty($searchDto->getAssetAndMainFileIds())) {
$filter[] = $this->getAssetIdAndMainFileIdFilter($searchDto->getAssetAndMainFileIds());

// other filters should not be applied
return $filter;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Elasticsearch/SearchDto/AssetAdmSearchDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ public function getAuthorIds(): array
public function setAuthorIds(array $authorIds): self
{
$this->authorIds = $authorIds;

return $this;
}

Expand All @@ -670,6 +671,7 @@ public function getMainFileIds(): array
public function setMainFileIds(array $mainFileIds): self
{
$this->mainFileIds = $mainFileIds;

return $this;
}

Expand All @@ -681,6 +683,7 @@ public function getCreatedByIds(): array
public function setCreatedByIds(array $createdByIds): self
{
$this->createdByIds = $createdByIds;

return $this;
}

Expand All @@ -692,6 +695,7 @@ public function getAssetAndMainFileIds(): array
public function setAssetAndMainFileIds(array $assetAndMainFileIds): self
{
$this->assetAndMainFileIds = $assetAndMainFileIds;

return $this;
}
}
6 changes: 6 additions & 0 deletions src/Entity/Embeds/PodcastDates.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ public function __construct()
$this->setImportFrom(null);
}

/**
* @deprecated
*/
public function getImportFrom(): ?DateTimeImmutable
{
return $this->importFrom;
}

/**
* @deprecated
*/
public function setImportFrom(?DateTimeImmutable $importFrom): self
{
$this->importFrom = $importFrom;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/elasticsearch/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'type' => 'text',
'analyzer' => 'edgegrams',
],
]
],
],
'type' => [
'type' => 'keyword',
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/elasticsearch/keyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'type' => 'text',
'analyzer' => 'edgegrams',
],
]
],
],
'createdAt' => [
'type' => 'date',
Expand Down

0 comments on commit da4ffc2

Please sign in to comment.