Kevin Jackson wrote:
Hi all,
Looking through the bugzilla I came across, #28736 requesting a retry
attribute for the ftp task.
I thought instead that a generic Retry task container may be useful.
I've quickly thrown this together and first tests (using get) seem to
be fine, does anyone have an objection to adding this?
Use case:
- network operations may fail and cause a build to fail when all is
needed is another attempt
<retry noRetries="3">
<get src="" dest=""/>
</retry>
1. we have this in the smartfrog workflow stuff...I'd recommend you add
an interval too, so that if something fails you can wait a bit before
trying again. Exponential backoff with jitter is just feature creep.
2. it looks like you try and redo each task until it succeeds. Surely
you'd want to rerun the sequence?
3. I'd resend the underlying exception on the ultimate failure, as it
may contain useful information
src:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant.taskdefs;
import java.util.Enumeration;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer;
/**
* Retries the nested task a set number of times
*/
public class Retry extends Task implements TaskContainer {
private Vector nestedTasks = new Vector();
private int noRetries;
public void addTask(Task t) {
nestedTasks.addElement(t);
}
public void setNoRetries(int n) {
noRetries = n;
}
public void execute() throws BuildException {
for(Enumeration e = nestedTasks.elements(); e.hasMoreElements();) {
Task t = (Task)e.nextElement();
for(int i=0; i<noRetries; i++) {
try {
t.perform();
} catch (Exception ex) {
log("Attempt ["+i+"] error occured, retrying..." ,
ex, Project.MSG_INFO);
}
}
try {
t.perform();
} catch(Exception ex) {
throw new BuildException("Failed after ["+noRetries+"]
attempts, giving up");
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]