---
name: import-dm-failed-job-analyze
description: Stable Import/DM failed job analysis. Uses the cronjob wrapper to query failed jobs, call OpenClaw through the running Gateway, write Feishu Wiki, and send fixed Feishu cards.
---

# Import DM Failed Job Analyze Skill

Use this skill when you want the same logic as the scheduled job, but triggered manually.

## What It Does

1. Fetches failed Import/DM jobs for yesterday or a specified date
2. Builds deterministic input for analysis
3. Calls `openclaw agent` through the running Gateway
4. Writes the full report to Feishu Wiki
5. Sends a fixed Feishu interactive card

The skill entrypoint delegates to the cronjob implementation, so manual runs and scheduled runs stay consistent.

## Runtime Model

This skill does **not** ask the current chat session to improvise the report.
It calls the stable wrapper at `cronjobs/team-workflow/import-dm-failed-job-analyze/main.py`.

That wrapper keeps:

- Scheduling stable
- Output format stable
- Feishu delivery stable

OpenClaw is only used for the analysis step.

## Gateway Requirement

The OpenClaw Gateway must already be running.

Check it with:

```bash
openclaw gateway health --json
```

## Usage

As a skill:

```text
/import-dm-failed-job-analyze
```

Specific date:

```text
/import-dm-failed-job-analyze 20260320
```

As a Python command:

```bash
python3 skills/team-workflow/import-dm-failed-job-analyze/run.py
python3 skills/team-workflow/import-dm-failed-job-analyze/run.py 20260320
```

Personal-target test:

```bash
ONCALL_NOTIFY_CHAT_ID="user:ou_xxx" python3 skills/team-workflow/import-dm-failed-job-analyze/run.py 20260320
```

## Notification Targets

`ONCALL_NOTIFY_CHAT_ID` supports multiple targets separated by comma, semicolon, or whitespace.

Supported forms:

- `chat:oc_xxx`
- `oc_xxx`
- `user:ou_xxx`
- `ou_xxx`

Example:

```bash
export ONCALL_NOTIFY_CHAT_ID="user:ou_xxx,chat:oc_xxx"
```

## Environment Variables

| Variable | Description |
|----------|-------------|
| `CRONJOB_TEAM_WORKFLOW_APP_ID` | Feishu app id |
| `CRONJOB_TEAM_WORKFLOW_APP_SECRET` | Feishu app secret |
| `FAILED_JOBS_APP_TOKEN` | Failed-jobs bitable app token |
| `FAILED_JOBS_TABLE_ID` | Failed-jobs bitable table id |
| `ONCALL_NOTIFY_CHAT_ID` | One or more Feishu targets |
| `OPENCLAW_BIN` | Optional OpenClaw CLI path. If unset, auto-detect from `PATH` and common install locations |
| `OPENCLAW_ANALYSIS_TIMEOUT` | Analysis timeout in seconds |
| `SKIP_SEND_NOTIFICATION` | Skip Feishu notification |
| `SKIP_OPENCLAW_ANALYSIS` | Skip OpenClaw analysis |
| `AI_CONFIG_REPO` | Repo root override |

## Output

1. Feishu Wiki page with:
   - Summary
   - Import failed jobs
   - DM failed jobs
   - OpenClaw analysis section
2. Deterministic JSON stdout summary
3. Feishu interactive card

## Recommended Cron Form

```bash
0 3 * * * cd /home/openclaw/github/data-service-infra-ai-configurations && python3 cronjobs/team-workflow/import-dm-failed-job-analyze/main.py >> /tmp/import-dm-failed-job-analyze.log 2>&1
```

## Troubleshooting

If analysis fails but Wiki/card still succeed, the wrapper will fall back to a deterministic summary and mark:

- `analysis_status: failed`
- `risk_level: medium`

Validate the agent path directly with:

```bash
openclaw agent --agent main --json --thinking minimal --timeout 60 --message 'Reply with exactly the JSON string {"ok":true} and nothing else.'
```
