Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

workflow always in RUNNING state even though the workflow process finishes

Avatar

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
Rui_J
Level 2

15-10-2015

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 100
Level 6
GK-AEM
Level 6

Likes

40 likes

Total Posts

482 posts

Correct Reply

32 solutions
Top badges earned
Validate 100
Validate 50
Validate 25
Validate 10
Validate 1
View profile

Avatar
Validate 100
Level 6
GK-AEM
Level 6

Likes

40 likes

Total Posts

482 posts

Correct Reply

32 solutions
Top badges earned
Validate 100
Validate 50
Validate 25
Validate 10
Validate 1
View profile
GK-AEM
Level 6

15-10-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.

Answers (8)

Answers (8)

Avatar

Avatar
Validate 10
Level 3
Naveen_AEM_dev
Level 3

Likes

21 likes

Total Posts

70 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
Naveen_AEM_dev
Level 3

Likes

21 likes

Total Posts

70 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
Naveen_AEM_dev
Level 3

15-10-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!

Avatar

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
Rui_J
Level 2

15-10-2015

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

Avatar

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
Rui_J
Level 2

15-10-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.

Avatar

Avatar
Validate 100
Level 6
GK-AEM
Level 6

Likes

40 likes

Total Posts

482 posts

Correct Reply

32 solutions
Top badges earned
Validate 100
Validate 50
Validate 25
Validate 10
Validate 1
View profile

Avatar
Validate 100
Level 6
GK-AEM
Level 6

Likes

40 likes

Total Posts

482 posts

Correct Reply

32 solutions
Top badges earned
Validate 100
Validate 50
Validate 25
Validate 10
Validate 1
View profile
GK-AEM
Level 6

15-10-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.

Avatar

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
Rui_J
Level 2

15-10-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?

Avatar

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
Rui_J
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
Rui_J
Level 2

15-10-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?

Avatar

Avatar
Validate 100
Level 6
GK-AEM
Level 6

Likes

40 likes

Total Posts

482 posts

Correct Reply

32 solutions
Top badges earned
Validate 100
Validate 50
Validate 25
Validate 10
Validate 1
View profile

Avatar
Validate 100
Level 6
GK-AEM
Level 6

Likes

40 likes

Total Posts

482 posts

Correct Reply

32 solutions
Top badges earned
Validate 100
Validate 50
Validate 25
Validate 10
Validate 1
View profile
GK-AEM
Level 6

15-10-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.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

15-10-2015

See this AEM doc topic:

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

You can manually terminate it.