Server routines - how to get out infinite looping

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sigma
Premium Member
Premium Member
Posts: 83
Joined: Thu Aug 07, 2008 1:22 pm

Server routines - how to get out infinite looping

Post 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..
kandyshandy
Participant
Posts: 597
Joined: Fri Apr 29, 2005 6:19 am
Location: Singapore

Post 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.
Kandy
_________________
Try and Try again…You will succeed atlast!!
sigma
Premium Member
Premium Member
Posts: 83
Joined: Thu Aug 07, 2008 1:22 pm

Post 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
kandyshandy
Participant
Posts: 597
Joined: Fri Apr 29, 2005 6:19 am
Location: Singapore

Post 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"?
Kandy
_________________
Try and Try again…You will succeed atlast!!
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post 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.
Choose a job you love, and you will never have to work a day in your life. - Confucius
Post Reply