Expand my Community achievements bar.

SOLVED

How to programmatically schedule the publish/unpublish of AEM content fragments?

Avatar

Level 3

We are using AEM on-prem as a headless CMS, and our users want to be able to schedule the publish/unpublish of multiple content fragments (CFs) at once by uploading a CSV file containing the paths of the CFs, the action (publish/unpublish), and the activation datetimes. The functionality should work just like what we do using the "Manage publication" wizard, but should be able to affect more CFs at the same time. The CSV file may contain more than 100 lines.

 

We have implemented a ResourceChangeListener to process the CSV, but we are not sure how to schedule the publish/unpublish of the CFs programmatically. We tried to use Replicator, but it can only affect immediately and is not able to schedule.

 

We are looking for guidance on how to achieve this functionality using AEM's APIs or any other recommended approach. Any help or insights would be greatly appreciated. Thank you in advance!

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Thanks @wei_lyu  for elaborating on the usecase.

I believe, for such kind of replication tasks, Sling Scheduled Jobs are ideal, as they guarantee execution at least once. 

1. Resource Change Listener can be implemented to handle and parse CSV (as mentioned above)

2. For every row in csv, Sling Job or a Sling Schedule Job can be created as per the schedule, where in the Listener will delegate the work to an executor, that is consumed by a Job Consumer. This guarantees execution and would not block the listener as well.
Please see following links as help docs:

 

For Replication API: please see this:

https://aem.redquark.org/2018/10/day-19-replication-api-in-action.html

For Scheduling: 

https://aem.redquark.org/2018/10/day-13-schedulers-in-aem.html

For Sling Schedule Jobs (recommended):

https://blog.developer.adobe.com/handling-sling-schedulers-in-aem-as-a-cloud-service-cb59d5e59e9

View solution in original post

5 Replies

Avatar

Employee Advisor

@wei_lyu 

Could you elaborate on your usecase:

-When do you want to schedule replication, for eg- daily, weekly etc

-On which resource, you have implemented Resource Change Listener

For Replication API: please see this:

https://aem.redquark.org/2018/10/day-19-replication-api-in-action.html

For Scheduling: 

https://aem.redquark.org/2018/10/day-13-schedulers-in-aem.html

For Sling Schedule Jobs (recommended):

https://blog.developer.adobe.com/handling-sling-schedulers-in-aem-as-a-cloud-service-cb59d5e59e9

 

Avatar

Level 3

@krati_garg , thank you for your response!

To answer your questions:

  • The scheduling of replication will be based on the activation date specified in the CSV file. Users will be able to set this date to any time in the future, so it can vary from CF to CF.
  • We have implemented the ResourceChangeListener on the folder where users will upload the CSV files. When a new CSV file is uploaded, the listener should parse each line in the CSV and schedule the publish/unpublish for each CF.

To provide more context, the CSV file will look like this:

path,action,activation_date

/content/dam/mysite/aaa,PUBLISH,2023-10-10T13:50:00+09:00

/content/dam/mysite/bbb,UNPUBLISH,2023-10-11T15:30:00+09:00

Avatar

Correct answer by
Employee Advisor

Thanks @wei_lyu  for elaborating on the usecase.

I believe, for such kind of replication tasks, Sling Scheduled Jobs are ideal, as they guarantee execution at least once. 

1. Resource Change Listener can be implemented to handle and parse CSV (as mentioned above)

2. For every row in csv, Sling Job or a Sling Schedule Job can be created as per the schedule, where in the Listener will delegate the work to an executor, that is consumed by a Job Consumer. This guarantees execution and would not block the listener as well.
Please see following links as help docs:

 

For Replication API: please see this:

https://aem.redquark.org/2018/10/day-19-replication-api-in-action.html

For Scheduling: 

https://aem.redquark.org/2018/10/day-13-schedulers-in-aem.html

For Sling Schedule Jobs (recommended):

https://blog.developer.adobe.com/handling-sling-schedulers-in-aem-as-a-cloud-service-cb59d5e59e9

Avatar

Community Advisor

@wei_lyu Did you get the chance to have a look at this solution using custom workflow and creating a workflow instance for each CFs. 

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/scheduling-activation-on-c... 

Avatar

Community Advisor

Hello @wei_lyu 

 

There are few options that you could try.

 

1. Using the onTime/offTime feature: Useful to decide availability of the pages. Specifically, if a lot of pages are to be made available during peak traffic

The following link explains the difference between onTime and publish

https://www.linkedin.com/pulse/onoff-time-aem-pages-veena-vikraman/

 

2. Use the OOTB "Schedule Page/Asset Activation" workflow. So, you could trigger the workflow, with required params, which would publish content when time is reached. It is the "manage publication" way.

 

3. You create your own custom workflow, add the step for "Absolute Time advancer". Once reached, workflow moves to next step and publishes the content.

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/schedule-activation-throug...

 

 


Aanchal Sikka