Guide · updated

Sling Jobs vs schedulers vs listeners on AEM as a Cloud Service

Background work is where many AEM 6.5 code bases quietly assume things that Cloud Service does not promise. Adobe's development guidelines are blunt: code running as a background task must assume the instance it runs on can be brought down at any time. That one sentence decides how you schedule work, react to content changes and store files.

The rules, in Adobe's words

TopicAdobe's guidance for Cloud Service
SchedulingDo not use the Sling Commons Scheduler for scheduling, because execution cannot be guaranteed.
Long-running workUse Sling Jobs, which have an at-least-once guarantee, and avoid restarting long jobs from scratch.
Event handlingAsynchronous handling of JCR events and Sling resource events cannot be guaranteed to run locally; use these mechanisms with care.
Local filesDo not use the instance's file system; the disk is ephemeral and disposed of when instances are recycled.
Outgoing HTTPSet timeouts. Adobe suggests 1 s to connect and 5 s to read; code without timeouts gets platform limits of 10 s and 60 s.

Replacing a scheduler with a scheduled Sling Job

  1. Pick a job topic, for example com/acme/jobs/sitemap.
  2. On component activation, register the schedule with the JobManager: createJob(topic).schedule().cron(expression).add(). Check first whether the schedule already exists so redeployments do not add duplicates.
  3. Move the work into a JobConsumer for that topic. Because jobs run at least once, make the consumer idempotent: running it twice must not create two copies of anything.
  4. Split long work into steps that record progress, so a restarted job continues instead of starting over.

Replacing JCR observation listeners

Many 6.5 projects use javax.jcr.observation.EventListener to react to content changes. On Cloud Service the usual replacement is a Sling ResourceChangeListener registered for specific paths and change types. If the reaction does work that must not be lost (sending to a search index, generating renditions, calling another system), let the listener only enqueue a Sling Job and do the work in a JobConsumer, which gives you the at-least-once guarantee the listener alone does not.

Files and temporary data

  • Small temporary files inside one request are fine; nothing that must survive the request should touch disk.
  • Persist results in the repository or an external store; send large artefacts to object storage you control.

How we migrate these patterns

Our scanner finds Sling Commons Scheduler use, JCR observation listeners and local file system access. Schedulers and listeners are rewritten by our AI refactoring on our own servers, checked automatically, and approved by an engineer. The engineer also confirms the idempotency of each job consumer, because that is a design decision rather than a code change.

Check your own site or code for free

This guide covers the AEM code and platform side of a move. The pages are a separate job, and that is the job the four steps do.

Surge Migrate moves a website from any CMS to any CMS in four steps: Scan, Convert, Verify, Install. Pages are converted automatically, and you check the result before you install anything.

Questions

Can we keep using the Sling Commons Scheduler on Cloud Service?

Adobe's guidelines say not to use it for scheduling because execution cannot be guaranteed. Use scheduled Sling Jobs, which run at least once.

Are JCR observation listeners removed?

They are not on Adobe's removed-API list, but Adobe notes that asynchronous handling of JCR and Sling resource events cannot be guaranteed to run locally. For work that must happen, enqueue a Sling Job.

Sources

Any CMS to any CMS

Scan, Convert, Verify, Install

This guide covers one part of a move. Surge Migrate moves the pages, from any CMS to any CMS. Converted automatically. Checked before you install.

  1. 1

    Scan

    Names the system behind your site, counts pages and templates, lists the blocks to build and the work no tool does, and gives an effort range with its working.

    Scan a site →
  2. 2

    Convert

    Each page becomes an Edge Delivery document, an AEM Core Component page and import files for 7 other systems. 10 pages free; 500 or 2,000 pages in one paid run.

    Convert your pages →
  3. 3

    Verify

    A download is offered only when its own format check passes. The report lists every field not found and every component kept as plain content. Compare old and new pages side by side.

    Parity check →
  4. 4

    Install

    You import with the target system's own tool, on your own environment. Each download's README gives the command. Your system changes only when you run it.

    How each import was tested →

No account needed. Public pages only, robots.txt obeyed. Nothing is installed in your system by these tools.