Hi,
I wanted the retry task to wait a bit before retrying. Since I didn't
find a clean way to do this I patched the retry task to support a
'retryDelay' attribute. This simply sets the time to sleep between
different retry attempts. We currently use this on our build server to
retry SVN updates which might fail because multiple jobs are updating
the same sandbox concurrently. So far it's been working fine.
The attached patch has only been compiled/tested against java 1.6, but
I guess it should be fine in older versions as well.
The output, when a retryDelay is set looks like this:
updateLib:
[echo] Start library update...
[svn] svn: Working copy 'C:\BuildSystem\Libraries' locked; try
performing 'cleanup'
[svn] svn: Working copy 'C:\BuildSystem\Libraries' locked; try
performing 'cleanup'
[svn] <Update> failed.
[retry] Attempt [0]: error occurred; retrying after 1000 ms...
[svn] svn: Working copy 'C:\BuildSystem\Libraries' locked; try
performing 'cleanup'
[svn] svn: Working copy 'C:\BuildSystem\Libraries' locked; try
performing 'cleanup'
[svn] <Update> failed.
[retry] Attempt [1]: error occurred; retrying after 1000 ms...
[echo] Update done...
I'd like to see this added to ANT as running custom versions of basic
tools is just tedious. So if anything in this patch would block
inclusion please let me know and I'll see if I can improve it.
Regards,
Arjan Veenstra
Index: main/org/apache/tools/ant/taskdefs/Retry.java
===================================================================
--- main/org/apache/tools/ant/taskdefs/Retry.java (revision 1183274)
+++ main/org/apache/tools/ant/taskdefs/Retry.java (working copy)
@@ -40,6 +40,11 @@
private int retryCount = 1;
/**
+ * The time to wait between reties in milliseconds, default to 0.
+ */
+ private int retryDelay = 0;
+
+ /**
* set the task
* @param t the task to retry.
*/
@@ -61,6 +66,17 @@
}
/**
+ * set the delay between retries (in miliseconds)
+ * @param n the time between retries.
+ */
+ public void setRetryDelay(int retryDelay) {
+ if(retryDelay < 0)
+ this.retryDelay = 0;
+ else
+ this.retryDelay = retryDelay;
+ }
+
+ /**
* perform the work
* @throws BuildException if there is an error.
*/
@@ -81,7 +97,17 @@
exceptionMessage.append(errorMessages);
throw new BuildException(exceptionMessage.toString(),
getLocation());
}
- log("Attempt [" + i + "]: error occurred; retrying...", e,
Project.MSG_INFO);
+ String msg;
+ if(retryDelay > 0)
+ msg = "Attempt [" + i + "]: error occurred; retrying after
" + retryDelay + " ms...";
+ else
+ msg = "Attempt [" + i + "]: error occurred; retrying...";
+ log(msg, e, Project.MSG_INFO);
+ try {
+ Thread.sleep(retryDelay);
+ } catch (InterruptedException ie) {
+ // Ignore Exception
+ }
errorMessages.append(StringUtils.LINE_SEP);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org