cancel
Showing results for 
Search instead for 
Did you mean: 

KX Control - stopStateFunct?

adrianosm_
New Contributor III

Hi all,

We can define initial state functions for our beloved KX processes on KX Control, but what about stop state functions? Say I want an RTE to do a few things on close, how could I do that?

Kind regards,
Adriano

1 ACCEPTED SOLUTION

On the KX Platform you should not use .z.exit directly as it performs some inbuilt operations.

Instead use .ch.addExit which is a handler for you to add your custom behaviour on top of what is inbuilt.

 

https://code.kx.com/platform/api/IPC/#chaddexit

View solution in original post

5 REPLIES 5

dcrossey
New Contributor III
New Contributor III

EDIT: See @rocuinneagain 's reply for the optimal solution for this question.

---

Hi adrainosm_,

You would need to define an analytic (or analyticgroup) that is loaded by your RTE process, then send a message to that process via IPC (for example) just prior to shutting down your, if there is some specific steps you want to take prior to shutdown.

Alternatively, you could also add a wrapper around your eodFunct to carry out your steps if you RTE stops just after EOD, or you could also try using the timer functions on the process say e.g. once per day to achieve something similar.

Hope this helps,

David

adrianosm_
New Contributor III

Hi David,
Thanks for the reply. It looks like what I already do is in line with what you told me.

Here is my scenario:
I have one workflow that contains a single RTE that I use to start a bunch of service classes.
To do that, i used the initial state function of the RTE to call the startServiceCSV.sh script provided on the KX Data Warehouse tutorial.  Meanwhile, the csv contains hardcoded information about the "parent" RTE at each service class row.

Then, each service class has a custom initStateFunction that, among other things, creates an IPC handle to their parent RTE and keeps checking (with a timer) if the handle is still valid. So whenever i stop the workflow, the RTE obviously dies, making the handles invalid and therefore killing the services.

I asked about a stopStateFunction because if such a thing existed, i would not have to do the ipc logic 😆 - but what I am getting from your response is that this is as good as it gets?

cheers,
Adriano


Update: I did more investigation and found out .z.exit and that solved my problem.
Inside the initialStateFunction of the RTE, I assigned .z.exit to a function that calls the stopServiceCSV.sh script, thus eliminating the need of  using timers 😄

On the KX Platform you should not use .z.exit directly as it performs some inbuilt operations.

Instead use .ch.addExit which is a handler for you to add your custom behaviour on top of what is inbuilt.

 

https://code.kx.com/platform/api/IPC/#chaddexit

Oooo I see
Thanks for the tip. It works perfectly 😄