Cron Service
Cron Service is a service designed to manage, execute, and monitor scheduled tasks (cron jobs) in the Platon platform.
It dynamically loads schedules from the database, validates them, executes them, and monitors their status.
This service runs only under the cron Spring profile.
Overview
Cron Service provides the following capabilities:
- Dynamically load cron tasks from the database
- Automatically detect new, updated, or deleted tasks
- Support multiple execution types (SQL, HTTP request, JS Eval, etc.)
- Validate and normalize cron expressions
- Centralized logging via NATS
- Manual schedule refresh capability
Architecture Components
The main logic of Cron Service resides in the service layer.
Key Responsibilities:
- Read cron schedules from the database
- Register new or updated schedules
- Remove deleted or inactive schedules
- Validate cron expressions and job configurations
- Execute tasks via
TaskScheduler
Schedule Lifecycle
- Cron Service loads schedules from the database
- Each schedule is validated
- Valid schedules are added to the scheduler
- Invalid schedules are canceled and logged
- Updated or deleted schedules are dynamically refreshed
Cron Schedule Registration Flow
text
Database → Validation → Scheduler → Execution → LoggingCron Schedule Format
text
* * * * * every minute
*/30 * * * * every 30 minutes
30 16 * * * daily at 16:30
30 16 2 * * monthly on the 2nd day at 16:30
30 16 2 11 * yearly on November 2nd at 16:30
30 16 * 11 Mon-Fri yearly in November from Monday to Friday at 16:30