Skip to content

Commit

Permalink
fix: schedule jobs from CronTask instead of running them directly
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarlovi committed Nov 2, 2022
1 parent 2e003e9 commit ec26190
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ProcessManagerBundle/Maintenance/CronTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
use Pimcore\Maintenance\TaskInterface;
use CoreShop\Component\Registry\ServiceRegistry;
use Cron\CronExpression;
use ProcessManagerBundle\Message\ProcessMessage;
use ProcessManagerBundle\Model\Executable;
use Symfony\Component\Messenger\MessageBusInterface;

class CronTask implements TaskInterface
{
private ServiceRegistry $registry;
private MessageBusInterface $messageBus;

public function __construct(ServiceRegistry $registry)
public function __construct(ServiceRegistry $registry, MessageBusInterface $messageBus)
{
$this->registry = $registry;
$this->messageBus = $messageBus;
}

public function execute()
Expand All @@ -43,7 +47,8 @@ public function execute()
if($cron->getPreviousRunDate() > $lastrun) {
$executable->setLastrun($cron->getPreviousRunDate()->getTimestamp());
$executable->save();
$this->registry->get($executable->getType())->run($executable);

$this->messageBus->dispatch(new ProcessMessage($exe->getId()));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ProcessManagerBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ services:
ProcessManagerBundle\Maintenance\CronTask:
arguments:
- '@process_manager.registry.processes'
- '@messenger.default_bus'
tags:
- { name: pimcore.maintenance.task, type: process_manager.maintenance.cron }

Expand Down

0 comments on commit ec26190

Please sign in to comment.