Aller au contenu

Introduction aux Workflows

Qu'est-ce qu'un Workflow ?

Un workflow est une séquence de tâches exécutées dans un ordre spécifique sur un appareil Android. Il définit la logique, les conditions et le flux des actions d'automatisation.

Structure Interne : Basée sur un Graphe

En interne, les workflows sont représentés comme un graphe orienté avec : - Nœuds : Tâches individuelles (Start, End, tâches normales, conditions) - Arêtes/Liens : Connexions entre nœuds définissant le flux d'exécution - Point d'entrée : Nœud START unique par lequel l'exécution commence - Points de sortie : Un ou plusieurs nœuds END où l'exécution se termine

Le moteur de workflow traverse le graphe en commençant par START, suit les liens, et exécute chaque nœud jusqu'à atteindre un nœud END.

Exemple de structure JSON :

{
  "Start": [
    {
      "id": "0",
      "title": "Test de Connectivité Réseau",
      "variables": [
        {
          "variableName": "$network_status",
          "variableValue": "unknown",
          "is_kpi": false
        }
      ]
    }
  ],

  "CmdStage": [
    {
      "id": "1",
      "title": "Ping Google DNS",
      "cmd_text": "ping -c 1 8.8.8.8",
      "cmd_result_output": "$PING_RESULT",
      "cmd_error_output": "$PING_ERROR"
    }
  ],

  "CompareText": [
    {
      "id": "2",
      "title": "Vérifier si Réseau Inaccessible",
      "text_x": "$PING_ERROR",
      "text_y": "unreachable",
      "compare_type": 2
    }
  ],

  "TextReport": [
    {
      "id": "3",
      "title": "Logger Réseau Hors Ligne",
      "texte": "Le réseau est inaccessible: $PING_ERROR"
    },
    {
      "id": "4",
      "title": "Logger Réseau En Ligne",
      "texte": "Le réseau est OK: $PING_RESULT"
    }
  ],

  "End": [
    {
      "id": "100",
      "title": "Workflow Terminé"
    }
  ],

  "Links": [
    {
      "from": "0",
      "to": "1"
    },
    {
      "from": "1",
      "to": "2"
    },
    {
      "from": "2",
      "true": "3",
      "false": "4"
    },
    {
      "from": "3",
      "to": "100"
    },
    {
      "from": "4",
      "to": "100"
    }
  ]
}

Visualisation du graphe :

START (id:0)
TextReport (id:1)
CompareNumber (id:2)
    ├─→ VRAI → END (id:100)
    └─→ FAUX → TextReport (id:1) [boucle]

La section Links définit comment les nœuds sont connectés et le flux d'exécution :

Types de Liens

1. Lien Séquentiel (Tâche Normale)

Connecte une tâche directement à la suivante :

{
  "from": "0",
  "to": "1"
}

Signification : Après la fin du nœud 0, exécuter immédiatement le nœud 1.


2. Lien Conditionnel (Nœud de Décision)

Branche l'exécution selon le résultat de la condition :

{
  "from": "2",
  "true": "100",
  "false": "1"
}

Signification : - Si la condition du nœud 2 est VRAI → aller au nœud 100 - Si la condition du nœud 2 est FAUX → aller au nœud 1


Algorithme de Parcours du Graphe

Le moteur de workflow :

  1. Démarre au nœud START (id : 0 ou similaire)
  2. Suit les liens "from" → "to"
  3. Évalue les conditions et branches (true/false)
  4. Exécute chaque tâche à chaque nœud visité
  5. S'arrête en atteignant un nœud END

Exemple Complet de Workflow avec Structure Graphe

Scénario : Vérifier la température et enregistrer le résultat

{
  "Start": [
    {
      "id": "0",
      "title": "Initialiser",
      "variables": [
        {
          "variableName": "$temperature",
          "variableValue": "25",
          "is_kpi": true
        }
      ]
    }
  ],

  "TextReport": [
    {
      "id": "1",
      "title": "Logger Température",
      "texte": "Température actuelle: $temperature°C"
    }
  ],

  "CompareNumber": [
    {
      "id": "2",
      "title": "Vérifier Température",
      "num_x": "$temperature",
      "num_y": "30",
      "compare_type": 1
    }
  ],

  "TextReport": [
    {
      "id": "3",
      "title": "Alerte Température Élevée",
      "texte": "Température dépasse 30°C: $temperature°C"
    },
    {
      "id": "4",
      "title": "Température Normale",
      "texte": "Température OK: $temperature°C"
    }
  ],

  "End": [
    {
      "id": "100"
    }
  ],

  "Links": [
    {
      "from": "0",
      "to": "1"
    },
    {
      "from": "1",
      "to": "2"
    },
    {
      "from": "2",
      "true": "3",
      "false": "4"
    },
    {
      "from": "3",
      "to": "100"
    },
    {
      "from": "4",
      "to": "100"
    }
  ]
}

Flux du Graphe :

flowchart TD
    Start([START id:0<br/>temperature=25]) --> TextReport1[TextReport id:1<br/>Logger Température]
    TextReport1 --> CompareNum[CompareNumber id:2<br/>25 > 30?]
    CompareNum -->|VRAI| TextReport3[TextReport id:3<br/>Alerte Trop Chaud]
    CompareNum -->|FAUX| TextReport4[TextReport id:4<br/>Température Normale]
    TextReport3 --> End[END id:100]
    TextReport4 --> End

    style Start fill:#e3f2fd
    style End fill:#c8e6c9
    style CompareNum fill:#fff9c4
    style TextReport1 fill:#f3e5f5
    style TextReport3 fill:#ffe0e0
    style TextReport4 fill:#e0f0e0

Structure du Workflow

Chaque workflow se compose de :

  1. Une seule tâche START - Point d'entrée (toujours requise)
  2. Une ou plusieurs tâches END - Points de sortie (au moins une requise)
  3. Tâches normales - S'exécutent séquentiellement sans conditions
  4. Tâches conditionnelles - S'exécutent selon des conditions logiques

Diagramme

flowchart TD
    Start([START]) --> NormalTask[Tâche Normale]
    NormalTask --> ConditionTask{Tâche Condition}
    ConditionTask -->|VRAI| ThenTask[Tâche Then]
    ConditionTask -->|FAUX| ElseTask[Tâche Else]
    ThenTask --> EndTask([Tâche END])
    ElseTask --> EndTask

    style Start fill:#e3f2fd
    style EndTask fill:#c8e6c9
    style NormalTask fill:#fff9c4
    style ThenTask fill:#ffe0e0
    style ElseTask fill:#e0f0e0

Résumé Workflow Components

Composant But Quantité Clé JSON Exemple ID Description
START Task Point d'entrée, initialise workflow Exactement 1 "Start" "0" Commence l'exécution.
Tâches Normales S'exécutent séquentiellement sans conditions 0 ou plus Type de tâche (CmdStage, Sleep, etc.) "1", "2" S'exécutent l'une après l'autre.
Tâches Conditionnelles Branchent l'exécution selon conditions 0 ou plus CompareNumber, CompareText "2" Évaluent vrai/faux et branchent.
END Task Point de sortie, termine workflow 1 ou plus "End" "100" Termine l'exécution. Plusieurs endpoints possibles.
Links Définissent connexions entre nœuds Requis "Links" N/A Mappent IDs nœuds avec "from", "to", "true", "false"

Flux d'Exécution du Workflow

Flux Basique (Linéaire)

Exécution linéaire : START → Tâche 1 → Tâche 2 → END

Exemple JSON :

{
  "Start": [{"id": "0"}],
  "CmdStage": [{"id": "1", "cmd_text": "ping -c 1 8.8.8.8"}],
  "Sleep": [{"id": "2", "Time_sleep": 1000}],
  "End": [{"id": "100"}],
  "Links": [
    {"from": "0", "to": "1"},
    {"from": "1", "to": "2"},
    {"from": "2", "to": "100"}
  ]
}

Diagramme Mermaid :

flowchart TD
    Start([START id:0]) --> Task1[CmdStage id:1<br/>ping]
    Task1 --> Task2[Sleep id:2<br/>1000ms]
    Task2 --> End[END id:100]

    style Start fill:#e3f2fd
    style End fill:#c8e6c9
    style Task1 fill:#f3e5f5
    style Task2 fill:#fff9c4

Flux Branché (Conditionnel)

Exécution branchée avec chemins vrai/faux : START → Tâche 1 → Condition → (VRAI→Tâche2 | FAUX→Tâche3) → END

Exemple JSON :

{
  "Start": [{"id": "0"}],
  "CmdStage": [{"id": "1", "cmd_text": "ping -c 1 8.8.8.8", "cmd_error_output": "$ERROR"}],
  "CompareText": [{"id": "2", "text_x": "$ERROR", "text_y": "unreachable", "compare_type": 2}],
  "TextReport": [
    {"id": "3", "texte": "Réseau hors ligne"},
    {"id": "4", "texte": "Réseau en ligne"}
  ],
  "End": [{"id": "100"}],
  "Links": [
    {"from": "0", "to": "1"},
    {"from": "1", "to": "2"},
    {"from": "2", "true": "3", "false": "4"},
    {"from": "3", "to": "100"},
    {"from": "4", "to": "100"}
  ]
}

Diagramme Mermaid :

flowchart TD
    Start([START id:0]) --> Task1[CmdStage id:1<br/>ping]
    Task1 --> Condition[CompareText id:2<br/>ERROR contient unreachable?]
    Condition -->|VRAI| Task3[TextReport id:3<br/>Réseau Down]
    Condition -->|FAUX| Task4[TextReport id:4<br/>Réseau Up]
    Task3 --> End[END id:100]
    Task4 --> End

    style Start fill:#e3f2fd
    style End fill:#c8e6c9
    style Condition fill:#fff9c4
    style Task1 fill:#f3e5f5
    style Task3 fill:#ffe0e0
    style Task4 fill:#e0f0e0