Skip to content

Instantly share code, notes, and snippets.

@dei-biz
Last active March 22, 2019 09:51
Show Gist options
  • Select an option

  • Save dei-biz/90f8c4de8177dce1e142a0a29099a0bb to your computer and use it in GitHub Desktop.

Select an option

Save dei-biz/90f8c4de8177dce1e142a0a29099a0bb to your computer and use it in GitHub Desktop.
Every15minutes
//Superseded by https://gist.github.com/dei-biz/112c3825b5752c76dcb0a915b49bca47
executeNext15 = (callback)=>{
const now = new Date();
const nextTime = new Date(now.getTime() + 15 * 60 * 1000 + 1);
const nextTimeRound = new Date(nextTime
.setMinutes(15*(Math.floor((nextTime.getMinutes() / 60) * 4)))) //every 15 minutes/4 times an hour
.setSeconds(0)
const timeout = nextTimeRound - now;
console.log(`Releasing the Kraken (again) at ${new Date(nextTimeRound)}`);
setTimeout(()=>{
callback();
executeNext15(callback);
}, timeout)
}
executeNext15(() => {console.log("RELEASED!")})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment