Commit 6e2498ab authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Retraitement asynchrone de fichier de thèse

parent 8340f1f5
Loading
Loading
Loading
Loading
+x+8
Changes for bin/fichier-retraiter.sh: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env bash

#destinataires=$1
#fichier=$2
#php ../public/index.php fichier retraiter --tester-archivabilite --notifier="${destinataires}" ${fichier}

args=$*
php ../public/index.php fichier retraiter ${args}
 No newline at end of file
+16 −5
Changes for config/autoload/global.php: 16 added lines, 5 removed lines.
Original line number Diff line number Diff line
<?php

use Application\Navigation\NavigationFactoryFactory;
use Retraitement\Filter\Command\CinesCommand;
use Retraitement\Filter\Command\MinesCommand;

return array(
@@ -10,7 +9,11 @@ return array(
            'check_ws_script_path' => __DIR__ . '/../../bin/from_cines/check_webservice_response.sh',
            'script_path'          => __DIR__ . '/../../bin/validation_cines.sh',
        ],

        'retraitement' => [
            /**
             * Commande utilisée pour retraiter les fichiers PDF, et ses options.
             */
            'command' => [
                'class' => MinesCommand::class,
                'options' => [
@@ -19,15 +22,23 @@ return array(
//                    'gs_args' => '-dPDFACompatibilityPolicy=1'
                ],
            ],

            /**
             * Durée au bout de laquelle le retraitement est interrompu pour le relancer en tâche de fond.
             * Valeurs possibles: '30s', '1m', etc. (cf. "man timeout").
             */
            'timeout' => '20s',
        ],

        'notification' => [
            // destinataires à mettre systématiquement en copie cachée des mails
            /**
             * Destinataires à ajouter systématiquement lors de l'envoi d'une notification.
             */
            'cc' => ['suivi-mail-sodoct@unicaen.fr'],
            //'bcc' => [],
        ],
    ],
    //'translator' => array(
        //'locale' => 'fr_FR',
    //),

    'service_manager' => array(
        'factories' => array(
            'navigation' => NavigationFactoryFactory::class,
+24 −3
Changes for module/Application/src/Application/Command/ShellScriptRunner.php: 24 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -27,6 +27,11 @@ class ShellScriptRunner
     */
    private $shell;

    /**
     * @var boolean
     */
    private $async = false;

    /**
     * Constructor.
     *
@@ -48,6 +53,17 @@ class ShellScriptRunner
        }
    }

    /**
     * @param bool $async
     * @return self
     */
    public function setAsync($async = true)
    {
        $this->async = $async;

        return $this;
    }

    /**
     * Lance le script.
     *
@@ -58,16 +74,21 @@ class ShellScriptRunner
    {
        $this->checkPrerequisites();

//        $scriptName = basename($this->scriptFilePath);

        chdir($this->scriptDirPath);

//        $command = sprintf("%s %s %s", $this->shell, $scriptName, $args);
        $command = $this->getCommandToString($args);

        if ($this->async) {
            $command = 'nohup ' . $command . ' > /dev/null 2>&1 &';
        }

        // exécution de la commande
        exec($command, $output, $returnCode);

        if ($this->async) {
            return null;
        }

        if (!is_array($output) || !isset($output[0])) {
            throw new RuntimeException(
                sprintf("La ligne de commande '%s' n'a retourné aucun résultat.", $command));
+23 −2
Changes for module/Application/src/Application/Controller/AbstractController.php: 23 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -5,9 +5,10 @@ namespace Application\Controller;
use Application\Controller\Plugin\Uploader\UploaderPlugin;
use Application\Controller\Plugin\UrlDoctorant;
use Application\Controller\Plugin\UrlFichierThese;
use Application\Controller\Plugin\UrlThese;
use Application\Controller\Plugin\Url\UrlThesePlugin;
use Application\Controller\Plugin\UrlWorkflow;
use Application\Entity\Db\These;
use Application\Entity\Db\Utilisateur;
use Application\RouteMatch;
use Application\Service\UserContextServiceAwareInterface;
use Application\Service\UserContextServiceAwareTrait;
@@ -25,7 +26,7 @@ use ZfcUser\Controller\Plugin\ZfcUserAuthentication;
 * @method HttpRequest getRequest()
 * @method UploaderPlugin uploader()
 * @method boolean isAllowed($resource, $privilege)
 * @method UrlThese urlThese()
 * @method UrlThesePlugin urlThese()
 * @method UrlDoctorant urlDoctorant()
 * @method UrlFichierThese urlFichierThese()
 * @method UrlWorkflow urlWorkflow()
@@ -37,6 +38,13 @@ class AbstractController extends AbstractActionController
{
    use UserContextServiceAwareTrait;

    /**
     * Pseudo-utilisateur correspondant à l'application elle-même.
     *
     * @var Utilisateur
     */
    protected $utilisateurApplication;

    /**
     * Teste si un privilège est accordé sur une ressource.
     * Si ce n'est pas le cas une exception est levée.
@@ -64,4 +72,17 @@ class AbstractController extends AbstractActionController

        return $routeMatch->getThese();
    }

    /**
     * Spécifie le Pseudo-utilisateur correspondant à l'application elle-même.
     *
     * @param Utilisateur $utilisateurApplication
     * @return self
     */
    public function setUtilisateurApplication(Utilisateur $utilisateurApplication)
    {
        $this->utilisateurApplication = $utilisateurApplication;

        return $this;
    }
}
 No newline at end of file
+38
Changes for module/Application/src/Application/Controller/Factory/TheseControllerFactory.php: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller\Factory;

use Application\Controller\TheseController;
use Zend\Mvc\Controller\ControllerManager;
use Zend\ServiceManager\ServiceLocatorInterface;

class TheseControllerFactory
{
    /**
     * Create service
     *
     * @param ControllerManager $controllerManager
     * @return TheseController
     */
    public function __invoke(ControllerManager $controllerManager)
    {
        $options = $this->getOptions($controllerManager->getServiceLocator());

        $service = new TheseController();
        $service->setTimeoutRetraitement($this->getTimeoutRetraitementFromOptions($options));

        return $service;
    }

    private function getTimeoutRetraitementFromOptions(array $options)
    {
        return isset($options['retraitement']['timeout']) ? $options['retraitement']['timeout'] : null;
    }

    private function getOptions(ServiceLocatorInterface $serviceLocator)
    {
        $options = $serviceLocator->get('config');

        return isset($options['sodoct']) ? $options['sodoct'] : [];
    }
}
 No newline at end of file
Loading