# Deployment Scheduling

Source: https://docs.ops0.com/docs/iac/deployments/scheduling

Control when your deployments run. ops0 supports three timing modes — run a deployment immediately, queue it for a specific date and time, or configure a recurring cron schedule for automated applies.

## Timing Modes

| Mode | Description | Use Case |
|------|-------------|----------|
| **Immediate** | Runs plan + apply right now | Urgent fixes, dev environments |
| **Scheduled** | Runs once at a specific date and time | Maintenance windows, coordinated releases |
| **Recurring** | Runs on a cron schedule | Automated nightly applies, periodic drift remediation |

---

## How to Schedule a Deployment

### Open Your Project
Navigate to the IaC project you want to deploy from the ops0 dashboard.

### Click Deploy
Click the **Deploy** button in the project toolbar to open the deployment dialog.

### Choose a Timing Mode
Select **Immediate**, **Scheduled**, or **Recurring** from the timing selector at the top of the dialog.

### Configure the Schedule
- **Immediate**: no additional configuration required — proceed to confirm.
- **Scheduled**: pick a date, time, and timezone using the date/time picker.
- **Recurring**: enter a cron expression and select a timezone.

### Confirm
Review the timing summary shown in the dialog, then click **Confirm Deployment** to queue the deployment.

---

## Immediate Deployments

Immediate deployments run plan and apply as soon as you confirm. Use this mode for:

- Hotfixes that need to go out right away
- Development and staging environments where timing does not matter
- First-time deployments of a new project

No additional configuration is required. The deployment enters the queue immediately and begins running within seconds.

---

## Scheduled (One-off) Deployments

A scheduled deployment runs plan and apply exactly once at the date and time you specify.

### Configuring the Date and Time

Use the date/time picker in the deployment dialog to set:

| Field | Description |
|-------|-------------|
| **Date** | Calendar date the deployment will run |
| **Time** | Hour and minute (24-hour format) |
| **Timezone** | IANA timezone (e.g. `America/New_York`, `UTC`, `Europe/London`) |

The dialog previews the scheduled time converted to your browser's local timezone so you can confirm the window is correct before saving.

### What Happens if the Plan Fails

If the plan stage produces an error at the scheduled time:

- The apply stage is skipped automatically — no resources are changed
- The failure is recorded in the deployment history with full log output
- The incident is flagged in the **Incidents** tab for review
- You can re-schedule or re-run manually once the issue is resolved

### Editing or Cancelling a Scheduled Deployment

You can change the date/time or cancel a scheduled deployment any time before it starts running. See [Cancelling a Scheduled Deployment](#cancelling-a-scheduled-deployment) below.

---

## Recurring (Cron) Deployments

Recurring deployments run on a cron schedule. ops0 evaluates the cron expression in the configured timezone and triggers plan + apply at each matching interval.

### Common Cron Expressions

| Expression | Schedule | Example Use Case |
|------------|----------|-----------------|
| `0 2 * * *` | Daily at 2:00 AM | Nightly applies to keep infrastructure in sync |
| `0 0 * * 1` | Monday at midnight | Weekly releases after weekend maintenance |
| `0 */6 * * *` | Every 6 hours | Frequent drift remediation |
| `0 0 1 * *` | 1st of month at midnight | Monthly configuration updates |
| `30 4 * * 1-5` | Weekdays at 4:30 AM | Business-day-only automation |
| `0 8,18 * * *` | 8 AM and 6 PM daily | Twice-daily environment syncs |

### Cron Expression Format

```
┌─────────── minute (0–59)
│ ┌───────── hour (0–23)
│ │ ┌─────── day of month (1–31)
│ │ │ ┌───── month (1–12)
│ │ │ │ ┌─── day of week (0–6, Sunday = 0)
│ │ │ │ │
* * * * *
```

### Timezone Selection

Always specify a timezone for recurring schedules. Leaving the schedule in UTC is fine for infrastructure that has no time-sensitive users, but for maintenance windows aligned to business hours, select the appropriate regional timezone.

**Recurring Deployments Always Run Full Checks**

Recurring deployments always run plan, policy checks, and cost estimation before apply. If the plan shows a destroy of a critical resource, or if a policy check returns a critical violation, the apply is blocked automatically and an incident is created for manual review. The next scheduled run will proceed independently — blocked runs do not retry.

---

## Approval Workflows with Scheduling

If your project has an approval policy attached, scheduling interacts with the approval workflow as follows:

| Stage | Timing |
|-------|--------|
| **Plan** | Runs at the scheduled time |
| **Apply** | Waits for an approver to review and approve |
| **Approval window** | Must be completed before the next scheduled run |

### What Happens if Approval Expires

- If a recurring deployment fires while a previous approval is still pending, the pending approval is automatically **expired** and a new plan is run for the current schedule
- This ensures approvers are always reviewing the most recent plan, not a stale one
- Expired approvals are recorded in the deployment history

**Approval Notifications**

Approvers receive a notification when a scheduled deployment is waiting for review. Configure notification channels in **Settings → Notifications** to ensure approvers are alerted promptly for time-sensitive maintenance windows.

---

## Cancelling a Scheduled Deployment

To cancel a scheduled deployment before it runs:

### Open the Project
Navigate to the IaC project from the dashboard.

### Go to Deployments
Click the **Deployments** tab to view the deployment queue and history.

### Find the Pending Deployment
Scheduled deployments show a **Scheduled** badge with the run time displayed.

### Cancel
Click the three-dot menu on the scheduled deployment row and select **Cancel Deployment**. Confirm in the dialog that appears.

Cancelling a deployment removes it from the queue entirely. For recurring schedules, cancelling a single pending run does not affect future runs — to stop a recurring schedule permanently, open the project settings and remove or disable the recurring schedule.

**Cancelling In-Progress Deployments**

If a scheduled deployment has already started running, use the **Cancel** button on the live deployment view to interrupt it. Canceling mid-apply may leave resources in a partial state — run another plan to assess current status.

---

## Deployment History for Scheduled Runs

All scheduled and recurring deployments appear in the **Deployments** tab alongside manual deployments. Each entry shows:

| Field | Description |
|-------|-------------|
| **Trigger** | `scheduled` or `recurring` (with the cron expression) |
| **Scheduled Time** | The time the deployment was configured to run |
| **Started At** | Actual start time (may differ slightly due to queue depth) |
| **Status** | `success`, `failed`, `blocked`, `cancelled`, `expired` |
| **Duration** | Total time for plan + apply |

---

## Best Practices

- Use **Scheduled** mode for production deployments during defined maintenance windows to limit the blast radius of unexpected changes.
- Use **Recurring** mode with drift remediation to automatically bring infrastructure back to the desired state without manual intervention.
- Attach an approval policy to recurring deployments in production — this lets the automation run the plan on schedule while a human reviews before apply executes.
- Keep cron intervals reasonable. Very frequent schedules (every minute or every few minutes) generate significant API activity against your cloud provider and may hit rate limits.
- Always specify an explicit timezone for recurring schedules — relying on UTC can cause confusion when your team works across multiple regions.

---

## Related

- [Deployments](https://docs.ops0.com/docs/iac/deployments): Overview of the deployment flow, plan output, and apply lifecycle

- [Approval Workflow](https://docs.ops0.com/docs/iac/deployments/approvals): Require human review before infrastructure changes are applied

- [Policies](https://docs.ops0.com/docs/iac/deployments/policies): Enforce security, compliance, and cost policies on every deployment
