flowsforapex / apex-flowsforapex

Flows for APEX - Model and run process flows all within Oracle APEX!
https://flowsforapex.org
Other
81 stars 41 forks source link

Restart a script/service task after failure #204

Closed vanDrielKevin closed 2 years ago

vanDrielKevin commented 3 years ago

Hello,

I am trying to use Flows For APEX as a replacement for the old Oracle workflows. I have a problem regarding error handing in Flows For APEX. My goal is to make a task red if it fails to execute. This way we can see where the flow went wrong. The problem is that I can’t figure out how to make the task change color. I found the plugin with javascript and css to make the blocks green or gray but I don’t know how the color change is called and how I can call my css class to make a block red this way.

Regards, Kevin (student)

nielsdebr commented 3 years ago

Nice to see you adopting Flows for APEX!

This is a great question. If it concerns a business error, you can model this today using error boundary events in your flow (have a look at tutorial AA6). When it comes to technical errors (and marking the activity red), we don't have support for this today, but I would like to discuss this with others in the group if this is a case that we should support. I wonder how Camunda handles this?

rallen2010 commented 3 years ago

HI Kevin, I think you'll find it difficult to do what you are trying to do at the moment, because we don't keep track of errors in the engine at the moment. I've always thought that this is part of a system management and monitoring (& audit) development feature that we need to address in some release in the next year or two, as we start to get users with applications in production. There are a few things that might help. First, so you understand how the colouring mechanism works: the way the task colouring works is that we have a view, flow_instance_details_vw that returns three columns all_completed, last_completed, and all_current -- which contain the list of objects falling into those categories. There are 3 css tags which match those three categories, & the bpmn_viewer plugin provides the list of nodes and css when it is refreshed. We discovered that all_completed and last_completed are best shown in the same colour (grey, out of the box) & so we usually now display 3 lists with 2 colours. The difficulty you will have at the moment is coming up with a list of objects that haven't succeeded / have failed. If you could do that, you could rewrite the flow_instance_details_vw view so that all completed tasks are included in one of the two categories - say all_completed, then rewrite the subquery for last_completed to return your error objects, and change the css colour assignment for that group to, for example - red. It's just not obvious to me how you would identify the failed nodes? type of object & time as current object => assumption/probability of having stalled?

vanDrielKevin commented 3 years ago

Hi Niels and Richard, First of all a big thanks to you both for giving me such a quick response!

Niels, I found the boundary events in the tutorial. This is not exact what we are looking for. Currently I am making my own ‘framework’ so we can simplify the script code behind each block. We do not anticipate where it could go wrong like you would with a boundary event. The flows we are using are only used to see where they go wrong, if they go wrong. This is why we would like to see the block in red.

Richard, Your awnser is more what I was looking for. Your explanation about the views helped a lot. I can detect an error just with an exception catch. From here I will use my ‘framework’ to update the tables. I am going to do try some work on this myself. I will post an update if it works but the plan for now is this:

  1. Write error from exception handler to FLOW_SUBFLOW_LOG -> sflg_notes
  2. Add sfgl_notes to error column in FLOW_INSTANCE_DETAILS_VW
  3. Add sfgl_notes to error column in FLOW_P0010_VW from FLOW_INSTANCE_DETAILS_VW
  4. Add PL/SQL Code in plugin to get error column into json format
  5. Add Javascript code to get the error from json and refer it to a css class that fills the block in red If these steps succeed I believe it should work. I will post an update for you when I tried this. For now again a big thanks for the answers!

Regards, Kevin (student)

nielsdebr commented 3 years ago

Be cautious by changing "our" objects as they might get overwritten during an update of Flows for APEX. Just create your own views and packages on top of our views/packages.

vanDrielKevin commented 3 years ago

Yes! That is a good point, I will create my own views so I don't interfere with future updates. Thanks for the heads up!

vanDrielKevin commented 3 years ago

Hello,

I have an update for the error color change. I got it working but it might not work for everyone because of the way I detect runtime errors. I detect the errors trough an exception function in every script task. I pause the flow by removing the ‘complete_step’ line in the FLOW_ENGINE.Process_scriptTask (I saw no other way then removing this) and if the function is completed I call my own stopfunction that will make ‘the complete_step’ for me.

As an extra I also added a document to retry if a task fails. So now if it fails, the task will turn red and the flow does no continue (unless you step over it manually in the subflow tab in apex). To retry a failed task I made an extra dropdown box in APEX so you can select the blocks in error. If you press the retry button it will try to execute the pl/sql again. So if you edit a var or the pl/sql code for example it will try to execute it again and if everything is okay it will continue the flow.

I know not everything will work perfectly, and there will be some flaws that I did not (yet) think of. But it will be a good basis to work from. I have made documents that explains everything that I have done. I hope it will help other people or the flows for apex team for future updates. https://drive.google.com/drive/folders/16bena2kMbWgZvSEBKZZqr8ofOy67ZdtG?usp=sharing

Regards, Kevin (student)

rallen2010 commented 3 years ago

Well done, Kevin! You've done some good and interesting work there & that's prompted us to think about several improvements that we could make to improve Flows for APEX in a future release.

rallen2010 commented 3 years ago
rallen2010 commented 3 years ago

Remaining Tasks after 12 August Merge:

LouisMoreaux commented 2 years ago

Delivered in version 21.1