exitFlow

Hi ,

Is a way that we ‘exitFlow with signalFailure’ from Child service and still have the pipeline data available in Parent service ?

In the parent service, in the catch block, invoke pub.flow:getLastError service and in the getLastError/pipeline document you will have the pipeline data until the point of exception. Using a simple map step you can retrieve the values back.

Cheers
Guna
http://www.nibodo.com

Gunasekhar,
Not getting like that … Below is the scenario …

I have 3 services as follows …

ParentSvc in try/catch block
calling ChildSvc1 inside this …
calling ChildSvc2 inside this

ChildSvc1 is again having try/catch block (I need this to handle some exceptions in catch block)
In catch block of ChildSvc1 , last step is ‘exitFlow signal failure’ . I need this because it should not continue processing ChildSvc2 in ParentSvc if there is an error in ChildSvc1 .

Now , the control comes to catch block of ParentSvc when it failes in ChildSvc1 .

By this time iam losing all pipeline data … which I need some of it here …

Items to consider:

  • When a service uses EXIT and signal FAILURE, a call to getLastError will not return anything (exit doesn’t throw an exception). Thus, lastError/pipeline won’t exist.

  • To throw a ServiceException, you can write a Java service (or use an existing service, such as one from PSUtilities) that accepts an message input and throws the ServiceException. This will put the state of the thread such that getLastError will return the error and the state of the pipeline at the time of the error.

  • Keep in mind that any variable declared/defined in the try block will not be directly available in the catch block (this is the same scoping behavior as virtually every programming language–vars defined in the try block are not visible in the catch block). If you want the var to be visible, define it outside of the try/catch sequence blocks. In the catch block, the var will then be visible and will hold the latest value that was set anywhere before the catch, even if mapped/set in the try block.

Hope this helps.

Hi Reamon,
Now I remember writing java service to do the job.
Good reminder. Thanks.

Cheers
Guna
http://www.nibodo.com

Gunasekhar and reamon,

Thanks for all your inputs .. I have managed to acheive this with some workaround using savePipeline and restorePipeline ...

Thanks,
Sasi …

Hey -

Sorry for chiming in a little late. Here are my comments though:

  1. “Exit and signal failure” does indeed throw an exception. It throws a com.wm.lang.flow.FlowException and you can use getLastError as you would with other exceptions.
  2. savePipeline and restorePipeline are normally used for debugging purposes. Nothing prevents you from using it for the purposes you’re describing, but it would normally not be considered good practice. Refer to Rob’s 3rd point and that should help you identify which variables you need to define outside the catch-block and which variables you should pull from lastError/pipeline.
  • Percio

You’re right, it does throw an exception. FlowException instead of ServiceException. You can call getLastError but there won’t be anything in it–nothing is returned.

I verified this behavior with 7.1.2 (FLOW has behaved this way for some time).

Be careful about the modularity aspects here. As Percio points out, save/restore really isn’t intended for this purpose.

Perhaps you can post your services (or a representative example) and we can help structure things such that the data you need is visible at the right spots.

Rob,

Maybe we’re talking about different things. I’ve always used “EXIT and signal failure” and getLastError returns exactly what I would expect. I just tested it in 7.1.2 and it worked.

There’s one scenario in which “EXIT and signal failure” does not work as most people would expect: if you setup a try-catch block and inside the try block in that same service you execute an “EXIT and signal failure” step, control will be transferred to the catch block, but like you said, getLastError won’t return anything.

However, if you setup a try-catch block, inside the try block you call another service and that service (or one of its children) executes “EXIT and signal failure”, control will be transferred back to the catch block of the parent and getLastError will return what is expected.

I apologize if I have misunderstood your post.

  • Percio

Great clarification. It was indeed the first scenario I was referring to. Thanks for sharing the second scenario–I wasn’t aware of the difference in behavior for getLastError in this case. Thanks for sharing!

You’re welcome. The way the EXIT step works (or doesn’t work, for that matter) is definitely quirky. I remember being a little confused and disappointed when I first came across it.

  • Percio

lets say if we are having a 4 level hierarchy flow services, and if in the Child service “Flow4” i’m using Exit step, is it possible to exit from ParentFlow1 directly without the control going to the catch blocks of Flow 2 and 3.

ParentFlow1
[INDENT]Flow2[/INDENT]
[INDENT][INDENT]Flow3[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]Flow4[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]Exit from ??? Signal Failure[/INDENT][/INDENT][/INDENT]

No. If you throw an exception, the exception will be propagated down through the call stack.

Can you provide some more details around what you’re trying to accomplish? We should be able to help you arrive at a sound solution.

  • Percio

You might have too many try/catch blocks. Normally, only top-level services should have try/catch unless there are specific errors you need to handle in child services.

Thanks Percio/Rob for the reply,

I have the error notification service in the Parent Flow. and I thought of putting the pipeline data, at the time of error , in to the error notification. By the time the control comes back to the Parent flow, the call stack would have duplicated items, and that would increase the message size.
Hence was looking to have smaller call stack.

This is it!!! This is kinda annoying… :-/