# cdc-dm-import-abnormal-check

Detect long-stuck CDC and DM jobs from the same Grafana-backed SQL data used by
workflow reporting jobs.

## Current Scope

- DM: `df_jobs.phase = 'creating'` and it has stayed there for more than 30 minutes
- CDC: `biz_changefeeds.operation_status = 'deleting'` and it has stayed there for more than 24 hours

This job sends a Feishu interactive alert card only when new abnormal jobs are
detected. By default it targets the workflow notification group configured by
`ONCALL_NOTIFY_CHAT_ID` or `ONCALL_METRICS_CHAT_ID`.

## Usage

```bash
python3 cronjobs/team-workflow/cdc-dm-import-abnormal-check/main.py
python3 cronjobs/team-workflow/cdc-dm-import-abnormal-check/main.py --format json
```

## Environment Variables

```bash
export DATASERVICE_GRAFANA_TOKEN="your-grafana-token"
export CRONJOB_TEAM_WORKFLOW_APP_ID="your-feishu-app-id"
export CRONJOB_TEAM_WORKFLOW_APP_SECRET="your-feishu-app-secret"
export ONCALL_NOTIFY_CHAT_ID="chat:oc_xxx"
```

Set `SKIP_SEND_NOTIFICATION=true` to dry-run without sending Feishu messages.

## State File

Default state file:

```bash
/tmp/cdc-dm-import-abnormal-check-state.json
```

The state file is used to distinguish:

- newly detected abnormal jobs
- still active abnormal jobs
- resolved abnormal jobs

## Schedule

Recommended schedule is every 30 minutes via the existing role runner.
