Commit ec7dbadd8b59ecebae06bf0788b623f5bdc23375
Exists in
master
and in
11 other branches
Merge remote-tracking branch 'origin/fix-gearman' into desenv
Showing
6 changed files
with
131 additions
and
71 deletions
Show diff stats
PENIntegracao.php
... | ... | @@ -353,11 +353,38 @@ class PENIntegracao extends SeiIntegracao { |
353 | 353 | return $xml; |
354 | 354 | } |
355 | 355 | |
356 | - public static function validarCompatibilidadeModulo($bolGerarExcecao = true, $strVersaoSEI = SEI_VERSAO) | |
356 | + public static function validarCompatibilidadeModulo($parStrVersaoSEI=null) | |
357 | 357 | { |
358 | + $strVersaoSEI = $parStrVersaoSEI ?: SEI_VERSAO; | |
358 | 359 | $objPENIntegracao = new PENIntegracao(); |
359 | 360 | if(!in_array($strVersaoSEI, self::COMPATIBILIDADE_MODULO_SEI)) { |
360 | 361 | throw new InfraException(sprintf("Módulo %s (versão %s) não é compatível com a versão %s do SEI.", $objPENIntegracao->getNome(), $objPENIntegracao->getVersao(), $strVersaoSEI)); |
361 | 362 | } |
362 | 363 | } |
364 | + | |
365 | + /** | |
366 | + * Método responsável pela validação da compatibilidade do banco de dados do módulo em relação ao versão instalada. | |
367 | + * | |
368 | + * @param boolean $bolGerarExcecao Flag para geração de exceção do tipo InfraException caso base de dados incompatível | |
369 | + * @return boolean Indicardor se base de dados é compatível | |
370 | + */ | |
371 | + public static function validarCompatibilidadeBanco($bolGerarExcecao=true) | |
372 | + { | |
373 | + $objInfraParametro = new InfraParametro(BancoSEI::getInstance()); | |
374 | + $strVersaoBancoModulo = $objInfraParametro->getValor(PenAtualizarSeiRN::PARAMETRO_VERSAO_MODULO, false) ?: $objInfraParametro->getValor(PenAtualizarSeiRN::PARAMETRO_VERSAO_MODULO_ANTIGO, false); | |
375 | + | |
376 | + $objPENIntegracao = new PENIntegracao(); | |
377 | + $strVersaoModulo = $objPENIntegracao->getVersao(); | |
378 | + | |
379 | + $bolBaseCompativel = ($strVersaoModulo === $strVersaoBancoModulo); | |
380 | + | |
381 | + if(!$bolBaseCompativel && $bolGerarExcecao){ | |
382 | + throw new ModuloIncompativelException(sprintf("Base de dados do módulo '%s' (versão %s) encontra-se incompatível. A versão da base de dados atualmente instalada é a %s. \n ". | |
383 | + "Favor entrar em contato com o administrador do sistema.", $objPENIntegracao->getNome(), $strVersaoModulo, $strVersaoBancoModulo)); | |
384 | + } | |
385 | + | |
386 | + return $bolBaseCompativel; | |
387 | + } | |
363 | 388 | } |
389 | + | |
390 | +class ModuloIncompativelException extends InfraException { } | ... | ... |
README.md
... | ... | @@ -80,8 +80,8 @@ Estes dois componentes são utilizados para gerenciar a fila de recebimento de n |
80 | 80 | user=apache |
81 | 81 | autostart=true |
82 | 82 | autorestart=true |
83 | - startsecs=15 | |
84 | - startretries=3 | |
83 | + startsecs=5 | |
84 | + startretries=1000 | |
85 | 85 | log_stdout=true |
86 | 86 | log_stderr=true |
87 | 87 | logfile_backups=50 |
... | ... | @@ -99,8 +99,8 @@ Estes dois componentes são utilizados para gerenciar a fila de recebimento de n |
99 | 99 | user=apache |
100 | 100 | autostart=true |
101 | 101 | autorestart=true |
102 | - startsecs=15 | |
103 | - startretries=3 | |
102 | + startsecs=5 | |
103 | + startretries=1000 | |
104 | 104 | log_stdout=true |
105 | 105 | log_stderr=true |
106 | 106 | logfile_maxbytes=10MB | ... | ... |
rn/EnviarReciboTramiteRN.php
... | ... | @@ -84,45 +84,57 @@ class EnviarReciboTramiteRN extends InfraRN |
84 | 84 | |
85 | 85 | public function enviarReciboTramiteProcesso($parNumIdTramite, $parArrayHash = null, $parDthRecebimento = null) |
86 | 86 | { |
87 | - date_default_timezone_set('America/Sao_Paulo'); | |
87 | + try{ | |
88 | + date_default_timezone_set('America/Sao_Paulo'); | |
88 | 89 | |
89 | - if(!isset($parNumIdTramite) || $parNumIdTramite == 0) { | |
90 | - throw new InfraException('Parâmetro $parNumIdTramite não informado.'); | |
91 | - } | |
90 | + if(!isset($parNumIdTramite) || $parNumIdTramite == 0) { | |
91 | + throw new InfraException('Parâmetro $parNumIdTramite não informado.'); | |
92 | + } | |
92 | 93 | |
93 | - //Verifica se todos os componentes digitais já foram devidamente recebido | |
94 | - $arrObjTramite = $this->objProcessoEletronicoRN->consultarTramites($parNumIdTramite); | |
95 | - if(!isset($arrObjTramite) || count($arrObjTramite) != 1) { | |
96 | - throw new InfraException("Trâmite não pode ser localizado pelo identificador $parNumIdTramite."); | |
97 | - } | |
94 | + //Verifica se todos os componentes digitais já foram devidamente recebido | |
95 | + $arrObjTramite = $this->objProcessoEletronicoRN->consultarTramites($parNumIdTramite); | |
96 | + if(!isset($arrObjTramite) || count($arrObjTramite) != 1) { | |
97 | + throw new InfraException("Trâmite não pode ser localizado pelo identificador $parNumIdTramite."); | |
98 | + } | |
98 | 99 | |
99 | - $objTramite = $arrObjTramite[0]; | |
100 | - $strNumeroRegistro = $objTramite->NRE; | |
100 | + $objTramite = $arrObjTramite[0]; | |
101 | + $strNumeroRegistro = $objTramite->NRE; | |
101 | 102 | |
102 | - if($objTramite->situacaoAtual != ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_COMPONENTES_RECEBIDOS_DESTINATARIO) { | |
103 | - throw new InfraException('Situação do Trâmite diferente da permitida para o envio do recibo de conclusão de trâmite.'); | |
104 | - } | |
103 | + if($objTramite->situacaoAtual != ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_COMPONENTES_RECEBIDOS_DESTINATARIO) { | |
104 | + throw new InfraException('Situação do Trâmite diferente da permitida para o envio do recibo de conclusão de trâmite.'); | |
105 | + } | |
105 | 106 | |
106 | - $dthRecebimentoComponentesDigitais = $this->obterDataRecebimentoComponentesDigitais($objTramite); | |
107 | - $dthRecebimentoComponentesDigitais = $dthRecebimentoComponentesDigitais ?: date(); | |
108 | - $dthRecebimento = gmdate("Y-m-d\TH:i:s.000\Z", InfraData::getTimestamp($dthRecebimentoComponentesDigitais)); | |
107 | + $dthRecebimentoComponentesDigitais = $this->obterDataRecebimentoComponentesDigitais($objTramite); | |
108 | + $dthRecebimentoComponentesDigitais = $dthRecebimentoComponentesDigitais ?: date(); | |
109 | + $dthRecebimento = gmdate("Y-m-d\TH:i:s.000\Z", InfraData::getTimestamp($dthRecebimentoComponentesDigitais)); | |
109 | 110 | |
110 | - $strReciboTramite = "<recibo>"; | |
111 | - $strReciboTramite .= "<IDT>$parNumIdTramite</IDT>"; | |
112 | - $strReciboTramite .= "<NRE>$strNumeroRegistro</NRE>"; | |
113 | - $strReciboTramite .= "<dataDeRecebimento>$dthRecebimento</dataDeRecebimento>"; | |
114 | - sort($parArrayHash); | |
111 | + $strReciboTramite = "<recibo>"; | |
112 | + $strReciboTramite .= "<IDT>$parNumIdTramite</IDT>"; | |
113 | + $strReciboTramite .= "<NRE>$strNumeroRegistro</NRE>"; | |
114 | + $strReciboTramite .= "<dataDeRecebimento>$dthRecebimento</dataDeRecebimento>"; | |
115 | + sort($parArrayHash); | |
115 | 116 | |
116 | - foreach ($parArrayHash as $strHashConteudo) { | |
117 | - if(!empty($strHashConteudo)){ | |
118 | - $strReciboTramite .= "<hashDoComponenteDigital>$strHashConteudo</hashDoComponenteDigital>"; | |
119 | - } | |
120 | - } | |
121 | - $strReciboTramite .= "</recibo>"; | |
117 | + foreach ($parArrayHash as $strHashConteudo) { | |
118 | + if(!empty($strHashConteudo)){ | |
119 | + $strReciboTramite .= "<hashDoComponenteDigital>$strHashConteudo</hashDoComponenteDigital>"; | |
120 | + } | |
121 | + } | |
122 | + $strReciboTramite .= "</recibo>"; | |
123 | + | |
124 | + //Envia o Recibo de salva no banco | |
125 | + $hashAssinatura = $this->objProcessoEletronicoRN->enviarReciboDeTramite($parNumIdTramite, $dthRecebimento, $strReciboTramite); | |
126 | + $this->cadastrarReciboTramiteRecebimento($strNumeroRegistro, $parNumIdTramite, $hashAssinatura, $parArrayHash); | |
122 | 127 | |
123 | - //Envia o Recibo de salva no banco | |
124 | - $hashAssinatura = $this->objProcessoEletronicoRN->enviarReciboDeTramite($parNumIdTramite, $dthRecebimento, $strReciboTramite); | |
125 | - $this->cadastrarReciboTramiteRecebimento($strNumeroRegistro, $parNumIdTramite, $hashAssinatura, $parArrayHash); | |
128 | + } catch (Exception $e) { | |
129 | + $detalhes = null; | |
130 | + $mensagem = InfraException::inspecionar($e); | |
131 | + | |
132 | + if(isset($strReciboTramite)){ | |
133 | + $detalhes = "Falha na validação do recibo de conclusão do trâmite do processo. Recibo: \n" . $strReciboTramite; | |
134 | + } | |
135 | + | |
136 | + throw new InfraException($mensagem, $e, $detalhes); | |
137 | + } | |
126 | 138 | } |
127 | 139 | |
128 | 140 | private function obterDataRecebimentoComponentesDigitais($parObjTramite){ |
... | ... | @@ -147,7 +159,7 @@ class EnviarReciboTramiteRN extends InfraRN |
147 | 159 | /** |
148 | 160 | * Consulta o componente digital no barramento. Utilizado para casos de retrasmissão, |
149 | 161 | * onde esta unidade esta recebendo um componente digital que pertence à ela |
150 | - * própria, então o id_tramite de envio, que foi gravado, é diferente do de recebimento | |
162 | + * própria, então o id_tramite de envio, que foi gravado, é diferente do recebimento | |
151 | 163 | * |
152 | 164 | * @param int $numIdTramite |
153 | 165 | * @return array[ComponenteDigitalDTO] |
... | ... | @@ -188,7 +200,6 @@ class EnviarReciboTramiteRN extends InfraRN |
188 | 200 | $objDocumentoDTO = $objDocumentoBD->consultar($objDocumentoDTO); |
189 | 201 | |
190 | 202 | if(empty($objDocumentoDTO)) { |
191 | - | |
192 | 203 | $dblIdDocumento = $objDocumentoDTO->getDblIdDocumento(); |
193 | 204 | } |
194 | 205 | } | ... | ... |
rn/PendenciasTramiteRN.php
... | ... | @@ -20,6 +20,7 @@ class PendenciasTramiteRN extends InfraRN { |
20 | 20 | |
21 | 21 | public static function getInstance() { |
22 | 22 | if (self::$instance == null) { |
23 | + PENIntegracao::validarCompatibilidadeBanco(); | |
23 | 24 | self::$instance = new PendenciasTramiteRN(ConfiguracaoSEI::getInstance(), SessaoSEI::getInstance(), BancoSEI::getInstance(), LogSEI::getInstance()); |
24 | 25 | } |
25 | 26 | |
... | ... | @@ -73,6 +74,8 @@ class PendenciasTramiteRN extends InfraRN { |
73 | 74 | |
74 | 75 | while (true) { |
75 | 76 | try { |
77 | + PENIntegracao::validarCompatibilidadeBanco(); | |
78 | + | |
76 | 79 | $this->gravarLogDebug('Recuperando lista de pendências do PEN', 1); |
77 | 80 | $arrObjPendenciasDTO = $this->obterPendenciasTramite(); |
78 | 81 | foreach ($arrObjPendenciasDTO as $objPendenciaDTO) { |
... | ... | @@ -81,6 +84,12 @@ class PendenciasTramiteRN extends InfraRN { |
81 | 84 | $this->gravarLogDebug($mensagemLog, 3, true); |
82 | 85 | $this->enviarPendenciaFilaProcessamento($objPendenciaDTO); |
83 | 86 | } |
87 | + | |
88 | + } catch(ModuloIncompativelException $e) { | |
89 | + //Registra a falha no log do sistema e reinicia o ciclo de requisição e | |
90 | + //sai loop de eventos para finalizar o script e subir uma nova versão atualizada | |
91 | + LogSEI::getInstance()->gravar(InfraException::inspecionar($e)); | |
92 | + break; | |
84 | 93 | } catch (Exception $e) { |
85 | 94 | //Apenas registra a falha no log do sistema e reinicia o ciclo de requisição |
86 | 95 | LogSEI::getInstance()->gravar(InfraException::inspecionar($e)); |
... | ... | @@ -212,22 +221,22 @@ class PendenciasTramiteRN extends InfraRN { |
212 | 221 | $client = new GearmanClient(); |
213 | 222 | $client->addServer("127.0.0.1", 4730); |
214 | 223 | |
215 | - $strWorkload = strval($objPendencia->getNumIdentificacaoTramite()); | |
224 | + $numIDT = strval($objPendencia->getNumIdentificacaoTramite()); | |
216 | 225 | |
217 | 226 | switch ($objPendencia->getStrStatus()) { |
218 | 227 | |
219 | 228 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_INICIADO: |
220 | - $client->addTaskBackground('enviarComponenteDigital', $strWorkload, null); | |
229 | + $client->addTaskBackground('enviarComponenteDigital', $numIDT, null, $numIDT); | |
221 | 230 | break; |
222 | 231 | |
223 | 232 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_COMPONENTES_ENVIADOS_REMETENTE: |
224 | 233 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_METADADOS_RECEBIDO_DESTINATARIO: |
225 | 234 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_COMPONENTES_RECEBIDOS_DESTINATARIO: |
226 | - $client->addTaskBackground('receberProcedimento', $strWorkload, null); | |
235 | + $client->addTaskBackground('receberProcedimento', $numIDT, null, $numIDT); | |
227 | 236 | break; |
228 | 237 | |
229 | 238 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_RECIBO_ENVIADO_DESTINATARIO: |
230 | - $client->addTaskBackground('receberReciboTramite', $strWorkload, null); | |
239 | + $client->addTaskBackground('receberReciboTramite', $numIDT, null, $numIDT); | |
231 | 240 | break; |
232 | 241 | |
233 | 242 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_RECIBO_RECEBIDO_REMETENTE: |
... | ... | @@ -237,7 +246,7 @@ class PendenciasTramiteRN extends InfraRN { |
237 | 246 | break; |
238 | 247 | |
239 | 248 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_RECUSADO: |
240 | - $client->addTaskBackground("receberTramitesRecusados", $strWorkload, null);; | |
249 | + $client->addTaskBackground("receberTramitesRecusados", $numIDT, null, $numIDT); | |
241 | 250 | break; |
242 | 251 | |
243 | 252 | default: | ... | ... |
rn/ProcessarPendenciasRN.php
... | ... | @@ -49,6 +49,9 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa |
49 | 49 | |
50 | 50 | while($this->objGearmanWorker->work()) |
51 | 51 | { |
52 | + PENIntegracao::validarCompatibilidadeBanco(); | |
53 | + | |
54 | + $this->gravarLogDebug("Gearman worker return code: " . $this->objGearmanWorker->returnCode(), 0, true); | |
52 | 55 | if ($this->objGearmanWorker->returnCode() != GEARMAN_SUCCESS) { |
53 | 56 | $strErro = 'Erro no processamento de pendências do PEN. ErrorCode: ' . $this->objGearmanWorker->returnCode(); |
54 | 57 | LogSEI::getInstance()->gravar($strErro); | ... | ... |
rn/ProcessoEletronicoRN.php
... | ... | @@ -43,6 +43,10 @@ class ProcessoEletronicoRN extends InfraRN { |
43 | 43 | // 02 a 18 estão registrados na tabela rel_tarefa_operacao |
44 | 44 | public static $OP_OPERACAO_REGISTRO = "01"; |
45 | 45 | |
46 | + // 10 minutos de timeout para requisições via webservice | |
47 | + const WS_CONNECTION_TIMEOUT = 600; | |
48 | + | |
49 | + | |
46 | 50 | const ALGORITMO_HASH_DOCUMENTO = 'SHA256'; |
47 | 51 | |
48 | 52 | /** |
... | ... | @@ -107,6 +111,9 @@ class ProcessoEletronicoRN extends InfraRN { |
107 | 111 | , 'passphrase' => $this->strLocalCertPassword |
108 | 112 | , 'resolve_wsdl_remote_includes' => true |
109 | 113 | , 'cache_wsdl'=> WSDL_CACHE_NONE |
114 | + , 'connection_timeout' => self::WS_CONNECTION_TIMEOUT | |
115 | + , CURLOPT_TIMEOUT => self::WS_CONNECTION_TIMEOUT | |
116 | + , CURLOPT_CONNECTTIMEOUT => self::WS_CONNECTION_TIMEOUT | |
110 | 117 | , 'trace' => true |
111 | 118 | , 'encoding' => 'UTF-8' |
112 | 119 | , 'attachment_type' => BeSimple\SoapCommon\Helper::ATTACHMENTS_TYPE_MTOM |
... | ... | @@ -368,34 +375,37 @@ class ProcessoEletronicoRN extends InfraRN { |
368 | 375 | public function consultarMotivosUrgencia() |
369 | 376 | { |
370 | 377 | $curl = curl_init($this->strComumXSD); |
371 | - curl_setopt($curl, CURLOPT_URL, $this->strComumXSD); | |
372 | - curl_setopt($curl, CURLOPT_HEADER, 0); | |
373 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
374 | - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | |
375 | - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
376 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
377 | - curl_setopt($curl, CURLOPT_SSLCERT, $this->strLocalCert); | |
378 | - curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $this->strLocalCertPassword); | |
379 | - $output = curl_exec($curl); | |
380 | - curl_close($curl); | |
381 | - | |
382 | - $dom = new DOMDocument; | |
383 | - $dom->loadXML($output); | |
384 | - | |
385 | - $xpath = new DOMXPath($dom); | |
386 | - | |
387 | - $rootNamespace = $dom->lookupNamespaceUri($dom->namespaceURI); | |
388 | - $xpath->registerNamespace('x', $rootNamespace); | |
389 | - $entries = $xpath->query('/x:schema/x:simpleType[@name="motivoDaUrgencia"]/x:restriction/x:enumeration'); | |
390 | - | |
391 | - $resultado = array(); | |
392 | - foreach ($entries as $entry) { | |
393 | - $valor = $entry->getAttribute('value'); | |
394 | - | |
395 | - $documentationNode = $xpath->query('x:annotation/x:documentation', $entry); | |
396 | - $descricao = $documentationNode->item(0)->nodeValue; | |
397 | - | |
398 | - $resultado[$valor] = utf8_decode($descricao); | |
378 | + | |
379 | + try{ | |
380 | + curl_setopt($curl, CURLOPT_URL, $this->strComumXSD); | |
381 | + curl_setopt($curl, CURLOPT_HEADER, 0); | |
382 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
383 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | |
384 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
385 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
386 | + curl_setopt($curl, CURLOPT_SSLCERT, $this->strLocalCert); | |
387 | + curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $this->strLocalCertPassword); | |
388 | + $output = curl_exec($curl); | |
389 | + | |
390 | + $dom = new DOMDocument; | |
391 | + $dom->loadXML($output); | |
392 | + | |
393 | + $xpath = new DOMXPath($dom); | |
394 | + | |
395 | + $rootNamespace = $dom->lookupNamespaceUri($dom->namespaceURI); | |
396 | + $xpath->registerNamespace('x', $rootNamespace); | |
397 | + $entries = $xpath->query('/x:schema/x:simpleType[@name="motivoDaUrgencia"]/x:restriction/x:enumeration'); | |
398 | + | |
399 | + $resultado = array(); | |
400 | + foreach ($entries as $entry) { | |
401 | + $valor = $entry->getAttribute('value'); | |
402 | + $documentationNode = $xpath->query('x:annotation/x:documentation', $entry); | |
403 | + $descricao = $documentationNode->item(0)->nodeValue; | |
404 | + $resultado[$valor] = utf8_decode($descricao); | |
405 | + } | |
406 | + | |
407 | + } finally{ | |
408 | + curl_close($curl); | |
399 | 409 | } |
400 | 410 | |
401 | 411 | return $resultado; | ... | ... |