In a long running Ant script, I have a target that gets called roughly once per second. (This is probably not a good thing, but let’s accept it for the moment.)
I only want it to execute if its last actual execution was at least five minutes ago.
One idea for a solution is to maintain a lastRunTimestamp property, and compare the current time to that.
Problem: How can I compare timestamps in Ant?
Another solution that would also be welcome is a means of executing the target only at specified time intervals, so that the check would not be necessary.
I am using Ant 1.7.1 and ant-contrib.
Any ideas are greatly appreciated – thanks!
Interesting question, and one which is a bit harder to answer than I originally thought.
You can use the
<tstamp>task to set a time stamp that’s five minutes old:Once you have that timestamp, you can use the lastmodified condition of the
<condition>task to see if a particular file has been updated since. If you don’t have a file, you can use the<touch>task to create one.The only issue is that default properties are immutable. Once set, you can’t change them. Fortunately you’re using
ant-contribandant-contriballows you to change that via the variable task.