def processInstance()

in lambda/autodowning/src/main/scala/AutoDowningLambdaMain.scala [158:181]


  def processInstance(details: LifecycleDetails, state:String, attempt:Int=0, maxRetries:Int=100)(implicit logger:LambdaLogger):Unit = getEc2Info(details.EC2InstanceId.get) match {
    case Success(Some(info))=>
      println(s"Got $info")
      if(shouldHandle(info)) {
        if (state == "shutting-down" || state == "terminated") {
          logger.info("registering shutdown")
          registerInstanceTerminated(details)
        } else if(state == "running"){
          logger.info("registering startup")
          registerInstanceStarted(details, info)
        } else {
          logger.info(s"don't need to register $state state")
        }
      } else {
        logger.info(s"We are not interested in this instance, tags are ${getEc2Tags(info)} but we want $tagsComparison")
      }
    case Success(None)=>
      throw new RuntimeException(s"No details returned from EC2 for instance ${details.EC2InstanceId.get}")
    case Failure(exception)=>
      logger.warn(s"Could not contact EC2 on attempt $attempt: ", exception)
      if(attempt>maxRetries) throw exception
      Thread.sleep(1000)
      processInstance(details, state, attempt+1, maxRetries)
  }