Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Prevent batch harvests from requesting invalid dates
Browse files Browse the repository at this point in the history
This prevents batch harvests from requesting date that is older than
yesterday with the assumption that it’s safest to not request an OAI
feed for today as more data may be added later we’d miss. I’m not
entirely sure that’s valid logic, but this is safe. The harvester
increments the updated date hence the need to make sure it is less than
yesterday (i.e. updated needs to be two days ago to actually run which
would then get incremented by 1 to be a harvest for yesterday… clear as
mud).

Admin kicked off harvests and knips are not limited by date. Only the
batch starter.

closes #240
  • Loading branch information
JPrevost committed Jul 15, 2015
1 parent 72f9c64 commit d6a5136
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import scala.concurrent.Await
import akka.actor.Props

import java.util.Date
import java.time.Instant
import java.time.temporal.ChronoUnit

import play.api._
import play.api.data._
Expand Down Expand Up @@ -273,10 +275,16 @@ object Application extends Controller with Security {

def startAllHarvests(key: String) = Action { implicit request =>
val authorized_key = Play.configuration.getString("auth.harvest.key").get
val yesterday = Instant.now.truncatedTo(ChronoUnit.DAYS).minus(1, ChronoUnit.DAYS)
if (key == authorized_key) {
Harvest.all.map{ h =>
harvester ! h
h.complete }
if(h.updated.before(Date.from(yesterday))) {
harvester ! h
h.complete
} else {
println("A harvest tried to start that had an invalid date.")
}
}
Ok("kicked off all harvests")
} else {
Unauthorized(views.html.static.trouble("You are not authorized"))
Expand Down

0 comments on commit d6a5136

Please sign in to comment.