Skip to content

Cria funcionalidade para notificar ausência de arquivos de log - #15

Merged
pitangainnovare merged 29 commits into
scieloorg:mainfrom
pitangainnovare:impl/report-missing-dates
Jul 17, 2024
Merged

Cria funcionalidade para notificar ausência de arquivos de log#15
pitangainnovare merged 29 commits into
scieloorg:mainfrom
pitangainnovare:impl/report-missing-dates

Conversation

@pitangainnovare

@pitangainnovarepitangainnovare commented May 10, 2024

Copy link
Copy Markdown
Contributor

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:

fromlog_managerimporttaskstasks.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
Comment threadlog_manager/models.py Outdated
blank=False,
)

existing_log_files = models.IntegerField(

Copy link
Copy Markdown
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

Comment threadlog_manager/models.py Outdated
default=0,
)

required_log_files = models.IntegerField(

Copy link
Copy Markdown
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

Comment threadlog_manager/models.py Outdated
)

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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

Comment threadlog_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):

Copy link
Copy Markdown
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

Comment threadlog_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(',')]

Copy link
Copy Markdown
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 threadlog_manager/tasks.py
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)

@robertatakenakarobertatakenakaJun 12, 2024

Copy link
Copy Markdown
Member

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:

fromdjango.db.modelsimportCountitems=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"}

Comment threadlog_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:

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Sim.

Comment threadlog_manager/tasks.py Outdated
send_mail(
subject=subject,
message=message,
from_email='log_manager@scielo.org',

Copy link
Copy Markdown
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

Comment threadlog_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.")

Copy link
Copy Markdown
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

@robertatakenakarobertatakenaka left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

@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:mainJul 17, 2024
@pitangainnovare
pitangainnovare deleted the impl/report-missing-dates branch July 17, 2024 12:20
Sign up for freeto 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

@pitangainnovare@robertatakenaka@rafaelpezzuto