Class ChenileScheduler
java.lang.Object
org.chenile.scheduler.ChenileScheduler
- All Implemented Interfaces:
InitializingBean
Chenile's scheduler. It holds this node's
SchedulerDefinitions, schedules them in Quartz
and, when one fires, raises its event through TriggerService.
Definitions come from chenile.scheduler.json.package at startup, and from code (or
chenile-scheduler-db) through schedule(SchedulerDefinition). Quartz is Spring Boot's: in memory by default,
clustered through spring.quartz.*. In a cluster every node must know every definition, so
code that schedules must run on every node, for example at startup.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringScheduler-context key for this node's instance: kept in memory, never persisted.static final StringJob data: the definition id.private final Map<String, SchedulerDefinition> static final Stringprivate final Resource[]private static final org.slf4j.Loggerprivate Function<String, SchedulerDefinition> private final tools.jackson.databind.ObjectMapperprivate final org.quartz.Schedulerstatic final StringJob data: the definition's tenant, when it has one.private final TenantScopeprivate final TriggerService -
Constructor Summary
ConstructorsConstructorDescriptionChenileScheduler(org.quartz.Scheduler quartz, TriggerService triggers, Resource[] jsonResources, TenantScope tenantScope) -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters this node with Quartz and schedules the JSON definitions.definition(String id) voidRaises the definition's event.private voidfireAsTenant(String id, Date scheduledFireTime, Date fireTime) private voidvoidWhere a fire looks first for its definition, before this node's own. chenile-scheduler-db passes a database lookup here: in a cluster, a schedule saved on one node can fire on another, and the database holds the current version.private SchedulerDefinitionvoidschedule(SchedulerDefinition definition) Adds or replaces a definition and (re)schedules it.voidunschedule(String id) Forgets the definition and removes it from Quartz.voidvalidate(SchedulerDefinition definition) Checks a definition without scheduling it: id, eventId, cron expression, timezone andx-headers.
-
Field Details
-
CONTEXT_KEY
Scheduler-context key for this node's instance: kept in memory, never persisted.- See Also:
-
DEFINITION_ID
-
TENANT
Job data: the definition's tenant, when it has one. With a database per tenant, the node that fires a stored schedule needs it to read the definition from that tenant's database.- See Also:
-
GROUP
- See Also:
-
logger
private static final org.slf4j.Logger logger -
quartz
private final org.quartz.Scheduler quartz -
triggers
-
jsonResources
-
tenantScope
-
mapper
private final tools.jackson.databind.ObjectMapper mapper -
definitions
-
lookup
-
-
Constructor Details
-
ChenileScheduler
public ChenileScheduler(org.quartz.Scheduler quartz, TriggerService triggers, Resource[] jsonResources, TenantScope tenantScope)
-
-
Method Details
-
afterPropertiesSet
Registers this node with Quartz and schedules the JSON definitions.- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception
-
schedule
Adds or replaces a definition and (re)schedules it. A disabled definition is kept but removed from Quartz. Replace-if-exists makes this safe when several nodes start together. -
unschedule
Forgets the definition and removes it from Quartz. -
definition
-
definitions
-
lookUpDefinitionsWith
Where a fire looks first for its definition, before this node's own. chenile-scheduler-db passes a database lookup here: in a cluster, a schedule saved on one node can fire on another, and the database holds the current version. -
fire
Raises the definition's event. Called bySchedulerJobon the node Quartz picked. The whole fire runs as the schedule's tenant (seeTenantScope), so the database lookup and the trigger reach that tenant's database even though the Quartz thread has no tenant. -
fireAsTenant
-
read
-
validate
Checks a definition without scheduling it: id, eventId, cron expression, timezone andx-headers. Throws aBadRequestException(E571). An empty timezone becomes UTC. -
invalid
-
CHENILE