Skip to content

Commit a9e3e94

Browse files
committed
fix: don't show always scheduled tasks are wrong, fixes #97
1 parent 7badc66 commit a9e3e94

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/Components/Health/Checker/HealthChecker/TaskChecker.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
1313
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\RangeFilter;
1414
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskDefinition;
15+
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskEntity;
16+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
1517

1618
class TaskChecker implements CheckerInterface
1719
{
1820
private EntityRepositoryInterface $scheduledTaskRepository;
1921

20-
public function __construct(EntityRepositoryInterface $scheduledTaskRepository)
22+
private ParameterBagInterface $parameterBag;
23+
24+
public function __construct(EntityRepositoryInterface $scheduledTaskRepository, ParameterBagInterface $parameterBag)
2125
{
2226
$this->scheduledTaskRepository = $scheduledTaskRepository;
27+
$this->parameterBag = $parameterBag;
2328
}
2429

2530
public function collect(HealthCollection $collection): void
@@ -44,9 +49,20 @@ public function collect(HealthCollection $collection): void
4449
));
4550

4651
$oldTasks = $this->scheduledTaskRepository
47-
->searchIds($criteria, Context::createDefaultContext())->getIds();
52+
->search($criteria, Context::createDefaultContext());
53+
54+
$oldTasks = $oldTasks->filter(function (ScheduledTaskEntity $task) {
55+
$taskClass = $task->getScheduledTaskClass();
56+
57+
// Old Shopware version
58+
if (!method_exists($taskClass, 'shouldRun')) {
59+
return true;
60+
}
61+
62+
return $taskClass::shouldRun($this->parameterBag);
63+
});
4864

49-
if (count($oldTasks) === 0) {
65+
if ($oldTasks->count() === 0) {
5066
$collection->add(SettingsResult::ok('frosh-tools.checker.scheduledTaskGood'));
5167

5268
return;

src/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109

110110
<service id="Frosh\Tools\Components\Health\Checker\HealthChecker\TaskChecker">
111111
<argument type="service" id="scheduled_task.repository"/>
112+
<argument type="service" id="parameter_bag"/>
112113
<tag name="frosh_tools.health_checker"/>
113114
</service>
114115

0 commit comments

Comments
 (0)