In previous versions of Adobe CQ5/AEM in order to purge old completed workflows, you needed to either write a custom job or install an additional package provided by DayCare. Now in AEM 5.6.1, this functionality comes out of the box with the product.
Why Purge Completed Workflows?
So why would you want to purge completed workflows? Workflow instances are stored as nodes inside CQ. Generally, this doesn’t pose a problem for author-generated workflows, at least not over the short and medium term. However, for very long running CQ instances or instances where website users or automated jobs can run workflows, this can quickly add up to large amounts of content accumulating in your repository. This can lead to slow performance and growing disk usage.
To avoid this, you can simply purge old workflows.
Enabling the Workflow Purge Scheduler
It does not come pre-configured, however so to enable CQ to automatically purge your workflows you will need to create a Workflow Purge Scheduler instance. The Workflow Purge Scheduler is a Sling Service Factory, so creating an instance is as easy as logging into the Apache Felix Configuration Console and selecting the %2B button next to Workflow Purge Scheduler:
Most of the fields in the scheduler are pretty self-explanitory. When you click Save, the scheduler will be scheduled on the cron schedule you specify and will purge workflows older than the specified number of days using the configuration you specify.
Configuring the Workflow Purge Scheduler in a Package
This is all well and good, but let’s just say you wanted to just deploy a configuration as a part of your package deployment process. Through the magic of Apache Sling’s OSGi Configurations, you can do this with a simple XML file.
Simply create an XML file in your IDE in your content project under a path like:
Set the name of the file to:
and put in the following contents, replacing with the values for your configuration:
xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="sling:OsgiConfig" scheduledpurge.name="Purge All Completed Workflows" scheduledpurge.workflowStatus="COMPLETED" scheduledpurge.modelIds="" scheduledpurge.cron="0 0 * * * ?" scheduledpurge.daysold="30" />
Once you deploy this file as part of your content package, you should see the configuration show up under the Workflow Purge Scheduler in the OSGi Configuration console.