Commit 9c8fa388693503b9c9ee09f1189c94a7b59d1fa7
1 parent
accd0632
Exists in
master
and in
9 other branches
Melhorias gerais no mecanismo de processamento das filas de tarefas
Showing
6 changed files
with
132 additions
and
72 deletions
Show diff stats
PENIntegracao.php
... | ... | @@ -11,7 +11,7 @@ class PENIntegracao extends SeiIntegracao { |
11 | 11 | } |
12 | 12 | |
13 | 13 | public function getVersao() { |
14 | - return '1.2.0'; | |
14 | + return '1.2.1'; | |
15 | 15 | } |
16 | 16 | |
17 | 17 | public function getInstituicao() { |
... | ... | @@ -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
... | ... | @@ -19,6 +19,7 @@ class PendenciasTramiteRN extends InfraRN { |
19 | 19 | |
20 | 20 | public static function getInstance() { |
21 | 21 | if (self::$instance == null) { |
22 | + PENIntegracao::validarCompatibilidadeBanco(); | |
22 | 23 | self::$instance = new PendenciasTramiteRN(ConfiguracaoSEI::getInstance(), SessaoSEI::getInstance(), BancoSEI::getInstance(), LogSEI::getInstance()); |
23 | 24 | } |
24 | 25 | |
... | ... | @@ -72,6 +73,8 @@ class PendenciasTramiteRN extends InfraRN { |
72 | 73 | |
73 | 74 | while (true) { |
74 | 75 | try { |
76 | + PENIntegracao::validarCompatibilidadeBanco(); | |
77 | + | |
75 | 78 | $this->gravarLogDebug('Recuperando lista de pendências do PEN', 1); |
76 | 79 | $arrObjPendenciasDTO = $this->obterPendenciasTramite(); |
77 | 80 | foreach ($arrObjPendenciasDTO as $objPendenciaDTO) { |
... | ... | @@ -80,6 +83,12 @@ class PendenciasTramiteRN extends InfraRN { |
80 | 83 | $this->gravarLogDebug($mensagemLog, 3, true); |
81 | 84 | $this->enviarPendenciaFilaProcessamento($objPendenciaDTO); |
82 | 85 | } |
86 | + | |
87 | + } catch(ModuloIncompativelException $e) { | |
88 | + //Registra a falha no log do sistema e reinicia o ciclo de requisição e | |
89 | + //sai loop de eventos para finalizar o script e subir uma nova versão atualizada | |
90 | + LogSEI::getInstance()->gravar(InfraException::inspecionar($e)); | |
91 | + break; | |
83 | 92 | } catch (Exception $e) { |
84 | 93 | //Apenas registra a falha no log do sistema e reinicia o ciclo de requisição |
85 | 94 | LogSEI::getInstance()->gravar(InfraException::inspecionar($e)); |
... | ... | @@ -211,22 +220,22 @@ class PendenciasTramiteRN extends InfraRN { |
211 | 220 | $client = new GearmanClient(); |
212 | 221 | $client->addServer("127.0.0.1", 4730); |
213 | 222 | |
214 | - $strWorkload = strval($objPendencia->getNumIdentificacaoTramite()); | |
223 | + $numIDT = strval($objPendencia->getNumIdentificacaoTramite()); | |
215 | 224 | |
216 | 225 | switch ($objPendencia->getStrStatus()) { |
217 | 226 | |
218 | 227 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_INICIADO: |
219 | - $client->addTaskBackground('enviarComponenteDigital', $strWorkload, null); | |
228 | + $client->addTaskBackground('enviarComponenteDigital', $numIDT, null, $numIDT); | |
220 | 229 | break; |
221 | 230 | |
222 | 231 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_COMPONENTES_ENVIADOS_REMETENTE: |
223 | 232 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_METADADOS_RECEBIDO_DESTINATARIO: |
224 | 233 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_COMPONENTES_RECEBIDOS_DESTINATARIO: |
225 | - $client->addTaskBackground('receberProcedimento', $strWorkload, null); | |
234 | + $client->addTaskBackground('receberProcedimento', $numIDT, null, $numIDT); | |
226 | 235 | break; |
227 | 236 | |
228 | 237 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_RECIBO_ENVIADO_DESTINATARIO: |
229 | - $client->addTaskBackground('receberReciboTramite', $strWorkload, null); | |
238 | + $client->addTaskBackground('receberReciboTramite', $numIDT, null, $numIDT); | |
230 | 239 | break; |
231 | 240 | |
232 | 241 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_RECIBO_RECEBIDO_REMETENTE: |
... | ... | @@ -236,7 +245,7 @@ class PendenciasTramiteRN extends InfraRN { |
236 | 245 | break; |
237 | 246 | |
238 | 247 | case ProcessoEletronicoRN::$STA_SITUACAO_TRAMITE_RECUSADO: |
239 | - $client->addTaskBackground("receberTramitesRecusados", $strWorkload, null);; | |
248 | + $client->addTaskBackground("receberTramitesRecusados", $numIDT, null, $numIDT); | |
240 | 249 | break; |
241 | 250 | |
242 | 251 | 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
... | ... | @@ -42,6 +42,10 @@ class ProcessoEletronicoRN extends InfraRN { |
42 | 42 | // 02 a 18 estão registrados na tabela rel_tarefa_operacao |
43 | 43 | public static $OP_OPERACAO_REGISTRO = "01"; |
44 | 44 | |
45 | + // 10 minutos de timeout para requisições via webservice | |
46 | + const WS_CONNECTION_TIMEOUT = 600; | |
47 | + | |
48 | + | |
45 | 49 | const ALGORITMO_HASH_DOCUMENTO = 'SHA256'; |
46 | 50 | |
47 | 51 | /** |
... | ... | @@ -106,6 +110,9 @@ class ProcessoEletronicoRN extends InfraRN { |
106 | 110 | , 'passphrase' => $this->strLocalCertPassword |
107 | 111 | , 'resolve_wsdl_remote_includes' => true |
108 | 112 | , 'cache_wsdl'=> WSDL_CACHE_NONE |
113 | + , 'connection_timeout' => self::WS_CONNECTION_TIMEOUT | |
114 | + , CURLOPT_TIMEOUT => self::WS_CONNECTION_TIMEOUT | |
115 | + , CURLOPT_CONNECTTIMEOUT => self::WS_CONNECTION_TIMEOUT | |
109 | 116 | , 'trace' => true |
110 | 117 | , 'encoding' => 'UTF-8' |
111 | 118 | , 'attachment_type' => BeSimple\SoapCommon\Helper::ATTACHMENTS_TYPE_MTOM |
... | ... | @@ -367,34 +374,37 @@ class ProcessoEletronicoRN extends InfraRN { |
367 | 374 | public function consultarMotivosUrgencia() |
368 | 375 | { |
369 | 376 | $curl = curl_init($this->strComumXSD); |
370 | - curl_setopt($curl, CURLOPT_URL, $this->strComumXSD); | |
371 | - curl_setopt($curl, CURLOPT_HEADER, 0); | |
372 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
373 | - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | |
374 | - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
375 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
376 | - curl_setopt($curl, CURLOPT_SSLCERT, $this->strLocalCert); | |
377 | - curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $this->strLocalCertPassword); | |
378 | - $output = curl_exec($curl); | |
379 | - curl_close($curl); | |
380 | - | |
381 | - $dom = new DOMDocument; | |
382 | - $dom->loadXML($output); | |
383 | - | |
384 | - $xpath = new DOMXPath($dom); | |
385 | - | |
386 | - $rootNamespace = $dom->lookupNamespaceUri($dom->namespaceURI); | |
387 | - $xpath->registerNamespace('x', $rootNamespace); | |
388 | - $entries = $xpath->query('/x:schema/x:simpleType[@name="motivoDaUrgencia"]/x:restriction/x:enumeration'); | |
389 | - | |
390 | - $resultado = array(); | |
391 | - foreach ($entries as $entry) { | |
392 | - $valor = $entry->getAttribute('value'); | |
393 | - | |
394 | - $documentationNode = $xpath->query('x:annotation/x:documentation', $entry); | |
395 | - $descricao = $documentationNode->item(0)->nodeValue; | |
396 | - | |
397 | - $resultado[$valor] = utf8_decode($descricao); | |
377 | + | |
378 | + try{ | |
379 | + curl_setopt($curl, CURLOPT_URL, $this->strComumXSD); | |
380 | + curl_setopt($curl, CURLOPT_HEADER, 0); | |
381 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
382 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | |
383 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | |
384 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
385 | + curl_setopt($curl, CURLOPT_SSLCERT, $this->strLocalCert); | |
386 | + curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $this->strLocalCertPassword); | |
387 | + $output = curl_exec($curl); | |
388 | + | |
389 | + $dom = new DOMDocument; | |
390 | + $dom->loadXML($output); | |
391 | + | |
392 | + $xpath = new DOMXPath($dom); | |
393 | + | |
394 | + $rootNamespace = $dom->lookupNamespaceUri($dom->namespaceURI); | |
395 | + $xpath->registerNamespace('x', $rootNamespace); | |
396 | + $entries = $xpath->query('/x:schema/x:simpleType[@name="motivoDaUrgencia"]/x:restriction/x:enumeration'); | |
397 | + | |
398 | + $resultado = array(); | |
399 | + foreach ($entries as $entry) { | |
400 | + $valor = $entry->getAttribute('value'); | |
401 | + $documentationNode = $xpath->query('x:annotation/x:documentation', $entry); | |
402 | + $descricao = $documentationNode->item(0)->nodeValue; | |
403 | + $resultado[$valor] = utf8_decode($descricao); | |
404 | + } | |
405 | + | |
406 | + } finally{ | |
407 | + curl_close($curl); | |
398 | 408 | } |
399 | 409 | |
400 | 410 | return $resultado; | ... | ... |