# Rules

## Overview

If you prefer to receive notifications only when predefined criteria are met, you can set up rules when creating a orquestration webhook. The rules consist of three components: variable, operation, and value.

The available operations vary depending on the data type of the variable:

|                     |                                                                   |
| ------------------- | ----------------------------------------------------------------- |
| `uuid` and `string` | `EQUAL`, `NOT_EQUAL`, `IN`, `NOT_IN`                              |
| `integer`           | `EQUAL`, `NOT_EQUAL`, `IN`, `NOT_IN`, `LESS_THAN`, `GREATER_THAN` |
| `date` and `time`   | `LESS_THAN`, `GREATER_THAN`                                       |
| `boolean`           | `EQUAL`, `NOT_EQUAL`                                              |

Rules must be specified during the creation of a webhook, provided via the `rules` attribute. Below is an example of a body with multiple rules for reference:

```json
{   
    "description": "airflow_trigger_example",
    "is_active": true,
    "jobs": [
        "uuid_1", 
        "uuid_2", 
        ..., 
        "uuid_n"
    ],
    "method": "POST",
    "url": "https://{{variables.TOOL_URL}}/api/v1/dags/{{erathos.JOB_ID}}/dagRuns",
    "header": {
        "Content-Type": "application/json",
        "Authorization": "Basic ${{secrets.USER_KEY}}"
    },
    "body": {
        "conf": {
            "name": "{{erathos.TABLE_NAME}}",
            "status": "${{erathos.STATUS}}"
        }
    },
    "rules": [
        {
            "erathos_variable": "STATUS",
            "operation": "EQUAL",
            "value": "FINISHED"
        },
        {
            "erathos_variable": "ROWS",
            "operation": "GREATER_THAN",
            "value": "0"
        },
        {
            "erathos_variable": "FINISHED_AT_TIME",
            "operation": "GREATER_THAN",
            "value": "00:00"
        },
        {
            "erathos_variable": "FINISHED_AT_TIME",
            "operation": "LESS_THAN",
            "value": "08:00"
        },
        {
            "erathos_variable": "FINISHED_AT_WEEKDAY",
            "operation": "NOT_IN",
            "value": ["0", "6"]
        }
    ]
}
```

To discover the variables available for creating rules, refer to [Metadata](/api/concepts/metadata.md).

## Examples

Below are groups of frequently used rules that can be included in your custom webhooks and combined with the webhook templates presented next.

### Execution status

#### Success

Every successful execution that has encountered any data.

```json
{
  ...
  "rules": [
    {
      "variable_name": "STATUS",
      "operation": "EQUAL",
      "value": "FINISHED"
    },
    {
      "variable_name": "ROWS",
      "operation": "GREATER_THAN",
      "value": "0"
    }
  ],
  ...
}
```

#### Failed

Every execution that results in a failure.

### Dependent jobs

Filter only the main tables (endpoints with nested tables generate a separate webhook for each table when this rule is not used).

```json
{
  ...
  "rules": [
    {
      "variable_name": "NESTED_TABLE",
      "operation": "EQUAL",
      "value": "false"
    },
  ],
  ...
}
```

### Time

Executions during weekdays between 00:00 BRT and 08:00 BRT.

```json
{
  ...
  "rules": [
    {
      "variable_name": "FINISHED_AT_WEEKDAY",
      "operation": "IN",
      "value": ["1", "2", "3", "4", "5"]
    },
    {
      "variable_name": "FINISHED_AT_TIME",
      "operation": "GREATER_THAN",
      "value": '02:59'
    },
    {
      "variable_name": "FINISHED_AT_TIME",
      "operation": "LESS_THAN",
      "value": "11:00"
    }
  ],
  ...
}
```

### Execution type

Filter only Full Refresh executions.

```json
{
  ...
  "rules": [
    {
      "variable_name": "FORCE_HISTORY",
      "operation": "EQUAL",
      "value": "true"
    },
  ],
  ...
}
```

### Schedules

Filter only scheduled executions.

```json
{
  ...
  "rules": [
    {
      "variable_name": "TRIGGERED_BY",
      "operation": "EQUAL",
      "value": "Erathos Schedule"
    },
  ],
  ...
}
```

### Orchestration

Filter only executions triggered programmatically.

```json
{
  ...
  "rules": [
    {
      "variable_name": "IS_ORCHESTRATION",
      "operation": "EQUAL",
      "value": "true"
    },
  ],
  ...
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.erathos.com/api/concepts/rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
