Restarting an instance

By far, I’m starting to get the impression that reading is too complicated for the likes of me…

I am following this documentation - Process Instance Restart | docs.camunda.org

I have a process, which is started by a message:

I start the process from another one by sending a starting message. This works fine.

Now I have the nerve to restart the process.

I follow the documentation, which states

ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
runtimeService.deleteProcessInstance(processInstance.getId(), "any reason");

I’m certain that I’m getting the correct instance:

runtimeService.createProcessInstanceQuery()
		                                         .processInstanceBusinessKey("child_" + execution.getProcessInstanceId())
		                                         .singleResult();

This is a drop-create local dev, and I physically don’t have anything else on the plate. Also .list() returns the same instance.

I am executing this from a JavaDelegate as an ExecutionListener (thought about transactions and divided into two calls, no luck).

And I am getting an error

Historic process instance 'fbc6735a-0ab1-11ee-a378-12adb3c8b01b' cannot be restarted. It is not completed or terminated.

What am I missing?

@Niall

Check your timer event how you configured. Error clearly states the reason. process instance is active and it was not terminated or completed.

Please look into the model how you defined it.

@cpbpm Can I somehow define a timer to be interruptable?

I made a very basic

You could do something like this…

But… Why “Restart”? You need to know what the state of your “poke” process is to do that. Why not just start another instance of the “poke” process?

2 Likes

Ah, so I can do a gateway with only one possible message? (and have the other direction as timer)

The tricky part here is that I’m starting an instance of the “poke” with some data. “Restart” will be a “something”, which may happen during the next steps. Starting a new instance means that I must provide data every time (yes, I could extract data from the running instance, but I assume that may take computation time).

UPD: ah, I remember now why I tried to restart instead of a message - Getting started with messages - #12 by Niall

@GotnOGuts I think I haven’t been soooo happy since I was a little kid :smiley:
It works!

Now it has a “waiting for a message” option and I managed to get a restart behavior

Thank you, good person! I can finally rest (and implement) in peace

1 Like

@Draakzward

Yes, but you can use the same “Event Based Gateway” to do the loop you originally planned… only at the gateway, wait for either the timer to go off, or the “Stop” message to come in…

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.