Jobs (CronJob)
Jobs are tasks that run periodically on a specified schedule. Use them for batch processing, data aggregation, periodic cleanup, and more.
What is a Job?
- A program that runs automatically at specified times
- Uses code from the same repository as your applications
- Can connect to databases
- Execution history and logs are available
Creating a Job
- In the project detail screen, click "New Job"
- Enter basic settings:
| Field | Description | Example |
|---|---|---|
| Job Name | Identifier name | daily-report |
| Language | Programming language to use | Node.js / Go / Python |
- Select deploy source:
| Field | Description | Example |
|---|---|---|
| Repository | Source code repository | myorg/my-jobs |
| Branch | Branch to use | main |
| Directory | Subdirectory (for monorepos) | jobs/report |
- Execution settings:
| Field | Description | Example |
|---|---|---|
| Command | Command to execute | node report.js |
| Setup Command | Install dependencies | npm install |
| Pre Command | Pre-processing command | npm run build |
- Schedule settings:
| Field | Description |
|---|---|
| Schedule Type | Preset or custom |
| Cron Expression | Only for custom type |
- Optional settings:
- Spec (resource size)
- Environment variables
-
Database connection
-
Click "Create"
Schedule Types
Presets
| Type | Timing | Cron Expression |
|---|---|---|
| Hourly | Every hour at :00 | 0 * * * * |
| Daily (Midnight) | Daily at 0:00 | 0 0 * * * |
| Daily (3 AM) | Daily at 3:00 | 0 3 * * * |
| Daily (9 AM) | Daily at 9:00 | 0 9 * * * |
| Weekly (Sunday) | Sundays at 0:00 | 0 0 * * 0 |
| Weekly (Monday) | Mondays at 0:00 | 0 0 * * 1 |
| Monthly (1st) | 1st of month at 0:00 | 0 0 1 * * |
Custom (Cron Expression)
Specify using standard cron expression format.
┌───────── minute (0 - 59)
│ ┌───────── hour (0 - 23)
│ │ ┌───────── day of month (1 - 31)
│ │ │ ┌───────── month (1 - 12)
│ │ │ │ ┌───────── day of week (0 - 6, 0 = Sunday)
│ │ │ │ │
* * * * *
Examples:
| Cron Expression | Meaning |
|---|---|
*/15 * * * * |
Every 15 minutes |
0 */2 * * * |
Every 2 hours |
30 8 * * 1-5 |
Weekdays at 8:30 |
0 0 15 * * |
15th of each month at 0:00 |
Note: Timezone is UTC. Japan Standard Time (JST) is UTC+9.
Running a Job Immediately
To run a job now without waiting for the schedule:
- Open the job detail screen
- Click the "Run Now" button
- Click "Execute" in the confirmation dialog
Viewing Execution History
- Click the "Execution History" tab in the job detail screen
- View information for each execution:
- Start time
- End time
- Duration
- Status (success / failure)
Viewing Execution Logs
- Select an execution from the history
- View stdout / stderr output in the log screen
Editing a Job
- Click the "Settings" tab in the job detail screen
- Editable fields:
- Schedule
- Command
- Spec
- Environment variables
- Database connection
- Click "Save"
Pausing a Job
To temporarily stop scheduled execution:
- Click "Pause" in the job detail screen
- The job will no longer run on schedule
- Click "Resume" to restart scheduled execution
Deleting a Job
- Click the "Settings" tab in the job detail screen
- Click "Delete Job"
- Enter the job name in the confirmation dialog
- Click "Delete"
⚠️ Warning: Execution history will also be deleted. This action cannot be undone.
Use Case Examples
Daily Report Generation
// report.js
const { Pool } = require('pg');
async function generateReport() {
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const result = await pool.query(`
SELECT DATE(created_at) as date, COUNT(*) as count
FROM orders
WHERE created_at >= NOW() - INTERVAL '1 day'
GROUP BY DATE(created_at)
`);
console.log('Daily Report:', result.rows);
// Send email or Slack notification
}
generateReport().catch(console.error);
Data Cleanup
# cleanup.py
import os
import psycopg2
from datetime import datetime, timedelta
conn = psycopg2.connect(os.environ['DATABASE_URL'])
cursor = conn.cursor()
# Delete temporary data older than 30 days
cursor.execute("""
DELETE FROM temp_data
WHERE created_at < NOW() - INTERVAL '30 days'
""")
conn.commit()
print(f"Deleted {cursor.rowcount} old records")