workflow always in RUNNING state even though the workflow process finishes | Community
Skip to main content
Level 3
October 16, 2015
Solved

workflow always in RUNNING state even though the workflow process finishes

  • October 16, 2015
  • 9 replies
  • 7860 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by GK-007

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.

9 replies

smacdonald2008
Level 10
October 16, 2015

See this AEM doc topic:

https://docs.adobe.com/docs/en/cq/current/workflows/wf-admin.html

You can manually terminate it. 

GK-007
Level 9
October 16, 2015

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.

Naveen_AEM_dev
Level 4
October 16, 2015

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!

Rui_JAuthor
Level 3
October 16, 2015

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?

Rui_JAuthor
Level 3
October 16, 2015

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?

GK-007
Level 9
October 16, 2015

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.

Rui_JAuthor
Level 3
October 16, 2015

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.

Rui_JAuthor
Level 3
October 16, 2015

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

GK-007
GK-007Accepted solution
Level 9
October 16, 2015

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.