Workflows - bartoszWesolowski/aem-tips GitHub Wiki
Workflows
- Implement bushiness processes
- Performed desired action on assets and pages (workflow payload) - for example creating asset rendition
- Each workflow consist of multiple steps executed after each other
- Workflow model is made of
WorkflowNodes
andWorkflowTransitions
and always has a start and end nodes - Runtime stored in
/var
directory - deploying changes through package will modify model definition in/conf
, workflows that have already started will not be affected as they are connected to runtime model - To apply changes to the workflow model is has to be synced - without that changes will not be applied (only changes in reference ECMA scripts will me applied as they are kept separately)
- Workflow can be Terminated, Suspended, Resumed and Restarted. Completed and terminated instances of a workflow are archived
Transient Workflows
Standard workflows save runtime (history) information during their execution. You can also define a workflow model as Transient to avoid such history being persisted. This is used for performance tuning as it saves/avoids the time/resources used for persisting the information. Transient workflows can be used for any workflows that:
- are run often.
- do not need the workflow history.
Does not support Go To
step.
Workflow execution - workflow instance is created and running (workflow was started):
- First step of workflow is executed
- Workflow engine determines which step to run next (based on workflow model)
- Next step is executed
- After all steps were executed workflow instance ends and is archived.
Executing a workflow instance generates a history that includes information about each step that has been executed for that instance - this can be useful for investigating errors.
Workflow step types
Participant step
- Requires a user action
- Can be assigned to group of users or particular user
- User will get item in his Inbox which he needs to complete manually
- Workflow instance will progress only when user step is finished
Process step
- Service perform a step
- Workflow instance will progress automatically
Participant process step
Process step example
@Component(immediate = true,
property = {
Constants.SERVICE_DESCRIPTION + "=Example workflow process",
Constants.SERVICE_VENDOR + "=Vendor",
WorkflowConstants.PROCESS_LABEL_PROPERTY_KEY + "=Example process step"
})
public class CreateTaskForAssetCollaborators implements WorkflowProcess {
@Reference
private ResourceResolverFactory factory;
@Override
public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
try (ResourceResolver rr = factory.getServiceResourceResolver(null)) {
if (PayloadMap.TYPE_JCR_PATH.equals(item.getWorkflowData().getPayloadType())) {
String payloadPath = workItem.getWorkflowData().getPayload().toString();
Resource payloadResource = Optional.ofNullable(resourceResolver.getResource(payloadPath))
.orElseThrow(() -> new WorkflowException("Can not get workflow payload resource for path: " + payloadPath));
// ....
} else {
throw new WorkflowException("Unsupported payload - only resource path is supported.");
}
} catch (LoginException e) {
// handle exception
}
}
Using custom step in new workflow
- Tools -> Workflow -> Models
- Create new workflow
- Add
Process Step
to the workflow parsys - Open step properties and select desired implementation to be invoked in this process
- Workflow model stored in
/conf
directory
Workflow Launcher
TODO