Are there any known issues with the Perspective View onShutdown Event

We have a system where operators are processing a part. On the initial step of process, a record is created in the database for the part. This record gets updated through the process, but the record has a status flag that denotes it as in process. If something occurs before the part processing is complete (i.e. a navigation event, logout event, etc.) we want to remove this record from the table.
To accomplish this we have an onShutdown Event script that calls a project script. This project script should remove the incomplete part record.
This works as expected on a navigation event.
It is NOT working correctly on a manual or auto logout event.
The behavior is actually somewhat intermittent.
Sometimes, but rarely, it will remove the record on a logout event.
Sometimes it will remove the record on a re-login.
Sometimes it does not remove the record at all.
I’m wondering if there are potential issues with this event. Can anyone give me some detail on the actual behind the scenes process that occurs with this event on a logout event?
Is there a better way to perform a cleanup routine that using this event?


EDIT: We are using 8.1.10.

Why does the part need to be in the table during the process? I would think it would be better to wait on insertion until the entire process is complete.

That is the way the developer who built that feature did it. He had the client’s approval and changing it now is not likely to get approval. So at this point we just need to make it work. Whether the methodology is right, wrong, or indifferent at this point simply does not matter.

Edit: As a note, I say that due to this being in a regulated environment and making updates, testing, validation, and deploying is cumbersome, so they make decisions on what needs to be done and doesn’t based on what they think is important. If it turns out that there IS NO WAY to do this the way it currently is, then we may be able to convince them of completely refactor the feature.

Sure, but my question was meant to point out that View onShutdown Events can be missed if the View is un-gracefully removed from the session (closing the tab, network disconnect, maybe a forced closing of the session) so it’s not a good idea to build business logic which is reliant on it.

Since it sounds like you’re locked into using it, there’s not a “better” way than what you have.

For some detail about the Event, the Event is executed/fired whenever the back-end of the session removes the attached View from the Page (browser DOM). Note that since the back-end is where this happens, anything which causes a de-synchronization of the front-end and back-end can result in this Event not executing.

As you’ve found, navigation events result in the back-end removing the view and replacing it with something else. Removing any embedded instance by changing the path in use for the embedding component will also result in this event executing.

Closing a browser tab or disconnecting from the gateway will not result in the Event executing because the back-end is waiting for information from the front-end. Eventually the back-end will give up (based on your configured project timeout setting), and just remove the session. This results in a configured onSessionClose Event firing, but I don’t believe this results in onShutdown Events for the Views in use for that session; I am not 100% positive about this scenario.

In some of my testing today, I’ve seen a script error, “Session is not running”, which makes me think that most of the time the session closes before the process is done, and that causes this script error, which in turn stops the process dead in its tracks. On some occasions the process completes, indicating that there is something of a race condition between the session shutting down and the process completing. The problem does not exist on simple navigation away from the page. I imagine that is due to the session not stopping like it does on a logout event.

This maybe a stupid question, but is there a way to keep the session open a tad longer? Maybe a way to simply delay it ending for a second or two?

Not that I am aware of. Any chance you could use the onSessionClose Event to invoke the same script you’re using in the onShutdown of the View as a fail-safe?

I could test that to see.
I have mentioned the other failure modes that our methodology would simply miss (browser/client crash, network disconnect, etc.) so I’m hoping we can get a task on the books to refactor this. A complication to the whole mess is that we use the same view to allow operators to edit/reprocess a part. So that would have to be handled as well. We are going to have a meeting of the minds next week to discuss how to move forward on this. I appreciate you input!