ivoruJavaBoy
ivoruJavaBoy

Reputation: 1357

ANT Recursive call of target, target calling itself

I've an ANT target like the one below:

<target name="validate_master_resources" description="Ensure the target is valid for local test run">

        <exec executable="bash" outputproperty="swap">
            <arg value="-c"/>
            <arg value="free -m | grep '^Swap:' | awk '{print $4}'"/>
        </exec>

        <if>
            <islessthan arg1="${swap}" arg2="5000"/>
            <then>
                <echo>the value of the swap memory is: ${swap}</echo>
                <sleep minutes="10"/>
                <runtarget target="validate_master_resources"/>
            </then>
        </if>
</target>

As you can see it's a kind of recursive target, validate_master_resources call itself if some condtions are encountered.

I decided to use runtarget (instead of ant call), to avoid the creation of a new ANT processes.

The job when tested ad hoc for few mins, works as expected, but in the first 2 "Real world" runs, it get stuck after 20 minutes...

I'm running the job in Jenkins and as said the job just stuck after 20 minutes

As you can see below, it has been called many times then stuck for hours and i need to kill it...

validate_master_resources:
     [echo] The number of current Java processes is: 33 summed to the 45 is 78 

validate_master_resources:
     [echo] The number of current Java processes is: 33 summed to the 45 is 78 

validate_master_resources:
     [echo] The number of current Java processes is: 33 summed to the 45 is 78 

validate_master_resources:
     [echo] The number of current Java processes is: 33 summed to the 45 is 78 

validate_master_resources:
     [echo] The number of current Java processes is: 33 summed to the 45 is 78 

validate_master_resources:
     [echo] The number of current Java processes is: 33 summed to the 45 is 78 

Now, my question is, can this problem (the build stuck) be related to the thing that this ant task is recursive?

Are there any task process/tags that helps me manage recursiions like that?

Am I using the task in an illegal mode, and the wrong behaviour depends by this particular loop that i created?

Thanks

Upvotes: 1

Views: 621

Answers (1)

ivoruJavaBoy
ivoruJavaBoy

Reputation: 1357

there were no issue here, stupid question, the only problem was that i was not un-setting the variables in the loop and i was using always the same values, this caused issues in the rest of the script that were causing the process to hung...

Resolved! Always be careful using variables in ant, the scope sometime can be a pain to manage!

Upvotes: 0

Related Questions