Commit 2bf539ee authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Amélioration des logs

parent 295796ae
Loading
Loading
Loading
Loading
Loading
+6 −3
Changes for module/Import/src/Import/Exception/CallException.php: 6 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Util;
use Zend\Http\Response;

class CallException extends RuntimeException
@@ -19,7 +20,6 @@ class CallException extends RuntimeException
    static public function badConfig(\Exception $previous = null)
    {
        return new self("La config fournie est incorrecte.", null, $previous);

    }

    static public function unexpectedResponse($uri, Response $response)
@@ -27,9 +27,12 @@ class CallException extends RuntimeException
        return new self("Mauvaise réponse du WS (URI '$uri') ! Status : " . $response->getStatusCode());
    }

    static public function invalidJSON($uri)
    static public function invalidJSONResponse($uri, $responseBody)
    {
        return new self("Impossible de décoder la réponse JSON du WS (URI '$uri') : " . json_last_error_msg());
        return new self(sprintf(
            "Erreur rencontrée lors du décodage de la réponse JSON du WS (URI '%s') : %s. Début de la réponse reçue : %s",
            $uri, json_last_error_msg(), Util::truncatedString($responseBody, 100)
        ));
    }

    static public function clientError(ClientException $error)
+2 −2
Changes for module/Import/src/Import/Service/CallService.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ class CallService
        $json = json_decode($response->getBody());
        if ($json === null) {
            // NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.
            throw CallException::invalidJSON($uri);
            throw CallException::invalidJSONResponse($uri, (string)$response->getBody());
        }

        return $json;
@@ -106,7 +106,7 @@ class CallService
        $json = json_decode($response->getBody());
        if ($json === null) {
            // NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.
            throw CallException::invalidJSON($uri);
            throw CallException::invalidJSONResponse($uri, (string)$response->getBody());
        }

        return $json;
+13 −4
Changes for module/Import/src/Import/Service/FetcherService.php: 13 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@ class FetcherService
     */
    private function fetchRow($serviceName, $entityClass, $sourceCode)
    {
        $this->logger->info(sprintf("Import: service %s[%s]", $serviceName, $sourceCode));

        $debut = microtime(true);
        $startDate = new DateTime();

@@ -164,14 +166,19 @@ class FetcherService
                throw new RuntimeException("Erreur lors de la mise à jour de la table $tableName en BDD", null, $e);
            }
        }
        $_fin = microtime(true);
        $this->logger->info(sprintf("Exécution des %d requêtes INSERT : %s secondes.", count($queries), $_fin - $_debut));

        /** Commit **/
        try {
            $this->entityManager->getConnection()->commit();
        } catch (ConnectionException $e) {
            throw new RuntimeException("Le commit a échoué", null, $e);
        } catch (\Exception $e) {
            $this->insertLog($debut, $uri, "ERROR_DB", $e->getMessage());
            return;
            throw new RuntimeException("Erreur inattendue", null, $e);
        }
        $_fin = microtime(true);
        $this->logger->info(sprintf("Exécution des %d requêtes INSERT : %s secondes.", count($queries), $_fin - $_debut));
        $this->logger->debug("Commit : " . ($_fin - $_debut) . " secondes.");

        $this->insertLog(
            $startDate,
@@ -189,6 +196,8 @@ class FetcherService
     */
    public function fetchRows($service, $entityClass, array $filters = [])
    {
        $this->logger->info(sprintf("Import: service '%s'", $service));

        $debut = microtime(true);
        $startDate = new DateTime();

@@ -267,7 +276,7 @@ class FetcherService
            throw new RuntimeException("Erreur inattendue", null, $e);
        }
        $_fin = microtime(true);
        $this->logger->info("Commit : " . ($_fin - $_debut) . " secondes.");
        $this->logger->debug("Commit : " . ($_fin - $_debut) . " secondes.");

        $fin = microtime(true);