ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: Retry task container
Date Sun, 13 May 2007 06:57:34 GMT

There is one of these in WebTest:

  http://webtest.canoo.com/webtest/manual/retry.html

But it might be nice to have one outside WebTest as well.

You might want to guard against NoRetries being equal to 0
or change the code to skip the perform in that case. It
wouldn't be the usual case but might be useful to allow it.

Cheers, Paul.

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>
> 
> 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: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message