Commit 5abbea9b authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Corrections autour de la gestion de TimedOutCommandException

parent f6f6cccd
Loading
Loading
Loading
Loading
+2 −18
Changes for module/Application/src/Application/Command/AbstractCommand.php: 2 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

namespace Application\Command;

use Retraitement\Exception\TimedOutCommandException;
use Application\Command\Exception\TimedOutCommandException;
use UnicaenApp\Exception\LogicException;
use UnicaenApp\Exception\RuntimeException;

@@ -44,6 +44,7 @@ abstract class AbstractCommand implements CommandInterface

    /**
     * @return string
     * @throws TimedOutCommandException Si un timeout d'exécution a été défini et qu'il a expiré
     */
    public function execute()
    {
@@ -73,23 +74,6 @@ abstract class AbstractCommand implements CommandInterface
        return $output;
    }

    /**
     * Exécute la commande avec une limite de temps d'exécution.
     *
     * @param string $timeoutValue Ex: '60s', '1m', '2h', '1d'. Cf. "man timeout".
     * @return string
     */
    public function executeWithTimeout($timeoutValue = '20s')
    {
        if (!$this->commandLine) {
            throw new LogicException("La ligne de commande n'a pas été générée, utilisez generate().");
        }

        $this->commandLine = "timeout --signal=HUP $timeoutValue " . $this->commandLine;

        return $this->execute();
    }

    /**
     * @return int|null
     */
+2 −0
Changes for module/Application/src/Application/Command/CommandInterface.php: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Application\Command;

use Application\Command\Exception\TimedOutCommandException;
use UnicaenApp\Exception\RuntimeException;

interface CommandInterface
@@ -37,6 +38,7 @@ interface CommandInterface

    /**
     * @return string
     * @throws TimedOutCommandException Si un timeout d'exécution a été défini et qu'il a expiré
     */
    public function execute();

+3 −5
Changes for module/Application/src/Application/Command/Exception/TimedOutCommandException.php: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
<?php

namespace Retraitement\Exception;
namespace Application\Command\Exception;

use UnicaenApp\Exception\RuntimeException;

class TimedOutCommandException extends RuntimeException
class TimedOutCommandException extends \Exception
{
    private $timeout;

    /**
     * @param string $userFirendlyTimeout
     * @return TimedOutCommandException
     * @return $this
     */
    public function setTimeout($userFirendlyTimeout)
    {
+5 −1
Changes for module/Application/src/Application/Controller/FichierTheseController.php: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

namespace Application\Controller;

use Application\Command\Exception\TimedOutCommandException;
use Application\Entity\Db\Fichier;
use Application\Entity\Db\FichierThese;
use Application\Entity\Db\NatureFichier;
use Application\Entity\Db\These;
use Application\Entity\Db\VersionFichier;
use Application\EventRouterReplacerAwareTrait;
@@ -445,7 +445,11 @@ class FichierTheseController extends AbstractController
        }

        $pdcData = $this->theseService->fetchInformationsPageDeCouverture($these);
        try {
            $outputFilePath = $this->fichierTheseService->fusionnerPdcEtThese($these, $pdcData, $versionFichier, $removeFirstPage);
        } catch (TimedOutCommandException $e) {
            // n'arrive jamais car aucun timeout n'a été spécifié lors de l'appel à fusionnerPdcEtThese()
        }

        $this->eventRouterReplacer->replaceEventRouter($this->getEvent());

+3 −9
Changes for module/Application/src/Application/Controller/TheseController.php: 3 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Application\Controller;

use Application\Command\Exception\TimedOutCommandException;
use Application\Entity\Db\Attestation;
use Application\Entity\Db\Diffusion;
use Application\Entity\Db\FichierThese;
@@ -24,8 +25,6 @@ use Application\Form\MetadonneeTheseForm;
use Application\Form\PointsDeVigilanceForm;
use Application\Form\RdvBuTheseDoctorantForm;
use Application\Form\RdvBuTheseForm;
use Application\Rule\AutorisationDiffusionRule;
use Application\Rule\SuppressionAttestationsRequiseRule;
use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\FichierThese\Exception\ValidationImpossibleException;
use Application\Service\FichierThese\FichierTheseServiceAwareTrait;
@@ -48,7 +47,6 @@ use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\Tools\Pagination\Paginator;
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator;
use Import\Service\Traits\ImportServiceAwareTrait;
use Retraitement\Exception\TimedOutCommandException;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenApp\Service\MessageCollectorAwareTrait;
@@ -808,8 +806,6 @@ class TheseController extends AbstractController
                } catch (TimedOutCommandException $toce) {
                    // relancer le retraitement en tâche de fond
                    $this->fichierTheseService->creerFichierTheseRetraiteAsync($fichierVersionOriginale);
                } catch (RuntimeException $re) {
                    // erreur prévue
                }
            }
            return $this->redirect()->toRoute(null, [], ['query'=>$this->params()->fromQuery()], true);
@@ -1569,7 +1565,7 @@ class TheseController extends AbstractController
        $pdcData = $this->theseService->fetchInformationsPageDeCouverture($these);

        try {
            // Un timeout peut être appliqué au lancement du  script de retraitement.
            // Un timeout peut être appliqué au lancement du  script.
            // Si ce timout est atteint, l'exécution du script est interrompue
            // et une exception TimedOutCommandException est levée.
            $timeout = $this->timeoutRetraitement;
@@ -1578,10 +1574,8 @@ class TheseController extends AbstractController
            $destinataires = [ $this->userContextService->getIdentityDb()->getEmail() ] ;
            // relancer le retraitement en tâche de fond
            $this->fichierTheseService->fusionneFichierTheseAsync($these, $versionFichier, $removal, $destinataires);

            return $this->redirect()->toRoute('these/rdv-bu', ['these' => $these->getId(), 'asynchronous' => 1], [], true);
            exit();
        } catch (RuntimeException $re) {
            // erreur prévue
        }

        /** Retourner un PDF ...  */
Loading