【问题标题】:ANT Recursive call of target, target calling itselfANT 递归调用目标,目标调用自身
【发布时间】:2017-04-24 08:47:26
【问题描述】:

我有一个像下面这样的 ANT 目标:

<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>

正如您所见,它是一种递归目标,如果遇到某些条件,validate_master_resources 会调用自己。

我决定使用 runtarget(而不是 ant 调用),以避免创建新的 ANT 进程。

该作业在临时测试了几分钟后,按预期工作,但在前 2 次“真实世界”运行中,它在 20 分钟后卡住了...

我在 Jenkins 中运行这项工作,正如所说的那样,这项工作在 20 分钟后卡住了

正如你在下面看到的,它被调用了很多次然后卡住了几个小时,我需要杀死它......

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 

现在,我的问题是,这个问题(构建卡住)是否与这个 ant 任务是递归的有关?

是否有任何任务流程/标签可以帮助我管理这样的递归?

我是否在非法模式下使用任务,错误行为取决于我创建的这个特定循环?

谢谢

【问题讨论】:

  • “if”和“runtarget”任务都是 ANT 扩展的一部分,称为 ant-contrib。两者都不是标准 ANT 的一部分
  • 是的,那我知道了?

标签: recursion ant ant-contrib


【解决方案1】:

这里没有问题,愚蠢的问题,唯一的问题是我没有取消设置循环中的变量并且我总是使用相同的值,这导致脚本的其余部分出现问题,导致进程挂起...

解决了!在 ant 中使用变量时要小心,有时管理范围会很痛苦!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 1970-01-01
    • 2013-06-17
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多