-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cria funcionalidade para notificar ausência de arquivos de log #15
Cria funcionalidade para notificar ausência de arquivos de log #15
Conversation
…por novo modelo CollectionTeam)
…go" (a ser substituída por um campo baseado em números: -1, -2, ...)
…ivada deveria existir
…ser separada em duas tasks: contagem e notificação)
log_manager/models.py
Outdated
blank=False, | ||
) | ||
|
||
existing_log_files = models.IntegerField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare no lugar de existing, usar found, fica mais explícito
log_manager/models.py
Outdated
default=0, | ||
) | ||
|
||
required_log_files = models.IntegerField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare no lugar de required, usar expected, fica mais explícito
log_manager/models.py
Outdated
) | ||
|
||
@classmethod | ||
def create_or_update(cls, user, collection, date, required_log_files, existing_log_files): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare adote o padrão de ter também get, create, IntegrityError. Se as tarefas executarem concorrentemente registros ficam duplicados
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log_manager/tasks.py
Outdated
|
||
|
||
@celery_app.task(bind=True, name=_('Check Missing Logs for Date Range')) | ||
def task_check_missing_logs_for_date_range(self, start_date, end_date, collection_acron2=None, user_id=None, username=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare Use collection_acron2 como lista e não como string
log_manager/tasks.py
Outdated
|
||
@celery_app.task(bind=True, name=_('Check Missing Logs for Date Range')) | ||
def task_check_missing_logs_for_date_range(self, start_date, end_date, collection_acron2=None, user_id=None, username=None): | ||
acron2_list = [c.acron2 for c in models.Collection.objects.iterator()] if not collection_acron2 else [c.strip() for c in collection_acron2.split(',')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare crie uma propriedade em Collection para retornar a lista de acron2
missing = models.CollectionLogFileDateCount.objects.filter(status=choices.COLLECTION_LOG_FILE_DATE_COUNT_MISSING_FILES) | ||
extra = models.CollectionLogFileDateCount.objects.filter(status=choices.COLLECTION_LOG_FILE_DATE_COUNT_EXTRA_FILES) | ||
ok = models.CollectionLogFileDateCount.objects.filter(status=choices.COLLECTION_LOG_FILE_DATE_COUNT_OK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare No lugar destes 3 comandos, use:
from django.db.models import Count
items = models.CollectionLogFileDateCount.objects.values('status', 'collection').annotate(total=Count('id'))
Obterá o resultado:
>>> {"status": "ok", "total": 10, "collection": "x"}
>>> {"status": "missing", "total": 30, "collection": "x"}
>>> {"status": "extra", "total": 50, "collection": "x"}
log_manager/tasks.py
Outdated
extra = models.CollectionLogFileDateCount.objects.filter(status=choices.COLLECTION_LOG_FILE_DATE_COUNT_EXTRA_FILES) | ||
ok = models.CollectionLogFileDateCount.objects.filter(status=choices.COLLECTION_LOG_FILE_DATE_COUNT_OK) | ||
|
||
if ok.exists() > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare exists não retorna bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sim.
log_manager/tasks.py
Outdated
send_mail( | ||
subject=subject, | ||
message=message, | ||
from_email='log_manager@scielo.org', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare usar variável de ambiente
log_manager/tasks.py
Outdated
config_type=choices.COLLECTION_CONFIG_TYPE_EMAIL, | ||
) | ||
if col_configs.count() == 0: | ||
raise exceptions.UndefinedCollectionConfigError("ERROR. Please, add an Application Configuration for the EMAIL attribute.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare preparar para usar mensagens traduzíveis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitangainnovare verificar comentários
…em dev não existia, em prod já existia)
…ma mesma coleção pode ter várias configurações. Por exemplo, de 01/01/2020 a 01/06/2020, exigia-se 1 arquivo por dia. A partir de 02/06/2020 passou-se a exigir 2 por dia. O método foi corrigido para capturar essas situações.
@robertatakenaka, fiz as alterações sugeridas. Aguardo novas avaliações. Enquanto isso, irei seguir com as tabelas top100, como acordado. |
O que esse PR faz?
Este PR cria uma funcionalidade para notificar ausência e corretude de arquivos de log. A notificação é realizada por e-mail. A meta é que o sistema esteja configurado para executar verificações periódicas (Periodic Tasks) e informar os responsáveis pelas coleções acerca dos arquivos de log faltantes bem como das datas que estão completas (com todos os arquivos de log esperados válidos).
Por onde a revisão poderia começar?
A partir do commit fa24d29
Como este poderia ser testado manualmente?
Tenha uma configuração válida como indicado no PR #1.
Para checar os resultados da coleção West Indies nas datas 2024-01-01 a 2024-01-15, faça:
Ou use o Periodic Tasks na interface web, registrando essas tasks.
Algum cenário de contexto que queira dar?
N/A
Screenshots
Exemplo de mensagem contendo relatório de logs ausentes e com datas corretas.
Exemplo de dados do novo modelo que armazena relatório de logs ausentes/extras e corretos
Quais são tickets relevantes?
N/A
Referências
N/A