rduncan10
12th December 2012, 16:30
I'm having problems with an AFS session that runs in a batch job. Sometimes it does not terminate correctly and leaves the batch job user logged in.

Here is the situation:

We sell many phantom items. When the user enters these on the sales order, they need to change the "Issue Status" field to "Issue Main Item". Of course they forget, so I wrote a session to fix this and run it in a batch job. The script looks like this:


...First it runs SQL to find any order lines with "Issue Components"
stpapi.put.field("tdsls4101m000", "tdsls040.orno", str$(i.orno))
ret = stpapi.find("tdsls4101m000")
stpapi.handle.subproc("tdsls4101m000", "tdsls4102s000", "add")
stpapi.continue.process("tdsls4101m000", err.msg)

stpapi.put.field("tdsls4102s000", "tdsls041.pono", str$(i.pono))
ret = stpapi.find("tdsls4102s000")
stpapi.put.field("tdsls4102s000", "tdsls041.isss", str$(tcisss.issue.main))
**SEE NOTE**
if stpapi.update("tdsls4102s000", true, err.msg) = 0 then
stpapi.recover("tdsls4102s000", err.msg)
endif
stpapi.end.session("tdsls4102s000")
stpapi.end.session("tdsls4010m000")

The problem is that sometimes the line gets delivered before the batch job runs. When this happens, the err.msg value in the stpapi.update() function will be "Deliveries already entered...". Changing the line is not possible.

If I run this session manually, stpapi.recover() and stpapi.end.session() do their job and the session ends.

I'm not really sure what happens in the batch job. The log shows the session ends, and no errors are thrown, but the batch job user stays logged in after the batch job ends.

I realize that I could just change the query to filter out delivered orders. But and AFS session could run into other messages and errors, and I would like to see if there is a way to handle this in AFS itself.

mark_h
12th December 2012, 20:48
Can you check to see if you have any sub-processes that did not really get ended for a batch job? I have had a few sessions that have caused some of the sub-processes not end correctly and hangs the AFS session. Of course I can see this manually, but not sure how to see it in batch. In some cases I have had to add a pause to give things time to cleanup in the background.

rduncan10
12th December 2012, 22:38
Thanks. I will look into that.

I do give the batch job 20 minutes to complete? Would that do the same thing a pause.

In the job history, the session is shown as terminating within seconds of starting, and the next session in the job begins.

mark_h
13th December 2012, 15:45
I can't say - never really messed that much with jobs. In a couple of sessions I had to put a suspend(1000) or suspend(5000) to give things time to cleanup before launching the session again. What I am thinking is that at times the code in the selectdo is getting executed so fast that maybe the stpapi.recover is not finishing before the stpapi.end.sessions get executed. Then the stpapi.end does not get completed because of the recover command. What is tough is remembering that the stpapi code executes in the session, sends the command to the subsession, and goes to the next command. When I put some of the sessions I call in debug mode using qkey I can see the stpapi called session still executing(for example an update) while the AFS session has moved onto the next command.