AEM Assets Post-Processing Workflows — A Savior to Resource Change Hell problem

Saravana Prakash
3 min readJan 27, 2024

--

Photo by Yaopey Yong on Unsplash

I had a problem. Solved with ResourceChangeListener. Now I have 2 problems.

Prelude

Here is my requirement. I am working on AEM Cloud environment. After the content author uploads assets to DAM, based on certain rules, I need to populate metadata onto the asset. But there is a catch! Sometimes, (actually many times) assets fail to complete processing. They get stuck while uploading into Dynamic media. So, assets wait under “Processing” state for a while before marked as “New”.

Assets take few seconds from this

to this

My main requirement is, I shouldn’t update metadata when assets fails processing. Dont update metadata when this happens

How to implement this?

What is the Resource-Change-Hell?

This is not a real jargon. I am coining after the problem I faced.

A typical AEM developer will try to solve above requirement using either.

  1. Sling Resource Change Listeners
  2. Workflow launchers

Definite no to Jcr listeners or sling events. They are dead already.

Now if you tried listeners or launchers, you run into the resource-change hell. The listeners/launchers will FIRE MULTIPLE TIMES during asset processing. I started with one problem and now have to deal with 2 problems. To fix, I added checks. If metadata is already updated, dont update second time. and insert only if empty. Inserts worked, then had to deal for property updates. After bandaging, biggest problem was. I had to undo when Processing Failed. To work around, again tried to listen to `dmProcessingStatus` property and update metadata accordingly. This is a Hell.

What is Post-processing workflows ?

Auto-start workflows concept has been around in AEM but not very handy. Nov 2023 Adobe launched enhancements and is now, very easy to use.

These workflows fire ONLY AFTER ASSET PROCESSING IS COMPLETE.

How to implement?

We start with creating a regular workflow modal like this

The last process step is the key. Post-processing workflows MUST include the “DAM Update Asset Workflow Completed” step. Else we cant auto-start this workflow.

After creating the modal, we add the Auto-start workflows from the targetted DAM folder. When open the DAM folder properties, from the Asset Processing tab; the new workflow modal shows; add the modal and give a title; save the properties.

All done, now when authors upload asset, this workflow is fired ONLY ONCE, after all processing is complete. This guarantees no duplicate executions happen. We can test this by adding an asset and checking the workflow queue. A new workitem is created and completes.

Conclusion:

Auto-start workflows is suitable only to execute steps post-asset-processing. Outside DAM assets, this is not useful. And it makes sense, since non-asset content tree doesnt get updated multiple times. Only DAM folder are updated multiple times. This adobe solution is very useful for this usecase.

Happy Coding!

--

--

Saravana Prakash

AEM Fullstack Enthusiast. Working on AEMCaaS, Adobe EDS, Adobe IO and other Adobe Marketing Cloud tools