diff --git a/Controller/PrinterController.php b/Controller/PrinterController.php index 74183e1..89b679d 100755 --- a/Controller/PrinterController.php +++ b/Controller/PrinterController.php @@ -612,13 +612,13 @@ class PrinterController extends Controller { $n_printers = $this->em->createQuery('SELECT count(p) FROM CocarBundle:Printer p')->getSingleScalarResult(); - $limit = 500; + $limit = 20; $iterations = (int)($n_printers / $limit); $iterations = $iterations + 1; $i = 0; while ($i < $iterations) { - // O objetivo é executar a coleta a cada 1000 impressoras + // O objetivo é executar a coleta a cada $limit impressoras $offset = $limit * $i; $this->selectPrinters($limit, $offset); $i = $i + 1; @@ -653,9 +653,12 @@ class PrinterController extends Controller $community = $printer->getCommunitySnmpPrinter(); $host = $printer->getHost(); - $this->get('logger')->info("Coletando impressora $host | ID ".$printer->getId()); + $this->get('logger')->info("Coletando impressora $host | ID ".$printer->getId()); + $arrBundle = $this->get('kernel')->getBundles(); + $rootDir = $arrBundle['CocarBundle']->getPath(); + $script = $rootDir . "/Resources/scripts/timeout3"; - $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; + $com = "$script snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; if($outPut = shell_exec($com)) { diff --git a/Resources/scripts/timeout3 b/Resources/scripts/timeout3 new file mode 100755 index 0000000..5c19d2e --- /dev/null +++ b/Resources/scripts/timeout3 @@ -0,0 +1,91 @@ +#!/bin/bash +# +# The Bash shell script executes a command with a time-out. +# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal +# is blocked, then the subsequent SIGKILL (9) terminates it. +# +# Based on the Bash documentation example. + +# Hello Chet, +# please find attached a "little easier" :-) to comprehend +# time-out example. If you find it suitable, feel free to include +# anywhere: the very same logic as in the original examples/scripts, a +# little more transparent implementation to my taste. +# +# Dmitry V Golovashkin + +scriptName="${0##*/}" + +declare -i DEFAULT_TIMEOUT=9 +declare -i DEFAULT_INTERVAL=1 +declare -i DEFAULT_DELAY=1 + +# Timeout. +declare -i timeout=DEFAULT_TIMEOUT +# Interval between checks if the process is still alive. +declare -i interval=DEFAULT_INTERVAL +# Delay between posting the SIGTERM signal and destroying the process by SIGKILL. +declare -i delay=DEFAULT_DELAY + +function printUsage() { + cat < 0)); do + sleep $interval + kill -0 $$ || exit 0 + ((t -= interval)) + done + + # Be nice, post SIGTERM first. + # The 'exit 0' below will be executed if any preceeding command fails. + kill -s SIGTERM $$ && kill -0 $$ || exit 0 + sleep $delay + kill -s SIGKILL $$ +) 2> /dev/null & + +exec "$@" -- libgit2 0.21.2