libretificacaotjcore 0.1.25__py3-none-any.whl → 0.1.49__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of libretificacaotjcore might be problematic. Click here for more details.
- libretificacaotjcore/database/arquivo_repository.py +1 -0
- libretificacaotjcore/database/config_db.py +15 -0
- libretificacaotjcore/database/rubrica_repository.py +32 -0
- libretificacaotjcore/database/tempo_processo_repository.py +99 -0
- libretificacaotjcore/dtos/processo_dto.py +78 -0
- libretificacaotjcore/dtos/solicitacao_dto.py +12 -0
- libretificacaotjcore/enums/e_eventos.py +2 -1
- libretificacaotjcore/enums/e_fase_retificacao.py +32 -0
- libretificacaotjcore/services/rabbitmq_consumer.py +39 -35
- libretificacaotjcore/services/rabbitmq_publisher.py +56 -0
- libretificacaotjcore/services/request_servico_api.py +20 -0
- {libretificacaotjcore-0.1.25.dist-info → libretificacaotjcore-0.1.49.dist-info}/METADATA +3 -1
- libretificacaotjcore-0.1.49.dist-info/RECORD +26 -0
- libretificacaotjcore-0.1.25.dist-info/RECORD +0 -20
- {libretificacaotjcore-0.1.25.dist-info → libretificacaotjcore-0.1.49.dist-info}/WHEEL +0 -0
- {libretificacaotjcore-0.1.25.dist-info → libretificacaotjcore-0.1.49.dist-info}/top_level.txt +0 -0
|
@@ -35,6 +35,21 @@ class ConfigDb:
|
|
|
35
35
|
await self.__db.protocolos.create_index([("id", 1)], unique=True)
|
|
36
36
|
await self.__db.protocolos.create_index([("solicitacaoId", 1), ("evento", 1)], unique=True)
|
|
37
37
|
self.db_initialized = True
|
|
38
|
+
|
|
39
|
+
if "rubricas" not in (await self.__db.list_collection_names()):
|
|
40
|
+
await self.__db.create_collection("rubricas")
|
|
41
|
+
|
|
42
|
+
await self.__db.rubricas.create_index([("cnpj", 1)])
|
|
43
|
+
await self.__db.rubricas.create_index([("solicitacaoId", 1)], unique=True)
|
|
44
|
+
await self.__db.rubricas.create_index([("id", 1)], unique=True)
|
|
45
|
+
self.db_initialized = True
|
|
46
|
+
|
|
47
|
+
if "tempo_processos" not in (await self.__db.list_collection_names()):
|
|
48
|
+
await self.__db.create_collection("tempo_processos")
|
|
49
|
+
|
|
50
|
+
await self.__db.rubricas.create_index([("SolicitacaoId", 1)])
|
|
51
|
+
await self.__db.rubricas.create_index([("id", 1)], unique=True)
|
|
52
|
+
self.db_initialized = True
|
|
38
53
|
|
|
39
54
|
async def get_db(self):
|
|
40
55
|
await self.criar_schema()
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from pymongo.errors import BulkWriteError
|
|
2
|
+
|
|
3
|
+
class RubricaRepository:
|
|
4
|
+
def __init__(self, db):
|
|
5
|
+
self.__db = db
|
|
6
|
+
|
|
7
|
+
async def inserir_rubrica(self, rubrica: dict) -> bool:
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
rubricas_no_db = await self.__db.rubricas.find_one(
|
|
11
|
+
{"solicitacaoId": rubrica["solicitacaoId"]}
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
if rubricas_no_db is None:
|
|
15
|
+
await self.__db.rubricas.insert_one(rubrica)
|
|
16
|
+
return True
|
|
17
|
+
|
|
18
|
+
await self.__db.rubricas.delete_one(
|
|
19
|
+
{"solicitacaoId": rubrica["solicitacaoId"]}
|
|
20
|
+
)
|
|
21
|
+
await self.__db.rubricas.insert_one(rubrica)
|
|
22
|
+
return True
|
|
23
|
+
except Exception as e:
|
|
24
|
+
print(f"❌ Erro ao inserir o rubrica: {e}")
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
async def buscar_por_solicitacao_id(self, solicitacaoId: int) -> dict:
|
|
28
|
+
try:
|
|
29
|
+
return await self.__db.rubricas.find_one({"solicitacaoId": solicitacaoId})
|
|
30
|
+
except Exception as e:
|
|
31
|
+
print(f"❌ Erro ao buscar rubricas por solicitacaoId: {e}")
|
|
32
|
+
return {}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pymongo.errors import BulkWriteError
|
|
3
|
+
|
|
4
|
+
from libretificacaotjcore.dtos.processo_dto import ProcessoDto
|
|
5
|
+
from libretificacaotjcore.enums.e_fase_retificacao import EFaseRetificacao
|
|
6
|
+
|
|
7
|
+
class TempoProcessoRepository:
|
|
8
|
+
def __init__(self, db):
|
|
9
|
+
self.__db = db
|
|
10
|
+
|
|
11
|
+
async def inserir_processo(self, *, processo: ProcessoDto) -> bool:
|
|
12
|
+
try:
|
|
13
|
+
processo_dict = processo.model_dump()
|
|
14
|
+
processo_dict["DataInicio"] = processo.DataInicio.strftime("%Y-%m-%d")
|
|
15
|
+
processo_dict["DataFim"] = processo.DataFim.strftime("%Y-%m-%d")
|
|
16
|
+
processo_dict["FaseDescricao"] = EFaseRetificacao(processo.Fase).name
|
|
17
|
+
|
|
18
|
+
processo_no_db = await self.__db.tempo_processos.find_one(
|
|
19
|
+
{
|
|
20
|
+
"SolicitacaoId": processo.SolicitacaoId,
|
|
21
|
+
"Fase": processo.Fase,
|
|
22
|
+
"DataInicio": processo_dict["DataInicio"],
|
|
23
|
+
"DataFim": processo_dict["DataFim"],
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if processo_no_db is None:
|
|
30
|
+
processo_dict["InicioProcesso"] = datetime.now()
|
|
31
|
+
await self.__db.tempo_processos.insert_one(processo_dict)
|
|
32
|
+
return True
|
|
33
|
+
|
|
34
|
+
await self.__db.tempo_processos.delete_one(
|
|
35
|
+
{
|
|
36
|
+
"SolicitacaoId": processo.SolicitacaoId,
|
|
37
|
+
"Fase": processo.Fase,
|
|
38
|
+
"DataInicio": processo_dict["DataInicio"],
|
|
39
|
+
"DataFim": processo_dict["DataFim"],
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
processo_dict["InicioProcesso"] = datetime.now()
|
|
44
|
+
await self.__db.tempo_processos.insert_one(processo_dict)
|
|
45
|
+
return True
|
|
46
|
+
|
|
47
|
+
except Exception as e:
|
|
48
|
+
print(f"❌ Erro ao inserir o processo: {e}")
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
async def atualizar_processo(self, *, processo: ProcessoDto) -> bool:
|
|
52
|
+
try:
|
|
53
|
+
processo_dict = processo.model_dump()
|
|
54
|
+
processo_dict["DataInicio"] = processo.DataInicio.strftime("%Y-%m-%d")
|
|
55
|
+
processo_dict["DataFim"] = processo.DataFim.strftime("%Y-%m-%d")
|
|
56
|
+
|
|
57
|
+
processo_no_db = await self.__db.tempo_processos.find_one(
|
|
58
|
+
{
|
|
59
|
+
"SolicitacaoId": processo.SolicitacaoId,
|
|
60
|
+
"Fase": processo.Fase,
|
|
61
|
+
"DataInicio": processo_dict["DataInicio"],
|
|
62
|
+
"DataFim": processo_dict["DataFim"],
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if processo_no_db is None:
|
|
67
|
+
return False
|
|
68
|
+
|
|
69
|
+
processo_no_db['FimProcesso'] = datetime.now()
|
|
70
|
+
tempo_de_processo = self._tempo_de_processo(processo_no_db['InicioProcesso'], processo_no_db['FimProcesso'])
|
|
71
|
+
processo_no_db['TempoDeProcesso'] = tempo_de_processo
|
|
72
|
+
|
|
73
|
+
await self.__db.tempo_processos.replace_one(
|
|
74
|
+
{
|
|
75
|
+
"SolicitacaoId": processo.SolicitacaoId,
|
|
76
|
+
"Fase": processo.Fase,
|
|
77
|
+
"DataInicio": processo_dict["DataInicio"],
|
|
78
|
+
"DataFim": processo_dict["DataFim"],
|
|
79
|
+
},
|
|
80
|
+
processo_no_db
|
|
81
|
+
)
|
|
82
|
+
return True
|
|
83
|
+
except Exception as e:
|
|
84
|
+
print(f"❌ Erro ao atualizar o processo: {e}")
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
def _tempo_de_processo(self, tempo_inicio: datetime, tempo_fim: datetime) -> str | None:
|
|
88
|
+
if tempo_inicio and tempo_fim:
|
|
89
|
+
delta = tempo_fim - tempo_inicio # <-- inverter a ordem
|
|
90
|
+
total_segundos = int(delta.total_seconds())
|
|
91
|
+
|
|
92
|
+
horas = total_segundos // 3600
|
|
93
|
+
minutos = (total_segundos % 3600) // 60
|
|
94
|
+
segundos = total_segundos % 60
|
|
95
|
+
|
|
96
|
+
tempo_formatado = f"{horas:02d}:{minutos:02d}:{segundos:02d}"
|
|
97
|
+
return tempo_formatado
|
|
98
|
+
|
|
99
|
+
return None
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from datetime import date, datetime, timedelta
|
|
2
|
+
from pydantic import BaseModel, Field, field_validator
|
|
3
|
+
from libretificacaotjcore.enums.e_fase_retificacao import EFaseRetificacao
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ProcessoDto(BaseModel):
|
|
7
|
+
SolicitacaoId: int = Field(..., description="ID da solicitação")
|
|
8
|
+
DataInicio: date = Field(..., description="Data de início no formato YYYY-MM-DD")
|
|
9
|
+
DataFim: date = Field(..., description="Data de fim no formato YYYY-MM-DD")
|
|
10
|
+
Fase: int | None = Field(None, description="Fase de retificação")
|
|
11
|
+
InicioProcesso: datetime | None = Field(None, description="Data e hora de início do processo")
|
|
12
|
+
FimProcesso: datetime | None = Field(None, description="Data e hora de fim do processo")
|
|
13
|
+
TempoDeProcesso: str | None = Field(None, description="Tempo de processamento")
|
|
14
|
+
Observacoes: str | None = Field(None, description="Observações adicionais")
|
|
15
|
+
|
|
16
|
+
# --- Validadores ---
|
|
17
|
+
|
|
18
|
+
@field_validator("SolicitacaoId")
|
|
19
|
+
@classmethod
|
|
20
|
+
def validar_solicitacao_id(cls, v: int) -> int:
|
|
21
|
+
if v <= 0:
|
|
22
|
+
raise ValueError("O solicitacaoId deve ser um inteiro positivo.")
|
|
23
|
+
return v
|
|
24
|
+
|
|
25
|
+
@field_validator("DataInicio", mode="before")
|
|
26
|
+
@classmethod
|
|
27
|
+
def formatar_data_inicio(cls, value) -> date:
|
|
28
|
+
"""
|
|
29
|
+
Aceita date, datetime ou string.
|
|
30
|
+
"""
|
|
31
|
+
if isinstance(value, date):
|
|
32
|
+
return value
|
|
33
|
+
if isinstance(value, datetime):
|
|
34
|
+
return value.date()
|
|
35
|
+
if isinstance(value, str):
|
|
36
|
+
try:
|
|
37
|
+
return datetime.strptime(value, "%Y-%m-%d").date()
|
|
38
|
+
except ValueError as ve:
|
|
39
|
+
raise ValueError("A DataInicio deve estar no formato YYYY-MM-DD.") from ve
|
|
40
|
+
raise TypeError("Tipo inválido para DataInicio.")
|
|
41
|
+
|
|
42
|
+
@field_validator("DataFim", mode="before")
|
|
43
|
+
@classmethod
|
|
44
|
+
def ajustar_data_fim(cls, value) -> date:
|
|
45
|
+
"""
|
|
46
|
+
Aceita date, datetime ou string.
|
|
47
|
+
Retorna o último dia do mês da data fornecida.
|
|
48
|
+
"""
|
|
49
|
+
if isinstance(value, datetime):
|
|
50
|
+
value = value.date()
|
|
51
|
+
if isinstance(value, date):
|
|
52
|
+
ano, mes = value.year, value.month
|
|
53
|
+
elif isinstance(value, str):
|
|
54
|
+
try:
|
|
55
|
+
ano, mes = map(int, value.split("-")[:2])
|
|
56
|
+
except Exception:
|
|
57
|
+
raise ValueError("A DataFim deve estar no formato YYYY-MM-DD.")
|
|
58
|
+
else:
|
|
59
|
+
raise TypeError("Tipo inválido para DataFim.")
|
|
60
|
+
|
|
61
|
+
if mes < 1 or mes > 12:
|
|
62
|
+
raise ValueError("A DataFim deve conter um mês válido (1–12).")
|
|
63
|
+
|
|
64
|
+
# calcula o último dia do mês
|
|
65
|
+
if mes == 12:
|
|
66
|
+
proximo_mes = datetime(ano + 1, 1, 1)
|
|
67
|
+
else:
|
|
68
|
+
proximo_mes = datetime(ano, mes + 1, 1)
|
|
69
|
+
return (proximo_mes - timedelta(days=1)).date()
|
|
70
|
+
|
|
71
|
+
@field_validator("Fase")
|
|
72
|
+
@classmethod
|
|
73
|
+
def validar_fase(cls, v):
|
|
74
|
+
if v is None:
|
|
75
|
+
return v
|
|
76
|
+
if v not in EFaseRetificacao:
|
|
77
|
+
raise ValueError(f"Fase '{v}' não é válida.")
|
|
78
|
+
return v
|
|
@@ -2,6 +2,7 @@ import re
|
|
|
2
2
|
from datetime import date, datetime, timedelta
|
|
3
3
|
|
|
4
4
|
from pydantic import BaseModel, Field, field_validator
|
|
5
|
+
from libretificacaotjcore.enums.e_fase_retificacao import EFaseRetificacao
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class SolicitacaoDTO(BaseModel):
|
|
@@ -10,6 +11,7 @@ class SolicitacaoDTO(BaseModel):
|
|
|
10
11
|
DataInicio: date = Field(..., description="Data de início no formato YYYY-MM-DD")
|
|
11
12
|
DataFim: date = Field(..., description="Data de fim no formato YYYY-MM-DD")
|
|
12
13
|
CertificadoId: int = Field(..., description="ID do certificado")
|
|
14
|
+
Fase: int | None = Field(None, description="fase de retificação")
|
|
13
15
|
|
|
14
16
|
@field_validator("SolicitacaoId")
|
|
15
17
|
@classmethod
|
|
@@ -54,3 +56,13 @@ class SolicitacaoDTO(BaseModel):
|
|
|
54
56
|
else:
|
|
55
57
|
proximo_mes = datetime(ano, mes + 1, 1)
|
|
56
58
|
return (proximo_mes - timedelta(days=1)).date()
|
|
59
|
+
|
|
60
|
+
@field_validator("Fase")
|
|
61
|
+
@classmethod
|
|
62
|
+
def validar_fase(cls, v: str) -> str | None:
|
|
63
|
+
if v is None:
|
|
64
|
+
return v
|
|
65
|
+
|
|
66
|
+
if v not in EFaseRetificacao:
|
|
67
|
+
raise ValueError(f"Fase '{v}' não é válido.")
|
|
68
|
+
return v
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EFaseRetificacao(Enum):
|
|
5
|
+
NaoIniciado = 0
|
|
6
|
+
SolicitacaoXml = 1
|
|
7
|
+
AguardandoXml = 2
|
|
8
|
+
DownloadXml = 3
|
|
9
|
+
ExtraindoDadosDoXml = 4
|
|
10
|
+
AguardandoRubrica = 5
|
|
11
|
+
EstruturandoXmlAberturaCompetencia = 6
|
|
12
|
+
EstruturandoXmlInclusaoRubricas = 7
|
|
13
|
+
EstruturandoXmlExclusaoPagamentos = 8
|
|
14
|
+
EstruturandoXmlRetificacaoRemuneracao = 9
|
|
15
|
+
EstruturandoXmlInclusaoPagamentos = 10
|
|
16
|
+
EstruturandoXmlDesligamento = 11
|
|
17
|
+
EstruturandoXmlFechamentoCompetencia = 12
|
|
18
|
+
AberturaDeCompetencia = 13
|
|
19
|
+
ConsultandoESocialAberturaCompetencia = 14
|
|
20
|
+
InclusaoDasRubricas = 15
|
|
21
|
+
ConsultandoESocialInclusaoRubricas = 16
|
|
22
|
+
ExclusaoDePagamentos = 17
|
|
23
|
+
ConsultandoESocialExclusaoPagamentos = 18
|
|
24
|
+
RetificacaoDaRemuneracao = 19
|
|
25
|
+
ConsultandoESocialRetificacaoRemuneracao = 20
|
|
26
|
+
InclusaoDosPagamentos = 21
|
|
27
|
+
ConsultandoESocialInclusaoPagamentos = 22
|
|
28
|
+
Desligamento = 23
|
|
29
|
+
ConsultandoESocialDesligamento = 24
|
|
30
|
+
FechamentoDeCompetencia = 25
|
|
31
|
+
ConsultandoESocialFechamentoCompetencia = 26
|
|
32
|
+
Finalizado = 27
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import asyncio
|
|
2
|
+
import aio_pika
|
|
2
3
|
import json
|
|
3
4
|
|
|
4
|
-
|
|
5
5
|
class RabbitMQConsumer:
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
*,
|
|
9
|
+
host: str,
|
|
10
|
+
queue: str,
|
|
11
|
+
username: str,
|
|
12
|
+
password: str,
|
|
13
|
+
vhost: str = "/",
|
|
13
14
|
):
|
|
14
15
|
self.host = host
|
|
15
16
|
self.queue = queue
|
|
@@ -19,37 +20,40 @@ class RabbitMQConsumer:
|
|
|
19
20
|
self.connection = None
|
|
20
21
|
self.channel = None
|
|
21
22
|
|
|
22
|
-
def connect(self):
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
heartbeat=
|
|
29
|
-
blocked_connection_timeout=300,
|
|
23
|
+
async def connect(self):
|
|
24
|
+
self.connection = await aio_pika.connect_robust(
|
|
25
|
+
host=self.host,
|
|
26
|
+
login=self.username,
|
|
27
|
+
password=self.password,
|
|
28
|
+
virtualhost=self.vhost,
|
|
29
|
+
heartbeat=600,
|
|
30
30
|
)
|
|
31
|
-
|
|
32
|
-
self.
|
|
33
|
-
self.channel =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def start_consuming(self, callback):
|
|
37
|
-
def on_message(ch, method, properties, body):
|
|
38
|
-
mensagem = json.loads(body)
|
|
39
|
-
callback(mensagem)
|
|
40
|
-
ch.basic_ack(delivery_tag=method.delivery_tag)
|
|
41
|
-
self.close()
|
|
42
|
-
|
|
31
|
+
self.channel = await self.connection.channel()
|
|
32
|
+
await self.channel.set_qos(prefetch_count=1)
|
|
33
|
+
await self.channel.declare_queue(self.queue, durable=True)
|
|
34
|
+
|
|
35
|
+
async def start_consuming(self, callback):
|
|
43
36
|
if not self.channel:
|
|
44
37
|
raise RuntimeError("❌ Canal RabbitMQ não conectado. Chame connect() antes.")
|
|
45
38
|
|
|
46
|
-
self.channel.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
queue = await self.channel.get_queue(self.queue)
|
|
40
|
+
|
|
41
|
+
async def on_message(message):
|
|
42
|
+
async with message.process():
|
|
43
|
+
try:
|
|
44
|
+
mensagem = json.loads(message.body.decode())
|
|
45
|
+
await callback(mensagem) # aqui sim passa o DTO
|
|
46
|
+
except Exception as e:
|
|
47
|
+
print(f"❌ Erro ao processar mensagem: {e}")
|
|
48
|
+
|
|
49
|
+
await queue.consume(on_message) # registra callback
|
|
50
|
+
|
|
51
|
+
print(f'[*] Aguardando mensagens na fila "{self.queue}". Para sair pressione CTRL+C')
|
|
52
|
+
|
|
53
|
+
# Mantém o consumer rodando
|
|
54
|
+
await asyncio.Future()
|
|
55
|
+
|
|
52
56
|
|
|
53
|
-
def close(self):
|
|
57
|
+
async def close(self):
|
|
54
58
|
if self.connection:
|
|
55
|
-
self.connection.close()
|
|
59
|
+
await self.connection.close()
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import aio_pika
|
|
2
|
+
import json
|
|
3
|
+
from aio_pika.abc import AbstractRobustConnection, AbstractChannel, AbstractQueue
|
|
4
|
+
|
|
5
|
+
class RabbitMQPublisher:
|
|
6
|
+
def __init__(
|
|
7
|
+
self,
|
|
8
|
+
host: str,
|
|
9
|
+
queue: str,
|
|
10
|
+
username: str,
|
|
11
|
+
password: str,
|
|
12
|
+
vhost: str = "/",
|
|
13
|
+
):
|
|
14
|
+
self.host = host
|
|
15
|
+
self.queue = queue
|
|
16
|
+
self.username = username
|
|
17
|
+
self.password = password
|
|
18
|
+
self.vhost = vhost
|
|
19
|
+
|
|
20
|
+
self.connection: AbstractRobustConnection | None = None
|
|
21
|
+
self.channel: AbstractChannel | None = None
|
|
22
|
+
self.queue_obj: AbstractQueue | None = None
|
|
23
|
+
|
|
24
|
+
async def connect(self):
|
|
25
|
+
self.connection = await aio_pika.connect_robust(
|
|
26
|
+
host=self.host,
|
|
27
|
+
login=self.username,
|
|
28
|
+
password=self.password,
|
|
29
|
+
virtualhost=self.vhost,
|
|
30
|
+
heartbeat=60,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
self.channel = await self.connection.channel()
|
|
35
|
+
# garante que mensagens não são perdidas
|
|
36
|
+
self.queue_obj = await self.channel.declare_queue(
|
|
37
|
+
self.queue, durable=True
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
async def publish(self, message: dict):
|
|
41
|
+
if not self.channel:
|
|
42
|
+
raise RuntimeError("❌ Canal RabbitMQ não conectado. Chame connect() antes.")
|
|
43
|
+
|
|
44
|
+
body = json.dumps(message).encode("utf-8")
|
|
45
|
+
await self.channel.default_exchange.publish(
|
|
46
|
+
aio_pika.Message(
|
|
47
|
+
body=body,
|
|
48
|
+
delivery_mode=aio_pika.DeliveryMode.PERSISTENT, # torna a msg persistente
|
|
49
|
+
),
|
|
50
|
+
routing_key=self.queue,
|
|
51
|
+
)
|
|
52
|
+
print(f"✅ Mensagem publicada na fila '{self.queue}': {message}")
|
|
53
|
+
|
|
54
|
+
async def close(self):
|
|
55
|
+
if self.connection:
|
|
56
|
+
await self.connection.close()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class RequestServicoApi:
|
|
5
|
+
def __init__(self, url, token):
|
|
6
|
+
self.url = url
|
|
7
|
+
self.token = token
|
|
8
|
+
self.client = httpx.AsyncClient(timeout=120, verify=False)
|
|
9
|
+
|
|
10
|
+
async def handler(self, *, mensagem_atualizacao: dict):
|
|
11
|
+
print(self.token)
|
|
12
|
+
response = await self.client.post(self.url, json=mensagem_atualizacao)
|
|
13
|
+
|
|
14
|
+
if response.status_code != 200:
|
|
15
|
+
raise Exception(f"Erro ao fazer request ao servico de API: {response.status_code}")
|
|
16
|
+
|
|
17
|
+
await self.close()
|
|
18
|
+
|
|
19
|
+
async def close(self):
|
|
20
|
+
await self.client.aclose()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libretificacaotjcore
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.49
|
|
4
4
|
Summary: Biblioteca para centralizar conexao com filas no rabbit e banco de dados no mongodb para os servicos de retificacao da TJ
|
|
5
5
|
Author-email: Jhonatan Azevedo <dev.azevedo@outlook.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/seu-usuario/libretificacaotjcore
|
|
@@ -21,9 +21,11 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Operating System :: OS Independent
|
|
22
22
|
Requires-Python: >=3.12
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
|
+
Requires-Dist: aio-pika>=9.5.7
|
|
24
25
|
Requires-Dist: aiofiles>=24.1.0
|
|
25
26
|
Requires-Dist: boto3>=1.39.16
|
|
26
27
|
Requires-Dist: cryptography>=45.0.6
|
|
28
|
+
Requires-Dist: httpx>=0.28.1
|
|
27
29
|
Requires-Dist: motor>=3.7.1
|
|
28
30
|
Requires-Dist: pika>=1.3.2
|
|
29
31
|
Requires-Dist: py7zr>=1.0.0
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
libretificacaotjcore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
libretificacaotjcore/database/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
3
|
+
libretificacaotjcore/database/arquivo_repository.py,sha256=sWXdaHzS0xogZfa4VtdMcd7P7QOmStn12GrNVcGAuYo,2156
|
|
4
|
+
libretificacaotjcore/database/certificado_repository.py,sha256=LF3rV1rQmRGZVB4wPh_vmDj81Gf_env_5hqtTbxXNFM,1396
|
|
5
|
+
libretificacaotjcore/database/config_db.py,sha256=ZrOynusf7YIrkITEZQ-8KLMPJLBiHWIAg1EyFvHjVSE,2572
|
|
6
|
+
libretificacaotjcore/database/protocolo_repository.py,sha256=kb-mXxiOYDPbrPbYMhOb9xDZHknUdVSfVlmQ_Cn0l1s,3788
|
|
7
|
+
libretificacaotjcore/database/rubrica_repository.py,sha256=BVZLukKVH1YKRgPkk18aqck90DdNGrqv4cYr1IRSbL4,1130
|
|
8
|
+
libretificacaotjcore/database/tempo_processo_repository.py,sha256=3pbeh69qI3I-Ucw-mGYrVLkyeh_wKTKAorq71ZHuc_k,3981
|
|
9
|
+
libretificacaotjcore/dtos/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
libretificacaotjcore/dtos/arquivo_dto.py,sha256=D4LLJZf-Z0XhJmOvu7nAcBq0j70m9TFtbgxI9ikHXQ0,1045
|
|
11
|
+
libretificacaotjcore/dtos/processo_dto.py,sha256=KbG3TjcxHS4UTdflApChBrq6BpM8xS1Cd6PNba--hA0,3096
|
|
12
|
+
libretificacaotjcore/dtos/solicitacao_dto.py,sha256=dmI-JGgE0wZ9zXqej6pqSIIaopkROnBQo2Hj3pEXcZ8,2576
|
|
13
|
+
libretificacaotjcore/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
libretificacaotjcore/enums/e_eventos.py,sha256=4NICIKFpxEvxMbHu_kcKqNXqylDETcr6qY1tK2bKmi4,207
|
|
15
|
+
libretificacaotjcore/enums/e_fase_retificacao.py,sha256=v7ERN6MuhdiuT2Yhzu5yzvR6rpKaxqoNMKrBlk4zhkY,1074
|
|
16
|
+
libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
libretificacaotjcore/services/crypto_pass_service.py,sha256=9D0vyjan6f_8AfNxGkLpGdvyMpojsJq_AAySpv_zKMc,740
|
|
18
|
+
libretificacaotjcore/services/file_service.py,sha256=14CJokBbrsryQGmL0_unH2QKZpnteEAfxf5CPFdv6cE,2075
|
|
19
|
+
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=yRS3sAkaMIIn8Y06icwkO1bpddlLC7BmNSHJVhUalzY,1818
|
|
20
|
+
libretificacaotjcore/services/rabbitmq_publisher.py,sha256=xsb9LmIuZizzq5lxnEEZKMK3U952KSQ2oqlTBZi2Lt8,1787
|
|
21
|
+
libretificacaotjcore/services/request_servico_api.py,sha256=G7vnmvOfwrCGL-Jy_5tCKG-l5E00OCkJfkuoa5Y6sHo,613
|
|
22
|
+
libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
|
|
23
|
+
libretificacaotjcore-0.1.49.dist-info/METADATA,sha256=1x9RtwNRlGp8NrJLfPW8HE4s_16vE-th92cweckLYek,2564
|
|
24
|
+
libretificacaotjcore-0.1.49.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
25
|
+
libretificacaotjcore-0.1.49.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
|
|
26
|
+
libretificacaotjcore-0.1.49.dist-info/RECORD,,
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
libretificacaotjcore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
libretificacaotjcore/database/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
3
|
-
libretificacaotjcore/database/arquivo_repository.py,sha256=Wv42CWjddS8RPVR3aAOGwuFuLyGqmgq-TXOc-V0BTvE,2154
|
|
4
|
-
libretificacaotjcore/database/certificado_repository.py,sha256=LF3rV1rQmRGZVB4wPh_vmDj81Gf_env_5hqtTbxXNFM,1396
|
|
5
|
-
libretificacaotjcore/database/config_db.py,sha256=1SNpQV6GcrS0aZGX12wXmxhmLb8oc3uV4_H6HQ1z74w,1775
|
|
6
|
-
libretificacaotjcore/database/protocolo_repository.py,sha256=kb-mXxiOYDPbrPbYMhOb9xDZHknUdVSfVlmQ_Cn0l1s,3788
|
|
7
|
-
libretificacaotjcore/dtos/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
libretificacaotjcore/dtos/arquivo_dto.py,sha256=D4LLJZf-Z0XhJmOvu7nAcBq0j70m9TFtbgxI9ikHXQ0,1045
|
|
9
|
-
libretificacaotjcore/dtos/solicitacao_dto.py,sha256=QxmAuWZSvNeN1KRJ-sPY9sEwXQnnIpAozAOUNkJqflY,2149
|
|
10
|
-
libretificacaotjcore/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
libretificacaotjcore/enums/e_eventos.py,sha256=x1LXcTLNCAAj1MuQP6jT5vu9cFkoAyGEzPAqQHj_8L8,185
|
|
12
|
-
libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
libretificacaotjcore/services/crypto_pass_service.py,sha256=9D0vyjan6f_8AfNxGkLpGdvyMpojsJq_AAySpv_zKMc,740
|
|
14
|
-
libretificacaotjcore/services/file_service.py,sha256=14CJokBbrsryQGmL0_unH2QKZpnteEAfxf5CPFdv6cE,2075
|
|
15
|
-
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=a25mRHjbkgO3lkdCJ5NpJfWAGHhVkQDCRDR2t8hMNAI,1710
|
|
16
|
-
libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
|
|
17
|
-
libretificacaotjcore-0.1.25.dist-info/METADATA,sha256=HTDZQ2H3C5cTVW8TbBEJaPrjv2zLjT5CYju-iNuWLwc,2502
|
|
18
|
-
libretificacaotjcore-0.1.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
-
libretificacaotjcore-0.1.25.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
|
|
20
|
-
libretificacaotjcore-0.1.25.dist-info/RECORD,,
|
|
File without changes
|
{libretificacaotjcore-0.1.25.dist-info → libretificacaotjcore-0.1.49.dist-info}/top_level.txt
RENAMED
|
File without changes
|