Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schedule jobs from CronTask instead of running them directly #86

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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