_job_logs collection with automatic retention management.
Quick Start
Register a job using the globalGetManager() singleton:
Cron Expression Syntax
pb-ext uses standard cron expression syntax:Common Patterns
| Expression | Description |
|---|---|
*/5 * * * * | Every 5 minutes |
0 2 * * * | Daily at 2 AM |
0 0 * * 0 | Every Sunday at midnight |
0 3 * * * | Daily at 3 AM |
0 0 1 * * | First day of every month at midnight |
30 14 * * 1-5 | Weekdays at 2:30 PM |
ExecutionLogger Methods
TheExecutionLogger provides structured logging methods for job output:
Basic Logging
Status Indicators
Completion Methods
Statistics Reporting
Real-World Examples
Example 1: Daily Cleanup Job
Fromcmd/server/jobs.go:55:
Example 2: Weekly Statistics Report
Fromcmd/server/jobs.go:115:
Example 3: Simple Periodic Task
Fromcmd/server/jobs.go:35:
Job Management API
All endpoints require superuser authentication.List Jobs
Trigger Job Manually
Remove Job
Get Scheduler Status
Update Timezone
Get Execution Logs
System Jobs
pb-ext automatically registers internal maintenance jobs. These appear in the dashboard with a “System” badge.__pbExtLogClean__
From core/jobs/manager.go:287:
- Schedule:
0 0 * * *(daily at midnight) - Purpose: Purges
_job_logsrecords older than 72 hours - Retention: 72 hours
__pbExtAnalyticsClean__
From core/jobs/manager.go:353:
- Schedule:
0 3 * * *(daily at 3 AM) - Purpose: Deletes
_analyticsrows older than 90 days - Retention: 90 days
Job Execution Storage
Collection Schema
Job logs are stored in the_job_logs system collection:
| Field | Type | Description |
|---|---|---|
job_id | text | Job identifier |
job_name | text | Display name |
description | text | Job description |
expression | text | Cron expression |
start_time | datetime | Execution start |
end_time | datetime | Execution end |
duration | number | Duration in milliseconds |
status | text | started, completed, failed, timeout |
output | text | Captured log output |
error | text | Error message if failed |
trigger_type | text | scheduled or manual |
trigger_by | text | User ID if manual |
Automatic Cleanup
Fromcore/jobs/logger.go:343:
- Logs older than 72 hours are automatically deleted
- Cleanup runs during flush operations
- Orphaned jobs (stuck in “started” status) are marked as “timeout” on startup
Buffer and Flush
Fromcore/jobs/logger.go:14:
- Logs are buffered in memory
- Flush interval: 30 seconds
- Batch size: 100 records
- Manual flush via
ForceFlush()
Error Handling
Jobs that panic are automatically recovered:core/jobs/manager.go:417:
Best Practices
- Use descriptive job IDs and names for easy identification in logs
- Always call
el.Start()andel.Complete()orel.Fail()to properly track execution - Use
el.Statistics()for structured data instead of multiple Info calls - Handle errors gracefully with
el.Error()andel.Fail() - Test jobs manually using the
/api/cron/jobs/{id}/runendpoint - Keep job execution time reasonable (under 1 minute preferred)
- Use Progress() for long-running operations to show intermediate status
- Validate collection existence before performing database operations
Dashboard Integration
View job status and logs in the pb-ext dashboard at/_/_:
- Recent job executions with status indicators
- Success/failure rates per job
- Average execution time
- Manual job triggering
- Live execution logs
Advanced: Manual Execution
Fromcore/jobs/manager.go:86:
Related
- Monitoring - System metrics tracking
- Logging - Application logging system
- Dashboard - Management UI