Reputation: 253
I'm trying to execute a function in angularjs every 10 minutes with final minute 5, for example: Function will execute once [...] 11:05, 11:15, 11:25, 11:35, 11:45, 11:55 [...]
I know I can set an interval like this, but I can't apply together:
function getStuff() {
$http.get().success(function(data) {
$timeout(getStuff, 5000);
});
});
Upvotes: 0
Views: 1690
Reputation: 466
One way would be to set an initial $interval to check for the time and check if the minute ends with a 5. Once it does, then you can run your $interval to run the job every 10 mins.
// run every min to check if time ends in 5
var stopTimeCheck = $interval(function() {
var currMin = new Date().getMinutes();
// check if minute time ends in 5
if (currMin % 5 === 0 && currMin % 10 !== 0) {
$interval(function() {
$http.get().then(...);
}, 600*1000); // run every 10 mins
$interval.cancel(stopTimeCheck);
}
}, 60*1000)
Upvotes: 1
Reputation: 41387
use $interval
to call the function every 10 minutes.
function getStuff() {
$http.get().success(function(data) {
console.log(data)
});
});
$interval(getStuff,600000)
Upvotes: 2