每隔几分钟检查一次文件状态,然后根据状态采取措施吗?

时间:2018-08-24 17:20:15

标签: gradle groovy

我有下面的gradle任务,如果文件的状态是B,我想运行循环,然后等待5分钟; 5分钟后,再次检查同一文件的状态,如果它是B,然后等待,或者它是R,然后打印“工作已完成”。因此,如果文件状态为B,它将循环运行直到状态更改为R;如果文件状态为R,则将打印并移动到下一个文件(循环运行后,它将检查文件的状态)每5分钟

我认为问题在于,当状态为B时,它不会再移动,因为即使文件状态更改为R后,变量“ val”的值也没有得到更新

    task exportComponents {
  doLast {
    String groupId = getgroupId(serverName, Port, User, Password, groupName)
    JSONArray products = getproductId(serverName, Port, User, Password, groupId)
    mkdir "${buildDir}/components"
    for (int i = 0; i < products.size(); i++)
    {
      String name = products.getJSONObject(i).get("name")
      if ( name.matches("$baseVersion(.*)")) {
        String status = products.getJSONObject(i).get("status")
        def val = status
        while("$val" == "B") {   //Here R means ready and B means Busy
          Thread.sleep(20000)
          Print "The work has been not been completed yet once status change to R will print The work has been completed" 
        }
          Print "The work has been completed"
      }
    }
  }
}

0 个答案:

没有答案