Hi,
I'm using a listener class to trigger a workflow on modification assets based on asset type. Since multiple assets are uploaded at once updating the properties in assets is giving persistence exception. I have configured a job queue for our model. It is triggering the workflow in order but not sure whether it's waiting for the previous wf to complete and then start. How to check whether the previous wf is completed and then trigger the wf for next asset.
private void triggerWorkflow(ResourceResolver resourceResolver, String resourcePath) {
try {
WorkflowSession workflowSession = resourceResolver.adaptTo(WorkflowSession.class);
if (workflowSession != null) {
WorkflowModel workflowModel = workflowSession.getModel(SamsConstants.MEDIA_SET_WF_MODEL);
if (workflowModel == null) {
log.error("Workflow model not found: {}", SamsConstants.MEDIA_SET_WF_MODEL);
return;
}
WorkflowData workflowData = workflowSession.newWorkflowData("JCR_PATH", resourcePath);
workflowSession.startWorkflow(workflowModel, workflowData);
} else {
log.error("Workflow session is null.");
}
} catch (Exception e) {
log.error("Error triggering workflow for resource at {}", resourcePath, e);
}
This is the piece of code where I'm calling the wf. Please let me know the better approach I can follow.
Thank You.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Just few options that just comes in my mind:
1. I would try to use a prop as a flag, that can be used as a semaphore for ordering the trigger of multiple sling jobs, each sling job would wrap a workflow that tries to access same resources. For example, each job would first check if this is true or false, and only starts only if flag is false. Otherwise it retries later. If is is false, it starts the workflow and sets the flag to true, and sets it back to false when the workflow finishes.
2. I assume you use resource resolver to commit changes. You can try to use a combination of isLive(), hasChanges(), refresh() and commit() methods to ensure each workflow's instance of resourceresolver has latest snapshot of jcr before it tries to commit the changes.
Hi @Tethich ,
1. Adding flag to the asset is not possible bcz we are checking the modified imagesets, spinsets and video. Then creating mediaset automatically. adding flag will be complicated.
2. I tried adding those condition still same issue.
Option-1:
How are you procuring ResourceResolver? Is it a shared object by all events ? Or is it a new resourceresolver for each event?
Preferrably, do not use the same Resolver object between events. This will help you avoid PersistenceException. Thus, you might not need to manage the order of workflows.
Option-2: Use workflow launchers instead of Events (Preferrable)
In this case you won't have to manage sessions & avoid Persistence Exception.
Hi @aanchal-sikka ,
Resolver is new for every event.
I created launcher. Even launcher has same issue. Is it possible to configure the delay in launcher?
Is it possible for you to share your Launcher configuration?
Also, can you please cross-check if multiple workflows were triggered for same asset?
Workflow is getting triggered once for each asset.
I have created 3 launchers for created, modified and delete.
Just for my understanding, wouldn't there be 2 workflows now on Asset upload
If yes, you should be able to trigger a Sub-Workflow for Custom Workflow at the end of DAM Update Asset. That would assure that Assets is worked upon by one Workflow session.
Shouldn't you be listening to even on Original Rendition Or metadata node update based on requirements. dam:Asset doesn't seem right. This node is not updated on metadata updates / rendition change
yes @aanchal-sikka
Hi @aanchal-sikka ,
I have added this configuration for the workflow to be triggered in order. Still the same issue. Can you please check If I'm missing anything?
Thank You
Views
Likes
Replies