Scheduled jobs and Content events
Outline
- Automation vs Reactivity: Scheduled Jobs enable time-based background automation, while Content Events provide an event-driven mechanism that reacts instantly to content lifecycle changes.
- Key developer capability: Scheduled jobs are typically used for background data synchronization, search re-indexing, reporting, and maintenance operations that should not run during a web request.
-
Event-driven architecture:
The
IContentEventsservice acts as a central hub for subscribing to events such asSavingContent,PublishedContent, andDeletedContent. - Cloud environment considerations: In Optimizely PaaS environments, job execution depends on active application instances and correct scheduler configuration to avoid duplicate executions across multiple servers.
-
Integration pattern:
When implementing
IContentProvidersolutions, scheduled jobs are typically used to refresh external data, while content events notify external systems about changes occurring within the CMS.
Introduction
In Optimizely CMS 12, enterprise content platforms often require automation and integration beyond manual editorial workflows. Two essential mechanisms that support this capability are Scheduled Jobs and Content Events.
Scheduled Jobs allow developers to implement background automation that runs periodically or on demand. These jobs execute outside the standard request pipeline and are ideal for tasks such as synchronizing external data sources, generating reports, refreshing search indexes, or performing maintenance activities.
Content Events, by contrast, enable an event-driven programming model. Developers can subscribe to content lifecycle events and execute custom logic whenever content is created, updated, published, moved, or deleted.
When building integrations with external systems—especially when implementing custom IContentProvider solutions—these mechanisms become essential for maintaining data consistency, cache integrity, and synchronization between Optimizely and external services.
Section 1: Scheduled Jobs
Scheduled Jobs are automated background processes that run at predefined intervals or can be triggered manually through the Optimizely administration interface.
They are designed for tasks that do not require immediate user interaction and can safely execute asynchronously without blocking editorial workflows.
Overview of Scheduled Jobs
-
Execution Context:
Scheduled jobs typically execute under an anonymous security context. If operations require elevated permissions (for example updating content through
IContentRepository), the job must explicitly set the user context. - Server Dependency: At least one application instance must be running for scheduled jobs to execute. In PaaS environments (such as Azure Web Apps), configurations like Always On ensure that the scheduler remains active even when the site receives no traffic.
- Management and Monitoring: Jobs are configured and monitored from the Optimizely CMS Admin interface, where administrators can manually trigger execution and view job logs.
- Built-in Maintenance Jobs: A standard Optimizely installation includes several predefined jobs for system maintenance tasks such as clearing the trash bin, publishing scheduled content, and maintaining internal indexes.
Common Use Cases
-
External Data Synchronization
Scheduled jobs can periodically fetch data from external APIs and update CMS caches or data structures used by
IContentProviderimplementations. - Content Lifecycle Automation Jobs can automatically archive outdated content, move expired pages, or apply business rules to content structures.
-
Search Index Maintenance
External content exposed via
IContentProvidermay require scheduled re-indexing to ensure search platforms (e.g., Optimizely Search & Navigation or Elasticsearch) reflect the latest data. - Analytics and Reporting Jobs can generate aggregated reports from content data and send them to analytics platforms or internal reporting systems.
Implementing a Scheduled Job
Custom scheduled jobs are created by implementing a class that inherits from EPiServer.Scheduler.ScheduledJobBase. The job must be decorated with ScheduledPlugInAttribute so it can be registered and managed within the CMS administration interface.
Key Considerations for Scheduled Jobs
-
User Context Management
In CMS 12,
PrincipalInfo.CurrentPrincipalis read-only. Developers must useIPrincipalAccessorto manipulate the current user context when elevated permissions are required. -
Multi-Server Environments
When running Optimizely in scaled environments, scheduler configuration must ensure that only one instance executes scheduled jobs. This can be controlled through
EpiServer:Cms:Schedulerconfiguration. -
Restartable Jobs
Setting
Restartable = trueallows jobs to resume if the application restarts unexpectedly. This requires idempotent logic so partially executed tasks can safely continue. - Performance Management Long-running operations should be optimized through batching, streaming, or background processing to prevent resource contention.
Section 2: Content Events
Content Events provide an event-driven mechanism for responding to lifecycle changes affecting IContent objects.
Through the IContentEvents service, developers can subscribe to events triggered when content is created, updated, published, moved, or deleted. These hooks allow custom logic to run before or after core CMS operations occur.
Overview of Content Events
-
Event-Driven Architecture
The
IContentEventsinterface acts as a centralized event dispatcher for content lifecycle events. - Synchronous Execution Most event handlers execute synchronously within the request pipeline. Heavy operations should therefore be delegated to background services.
- Global Scope Event subscriptions apply across the entire CMS instance, making them ideal for cross-cutting integration logic.
Subscribing to Content Events
Conclusion
Scheduled Jobs and Content Events form two complementary automation mechanisms within Optimizely CMS 12.
Scheduled Jobs provide time-based automation for background processing tasks such as synchronization, indexing, and reporting. Content Events enable reactive integration patterns by triggering logic in response to content lifecycle changes.
When used together—particularly in architectures involving IContentProvider integrations—these mechanisms enable developers to build scalable, reliable content systems that remain synchronized with external platforms while maintaining high performance within the CMS environment.
