Skip to content

Conversation

@pitangainnovare
Copy link
Contributor

@pitangainnovare pitangainnovare commented May 10, 2024

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:

from log_manager import tasks

tasks.task_log_files_count_status_report(collection_acron2='wi')
tasks.task_check_missing_logs_for_date_range('2024-01-01', '2024-01-15', collection_acron2='wi')

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.
image

Exemplo de dados do novo modelo que armazena relatório de logs ausentes/extras e corretos
image

Quais são tickets relevantes?

N/A

Referências

N/A

@pitangainnovare pitangainnovare marked this pull request as ready for review May 25, 2024 00:13
blank=False,
)

existing_log_files = models.IntegerField(
Copy link
Member

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

default=0,
)

required_log_files = models.IntegerField(
Copy link
Member

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

)

@classmethod
def create_or_update(cls, user, collection, date, required_log_files, existing_log_files):
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O seguinte trecho garante que só haja um registro por data e coleção:

image



@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):
Copy link
Member

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


@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(',')]
Copy link
Member

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

Comment on lines +169 to +171
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)
Copy link
Member

@robertatakenaka robertatakenaka Jun 12, 2024

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"}

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:
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sim.

send_mail(
subject=subject,
message=message,
from_email='log_manager@scielo.org',
Copy link
Member

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

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.")
Copy link
Member

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

Copy link
Member

@robertatakenaka robertatakenaka left a 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

@pitangainnovare
Copy link
Contributor Author

@robertatakenaka, fiz as alterações sugeridas. Aguardo novas avaliações. Enquanto isso, irei seguir com as tabelas top100, como acordado.

@pitangainnovare pitangainnovare merged commit 17ce0c2 into scieloorg:main Jul 17, 2024
@pitangainnovare pitangainnovare deleted the impl/report-missing-dates branch July 17, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants