ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey E Care <ca...@us.ibm.com>
Subject Re: Retry task container
Date Mon, 14 May 2007 12:17:54 GMT
How do you signal a task to clean up after itself after a failed attempt?

____________________________________________________________________________________________


Jeffrey E. (Jeff) Care 
carej@us.ibm.com 
IBM WebSphere Application Server 
Systems Management Tools Architecture & Development 







"Kevin Jackson" <foamdino@gmail.com> 
05/13/2007 12:32 AM
Please respond to
"Ant Developers List" <dev@ant.apache.org>


To
"Ant Developers List" <dev@ant.apache.org>
cc

Subject
Retry task container






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