Page 1 of 1

Server routines - how to get out infinite looping

Posted: Mon Apr 16, 2012 2:14 pm
by sigma
Dear all

I have a few server routines that takes in a variable and parses it out.

In short we have a lot of information in our material number and I have to parse out components based on some specific logic.

The logic is working great and it returns and tests out great.

I just have one concern.. as most of the routines I have built include a do while looping construct

As of now I have tested out the for 1.4 million materials and it works great but my only concern before putting to production is the threat or risk of a job getting stuck in one of the routines for infinite looping.

What is the best way to get some check in place so that it times out.. is there a timeout concept we can tie to the routine so that if it spends more than 60 seconds then it exists out with ANS set to "no value found" or something like that..

Posted: Tue Apr 17, 2012 1:04 am
by kandyshandy
Infinite loop means infinite ;) Do you want to implement a StartTime and CurrentTime difference check and use an exit?

Share your routine here.

Posted: Tue Apr 17, 2012 8:18 am
by sigma

Code: Select all

REM 'This function takes in a material number as a parameter and parses the package size out of the material number'
REM 'The following are some of the varaibles that will be used in the logic'
      Numeric = "0123456789,."
      Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      NextDash = 0
      AfterDashStr = ""
      Unit_SizeCk = ""
      PackageSize = "1EA"
      StartTime=Time()
      TimeDifference=0
      EndTime=0

REM 'Actual logic begins here'
REM 'Check if the material has any dashes'
      NextDash = Index(Material, "-",1)
REM 'If material has no dashes then set the package size to 1EA.. else loop through'
         If NextDash = 0 Then PackageSize = "1EA" ; goto 10 ; else AfterDashStr = Right(Material, Len(Material) - NextDash) ; 
      LOOP
         NextDash = Index(AfterDashStr, "-",1)
         If NextDash = 0 Then Unit_SizeCk = AfterDashStr else Unit_SizeCk = Left(AfterDashStr, NextDash - 1) ; 
            If Index(Numeric,left(Unit_SizeCk,1),1) > 0 and Index(Alpha ,right(Unit_SizeCk,1),1) > 0 then PackageSize = Unit_SizeCk ; exit ; else AfterDashStr = Right(AfterDashStr, Len(AfterDashStr) - NextDash)
REM 'Keep track of the end time and if this is looping for more than 10 seconds exit out
         EndTime=Time()
         TimeDifference= EndTime - StartTime
         if TimeDifference > 10 then PackageSize="TimedOut" ; exit ; 
      WHILE NextDash > 0
      REPEAT
10:*
      Ans=PackageSize

Posted: Tue Apr 17, 2012 9:11 pm
by kandyshandy
I don't see a valid reason for your loop to go infinite. Also, what you are doing is to check if a particular material process took more than 10 seconds & that's not at all needed... How many dashes do you expect in your "material"?

Posted: Wed Apr 18, 2012 6:35 am
by qt_ky
I'm not sure there is reason to be concerned about infinite loop, especially if it tested fine on 1.4 million records already.

You could run your own load test by concatenating your input file many times over or generating say 200 million records to test it with.

Another possible way to detect this potential problem is to monitor for it externally. Suppose your job with the routine outputs to a file. You could setup a separate job to monitor file size growth. If growth stalls for 60 seconds it could alert someone, but then again that could indicate the job completed.