Skip to content

Instantly share code, notes, and snippets.

@mmurray
Created July 17, 2014 23:45
Show Gist options
  • Save mmurray/752d794f69ebc572d584 to your computer and use it in GitHub Desktop.
Save mmurray/752d794f69ebc572d584 to your computer and use it in GitHub Desktop.
class Foo {
def fetchLatestActivityStats(orgCode: String): Future[String] = {
val yesterday = DateTime.now - 1.day
recursivelyLatestFetchActivityStats(yesterday, orgCode, 0)
}
def recursivelyLatestFetchActivityStats(
date: DateTime, org: String, errCount: Int): Future[String] = {
val key = "activity_stats/%s/%s/stats.json"
archiveBucket(key).map(fileItemOpt => {
fileItemOpt match {
case Some(fileItem) => date
case None => {
if (errCount >= 7) {
"-1"
} else {
val newDate = date - 1.day
val newErrCount = errCount + 1
recursivelyLatestFetchActivityStats(newDate, org, newErrCount)
}
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment