def runHouseKeeping()

in app/housekeeping/TimeOutLongRunningBakes.scala [27:57]


  def runHouseKeeping(earliestStartedAt: DateTime): Unit = {

    log.info("scanning for long running bakes to mark as timed out")

    val bakesToTimeout = getBakesToTimeOut(earliestStartedAt)

    log.info(
      s"${bakesToTimeout.size} long running bake(s) found for marking as timed out"
    )

    bakesToTimeout.foreach { bake =>
      packerEC2Client.getBakeInstance(bake.bakeId) match {
        case None =>
          log.warn(
            s"unable to find instance associated with long running bake ${bake.bakeId}"
          )

        case Some(instance) =>
          val instanceId = instance.getInstanceId
          log.info(
            s"terminating instance $instanceId associated with long running bake ${bake.bakeId}"
          )
          packerEC2Client.terminateEC2Instance(instanceId)
      }

      // Update the status to TimedOut, even if the respective EC2 instance can't be found.
      // This is to handle cases where e.g. the instance was deleted manually.
      log.info(s"marking long running bake $bake as timed out")
      bakesRepo.updateStatusToTimedOutIfRunning(bake.bakeId)
    }
  }