<?php
namespace App\EventListener;
use App\Event\PreExecutionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Process\Process;
class PreExecutionListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
PreExecutionEvent::NAME => 'onPreExecution',
];
}
public function onPreExecution(PreExecutionEvent $event)
{
$targetDateTime = $event->getTargetDateTime();
// Calculate the execution time 5 minutes before the target datetime
$executionTime = clone $targetDateTime;
$executionTime->sub(new \DateInterval('PT1M'));
// Replace with your actual command
$command = ['php', '/Users/yacoubadoumbia/Sites/e-learning/src/bin/console', 'app:test-mail:sending'];
// Schedule the command execution using Symfony Process
$process = new Process($command);
$process->setTimeout(null); // No timeout
$process->run();
}
}