# Set Up Cron Jobs

Schedule automated tasks for your agent.

## What Are Cron Jobs?

Cron jobs are scheduled tasks that run automatically:

* **Periodic checks** - Health monitoring, data sync
* **Reports** - Daily summaries, analytics
* **Maintenance** - Cleanup, backups
* **Actions** - Timed notifications, trades

## Accessing Cron Jobs

Navigate to **Cron Jobs** in the sidebar.

## Cron Job Interface

```
┌─────────────────────────────────────┐
│ Cron Jobs                      [+ ] │
├─────────────────────────────────────┤
│                                     │
│ Health Check                   Edit │
│ Every 5 minutes                Run  │
│ Last run: 2 min ago            🗑️  │
│ Status: ✅ Active                   │
│                                     │
│ Daily Report                   Edit │
│ Every day at 9:00 AM         Run  │
│ Last run: 5 hours ago          🗑️  │
│ Status: ✅ Active                   │
│                                     │
└─────────────────────────────────────┘
```

## Creating a Cron Job

### Step 1: Click "Add Cron Job"

Click **\[+]** button or **"New Cron Job"**.

### Step 2: Configure Schedule

Choose when job runs:

| Schedule     | Cron Expression | Description          |
| ------------ | --------------- | -------------------- |
| Every minute | `* * * * *`     | Every 60 seconds     |
| Every 5 min  | `*/5 * * * *`   | 5-minute intervals   |
| Every hour   | `0 * * * *`     | At top of hour       |
| Daily        | `0 9 * * *`     | Every day at 9:00 AM |
| Weekly       | `0 9 * * 1`     | Every Monday 9:00 AM |
| Custom       | `* * * * *`     | Your expression      |

### Step 3: Define Action

What the job does:

**Option A: Chat Command**

```
Action: /health-check
```

**Option B: Skill Invocation**

```
Action: skill:weather:fetch
```

**Option C: Custom Code**

```javascript
// JavaScript function
async function() {
  await agent.runHealthCheck();
  await agent.sendReport();
}
```

### Step 4: Set Options

| Option      | Description         |
| ----------- | ------------------- |
| **Name**    | Job identifier      |
| **Enabled** | Active/paused       |
| **Timeout** | Max execution time  |
| **Retry**   | On failure behavior |

### Step 5: Save

Click **"Save"** or **"Create"**.

## Cron Expression Format

```
* * * * *
│ │ │ │ │
│ │ │ │ └─── Day of week (0-7, 0=Sunday)
│ │ │ └───── Month (1-12)
│ │ └─────── Day of month (1-31)
│ └───────── Hour (0-23)
└─────────── Minute (0-59)
```

### Examples

| Expression    | Meaning           |
| ------------- | ----------------- |
| `*/5 * * * *` | Every 5 minutes   |
| `0 * * * *`   | Every hour        |
| `0 0 * * *`   | Daily at midnight |
| `0 9 * * 1`   | Monday 9 AM       |
| `0 */6 * * *` | Every 6 hours     |

## Common Use Cases

### Health Monitoring

```
Name: Health Check
Schedule: */5 * * * *
Action: Check system status
Notify: On failure
```

### Daily Reports

```
Name: Daily Summary
Schedule: 0 9 * * *
Action: Generate report
Channel: Telegram
```

### Data Sync

```
Name: Sync Database
Schedule: 0 */6 * * *
Action: skill:postgres:sync
Timeout: 10 minutes
```

### Cleanup

```
Name: Cleanup Logs
Schedule: 0 0 * * 0
Action: Delete old logs
Keep: 30 days
```

## Managing Cron Jobs

### View All Jobs

Cron Jobs section shows:

* Job name
* Schedule
* Last run time
* Status (active/paused)
* Next run time

### Edit Job

1. Find job in list
2. Click **"Edit"**
3. Modify settings
4. Save

### Run Manually

Click **"Run"** to execute immediately:

* Tests job without waiting
* Shows output in logs
* Does not affect schedule

### Pause/Resume

Toggle **Enabled** switch:

* Off: Job won't run
* On: Resumes schedule

### Delete Job

Click **🗑️** or **"Delete"**:

* Permanently removes job
* Cannot undo

## Monitoring Job Execution

### Last Run Status

| Status     | Meaning             |
| ---------- | ------------------- |
| ✅ Success  | Completed normally  |
| ❌ Failed   | Error occurred      |
| ⏱️ Timeout | Exceeded time limit |
| 🔄 Running | Currently executing |

### View Logs

Each job execution logged:

```
Logs → Cron Jobs → [Job Name]
```

Shows:

* Start/end time
* Output/errors
* Duration
* Exit code

## Troubleshooting

### Job Not Running

1. Check if enabled
2. Verify cron expression
3. Review logs for errors
4. Check agent is running

### Job Fails

1. Click job → View logs
2. Check error message
3. Test action manually in Chat
4. Fix and retry

### Timeout Issues

Increase timeout or optimize:

* Break into smaller tasks
* Use async operations
* Reduce data processed

## Best Practices

✅ **Do**:

* Name jobs descriptively
* Set reasonable timeouts
* Monitor job logs
* Test jobs manually first

❌ **Don't**:

* Create overlapping jobs
* Set intervals too short (< 1 min)
* Ignore failed jobs
* Run heavy tasks too frequently

## Advanced: Job Chaining

Jobs can trigger other jobs:

```
Job A completes → Triggers Job B
```

Use for multi-step workflows.

## Next Steps

→ [Monitor Usage](/agos/agos-cloud/agent/usage.md) to track resource consumption


---

# 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://agos.gitbook.io/agos/agos-cloud/agent/cron-jobs.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.
