feat: admin_data_tools — gerenciamento persistente de flow schedules#1017
Merged
feat: admin_data_tools — gerenciamento persistente de flow schedules#1017
Conversation
Create new Django app admin_data_tools and migrate the disable_unhealthy_flow_schedules management command (and its supporting package) from core to the new app.
Introduce DisabledFlowSchedule to persistently track disabled Prefect flow schedules across re-registrations. The Django admin allows operators to reactivate flows via a checkbox, which calls the Prefect mutation directly and records reactivated_at for use in post-reactivation checks.
Refactor FlowService into two explicit phases: Phase 1 (enforce): re-disables flows that Prefect reactivated after re-registration, and detects new failures in flows previously reactivated by an admin using reactivated_at as the baseline (valid_since) instead of Prefect's unreliable created field. Phase 2 (detect): queries only untracked failing flows, validates them, disables and registers new ones, then sends a chunked Discord notification to respect the 2000-character limit. Also adds ACTIVE_FLOWS_BY_NAMES query, disable_flow_schedule workaround, Google-style type hints and docstrings across all modules, and requests-toolbelt as an explicit dependency.
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: admin_data_tools — gerenciamento persistente de flow schedules
Contexto
Este PR cria o app
admin_data_tools, migra o management commanddisable_unhealthy_flow_schedulesdo appcoree resolve um problema estrutural do comando original: o Prefect 0.15 re-registra flows com novo UUID e novocreated, fazendo com que o campocreated— usado como baseline temporal na validação — se torne não confiável.A solução introduz o model
DisabledFlowSchedule, que persiste os flows desativados no banco usando onamecomo identificador estável. OFlowServicepassa a rodar um pipeline de duas fases para garantir que flows permaneçam desativados mesmo após re-registro, e que flows reativados pelo admin voltem a ser monitorados corretamente.Organização de pastas
Diagrama visual do fluxo de execução
Estrutura do código
1. Model
DisabledFlowScheduleRastreia flows desativados no banco usando
flow_namecomo identificador estável — oflow_id(UUID) é atualizado automaticamente quando o Prefect re-registra o flow.2. Django Admin —
DisabledFlowScheduleAdminO checkbox
is_schedule_activechama a mutation do Prefect diretamente ao salvar, sem necessidade de intervenção manual no Prefect. Ao reativar, gravareactivated_atpara uso como baseline nas verificações futuras.Acesso controlado pelo sistema de permissões padrão do Django —
is_staff=True+ permissões de modelo, sem necessidade de superuser.3.
FlowDisable— domínio e regra de negócioO campo
valid_sincesubstitui ocreateddo Prefect como baseline temporal. Para flows novos recebe ocreateddo Prefect; para flows reativados pelo admin recebe oreactivated_atdo banco.Critérios de desativação —
validate()O flow é desativado se qualquer uma das condições abaixo for atendida após
valid_since:1. Falha de task crítica
run_dbtSTATE_MESSAGE_IGNORE)2. Falhas consecutivas
Failed4.
FlowService— pipeline de duas fasesFase 1 — Enforce
Percorre flows rastreados no banco (
is_schedule_active=Falseoureactivated_atpreenchido), consulta o Prefect pelos que estão ativos e aplica a ação correta:Fase 2 — Detect
Consulta flows com falhas na última semana, filtra os não rastreados, valida e desativa:
Workaround de bug do Prefect
Como testar
Verifique no Django Admin (
/admin/admin_data_tools/disabledflowschedule/) que os flows desativados aparecem corretamente.Marque o checkbox
is_schedule_activede um flow e salve — confirme que a mutation foi chamada no Prefect.Verifique que um usuário com
is_staff=Truee permissõesadmin_data_tools | disabled flow schedule | Can view/changeacessa o admin sem ser superuser.