# Cron Job

In ClawCloud Run, a Cron Job is used to create tasks that run at regular intervals. Unlike regular applications, Cron Jobs automatically trigger tasks based on a predefined schedule, making them ideal for maintenance routines or data processing scenarios.

<figure><img src="/files/2D0MMU4k5WbbHJxFO5IX" alt=""><figcaption><p>Cron Job Configuration Entry</p></figcaption></figure>

### Typical Use Cases

1. **Data Backup and Synchronization:**\
   Execute daily backups at midnight.
2. **Scheduled Notifications:**\
   Send daily summary emails at a fixed time.
3. **Batch Processing:**\
   Run data processing tasks every hour.
4. **Scheduled Scaling:**\
   Perform scaling operations at set times.

Below is an example of how to configure a scheduled scaling task in ClawCloud Run.

### Scheduled Scaling Configuration

For applications that experience predictable traffic fluctuations (such as during e-commerce promotions, gaming events, or office systems), scheduled scaling allows for precise resource management.

#### Example Use Cases

* **E-commerce Promotions:**\
  Scale up to 10 instances from 09:00 to 23:00 during peak promotional hours and scale down to 3 instances during off-peak hours.
* **Office Systems:**\
  Maintain 5 instances on weekdays from 08:00 to 20:00 and reduce to 1 instance during non-business hours.
* **Gaming Events:**\
  Scale up to 15 instances on weekends, while keeping 5 instances on weekdays.

#### Configuration Steps

**Creating a Scheduled Task**

1. Open the Cron Job section in the ClawCloud Run console.
2. Click the **Add Cron Job** button to create a new task.

**Configuring Basic Parameters**

* **Task Name:**\
  Provide an easily recognizable name, such as "nginx-scale".
* **Task Type:**\
  Choose the task type:
  * `Scale APP Launchpad`: Scale application instances.
  * `Access URL`: Access a specified URL.
  * `Execute Command`: Run a custom command.
* **Cron Expression:**\
  Set the execution time using a Cron expression (based on Singapore Time).
* **App Name:**\
  When selecting `Scale APP Launchpad`, specify the target application for scaling.
* **Replica Count:**\
  When using `Scale APP Launchpad`, specify the desired number of instances.

**Example Configuration:**

```bash
Task Name: nginx-scale
Schedule: 0 8 * * *  # Executes daily at 8:00 AM Singapore Time
Replica Count: 5
```

This configuration means:

* **Cron Expression:** `0 8 * * *` — The task runs daily at 8:00 AM Singapore Time.
* **Replica Count:** The application instance count will be adjusted to 5.

<figure><img src="/files/0Cnet587hEvlAx8zFZBg" alt=""><figcaption><p>Cron Job Configuration Interface</p></figcaption></figure>

### Scheduled Power On/Off

For applications that need to be periodically paused (such as development environments or scheduled data processing tasks), you can combine two Cron Jobs to achieve automatic shutdown and startup.

#### Typical Use Cases

* **Development Environment:**\
  Run only during weekdays from 09:00 to 18:00 and shut down outside these hours.
* **Data Processing Tasks:**\
  Start compute tasks between 02:00 and 04:00 daily.
* **Demo Systems:**\
  Operate only during customer viewing periods.

**Creating a Shutdown Task**

<figure><img src="/files/KMr1XSyAriSv9OvR0WVy" alt=""><figcaption><p>Cron Job Shutdown Configuratio</p></figcaption></figure>

1. Click the **Add Cron Job** button to create the first task.
2. Configure the following parameters:

```bash
Task Name: dev-env-stop
Task Type: Scaling Applications at Launchpad
Cron Expression: 0 0 * * *  # Executes daily at 00:00 Singapore Time
App Name: your-app-name
Replica Count: 0
```

3. Click **Deploy** to save the configuration.

**Creating a Startup Task**

<figure><img src="/files/FRrVUHkGiiG8wjhk5dms" alt=""><figcaption><p>Cron Job Startup Configuration</p></figcaption></figure>

1. Click the **Add Cron Job** button again to create a second task.
2. Configure the following parameters:

```bash
Task Name: dev-env-start
Task Type: Scaling Applications at Launchpad
Cron Expression: 0 9 * * *  # Executes daily at 09:00 Singapore Time
App Name: your-app-name
Replica Count: 3  # Restore to the normal number of instances
```

3. Click **Deploy** to complete the configuration.

With this setup, the system will automatically:

* Shut down instances every day at midnight, saving resources.
* Restart the service every morning at 9:00, ensuring availability during working hours.
* Operate continuously throughout the year without manual intervention.


---

# 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.run.claw.cloud/clawcloud-run/guide/advanced/cron-job.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.
