Expand my Community achievements bar.

SOLVED

workflow always in RUNNING state even though the workflow process finishes

Avatar

Level 3

Hi,

  I am writing a workflow. This is my Code, In workflow, I put a "Process Step" in a workflow called "my workflow", check "Handler Advance". Then I start the workflow on this page, The code does the job. But if I switch to http://localhost:4505/libs/cq/workflow/content/console.html Instance tab to check the workflow instance, I found that "my workflow" is still in RUNNING state. What did I miss here?

package com.mycompany.workflow; import com.adobe.granite.workflow.WorkflowException; import com.adobe.granite.workflow.WorkflowSession; import com.adobe.granite.workflow.exec.WorkItem; import com.adobe.granite.workflow.exec.WorkflowData; import com.adobe.granite.workflow.exec.WorkflowProcess; import com.adobe.granite.workflow.metadata.MetaDataMap; import org.apache.felix.scr.annotations.*; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; import org.osgi.service.component.ComponentContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.jcr.RepositoryException; import javax.jcr.Session; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.Dictionary; import java.util.Enumeration; @Component(immediate = true, metatype = true, label = "Purge Cache", name = "com.mycompany.workflow.PurgingDispatcherWorkflow", description = "Purge the cache") @Service @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Implementation of cache purge"), @Property(name = Constants.SERVICE_VENDOR, value = "MyCompany"), @Property(name = "process.label", value = "Cache Purge"), @Property(name = "dispatcher.url", value = "http://localhost:80/dispatcher/invalidate.cache") }) public class PurgingDispatcherWorkflow implements WorkflowProcess { private Logger logger = LoggerFactory.getLogger(this.getClass()); private static final String TYPE_JCR_PATH = "JCR_PATH"; private String dispatcherUrl = ""; @Reference private ResourceResolverFactory resourceResolverFactory = null; @Override public void execute(WorkItem item, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException { Session jcrSession = null; try { WorkflowData workflowData = item.getWorkflowData(); if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) { String path = workflowData.getPayload().toString(); String purgeUrl = path; ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null); jcrSession = resourceResolver.adaptTo(Session.class); URL url = new URL(dispatcherUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/octet-stream"); connection.setRequestProperty("CQ-Action", "DELETE"); connection.setRequestProperty("Content-Length", "0"); connection.setRequestProperty("CQ-Path", purgeUrl); connection.setRequestProperty("CQ-Handle", purgeUrl); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); //Get Response InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); logger.info("**********Purge Result***********" + response.toString()); } } catch (Exception ex) { logger.error("Error in executing Cache Purge Workflow : ", ex); } finally { if (jcrSession != null && jcrSession.isLive()) { jcrSession.logout(); jcrSession = null; } } logger.info("******************Purging Finished******************"); } @Activate protected void activate(ComponentContext context) throws RepositoryException { final Dictionary<?, ?> properties = context.getProperties(); dispatcherUrl = (String) properties.get("dispatcher.url"); } }

 

 

Regards

 

Rui

1 Accepted Solution

Avatar

Correct answer by
Level 9

can you please add deactivate method as well to your process implementation class with empty block and check.This will complete entire service life cycle.

View solution in original post

9 Replies

Avatar

Level 9

Please check in AEM's Inbox ,any workitems are in queue or not.If there is any workitem there ,you need to complete that workitem.

After that please check Instances tab in workflow models,you will not see any running workflows.

Avatar

Level 4

Looks like your workflow is not able to advance from the custom "process step" to the "Flow end" step.You need to check the "Handler advance" value in the Process tab of the Process step. If the check box is ticked then the workflow will automatically move to the next step else you need to handle this programatically in your process implementation. Looks like you haven't done either.

Attached image also.

Hope this helps!

Avatar

Level 3

Yes, I can see its statsus is RUNNING  in the instance tab. But this workflow should be completed without any manual work. How can I do that?

Avatar

Level 3

I don't want to manually terminate it. I need it complete automatically without any manual process. Is there any thing I did wrong in my code?

Avatar

Level 9

it seems the designed workflow has participant step.

Can please share - screenshot of workflow and.

I have created a workflow with one process step and it deletes asset from DAM.Please refer the attached screenshot.

Avatar

Level 3

This is what I have. For example I start this workflow for one page for example /content/mysite/en.The workflow is supposed to finish without any user participation. I checked the log, everything runs without error.  But if I switch to workflow instance tab, I can see that this workflow is still in RUNNING status. I cannot start other workflow for this page because this workflow somehow is still running. Why is this happening?

Sorry, I dont know how to attach multiple pictures, So I add a new reply below.

Avatar

Level 3

[img]2015-02-21_20-39-46.png[/img] And this is the Working flow instance. It is always in RUNNING status

Avatar

Correct answer by
Level 9

can you please add deactivate method as well to your process implementation class with empty block and check.This will complete entire service life cycle.