adobe / adobe/aem-project-archetype

[Core] Replace legacy OSGi Scheduler (Runnable) with modern Sling Job Consumer

Open
#1,330 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
596
Forks
431
Avg merge
10d 6h
Merged PRs (30d)
1

Description

The current AEM Project Archetype includes a sample scheduled task (`SimpleScheduledTask.java`) that implements the `java.lang.Runnable` interface for the OSGi Scheduler. While functional for basic tasks, this approach is considered a "legacy" pattern in modern AEM development, especially for AEM as a Cloud Service and distributed environments.

The AEM community and Adobe best practices now strongly recommend using Sling Jobs (`JobConsumer`) for background processing.

The existing `Runnable` implementation has several limitations in a modern AEM architecture:
1. Guaranteed Execution: OSGi Schedulers are in-memory. If an instance restarts during execution, the task is lost. Sling Jobs are JCR-persisted, ensuring they resume after a restart.
2. Distributed Safety: In a clustered environment (multiple Authors/Publishers), a simple OSGi Scheduler can trigger on all nodes simultaneously, leading to race conditions or VersionConflicts. Sling Jobs are "topology-aware" and ensure a job runs only on one designated node (usually the Leader).
3. Observability: Sling Jobs can be monitored, stopped, and restarted via the Sling Jobs console (`/system/console/jobs`), providing much better visibility than hidden background threads.

Proposed Changes
1. Deprecate/Replace: Remove `SimpleScheduledTask.java` or update it to follow the Sling Job pattern.
2. Introduce `JobConsumer`: Add a new sample `SimpleJobConsumer.java` implementing the `JobConsumer` interface.
3. Scheduling Logic: Provide an example of how to trigger this job using the `JobManager` or a `ScheduledJob`.

Contributor guide

Open the contributing guide

Research direction

Start by locating the archetype's SimpleScheduledTask.java and reviewing how the sample is registered and scheduled. Compare the available Sling JobConsumer and JobManager entry points, then define the example's trigger and verify that the legacy Runnable sample is removed or replaced with a working persisted job pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.