Skip to content

Commit

Permalink
move init code back outside handler (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenoir authored Nov 15, 2024
1 parent d4ee454 commit f7ecb34
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@ import scala.util.Try
object LambdaMain extends RequestHandler[SQSEvent, String] with Logging {
import weco.pipeline.batcher.lib.SQSEventOps._

// Initialize anything we want to be shared across lambda invocations here

private val config = ConfigFactory.load("application")

private object SNSDownstream extends Downstream {
private val msgSender = SNSBuilder
.buildSNSMessageSender(config, subject = "Sent from batcher")
override def notify(batch: Batch): Try[Unit] = msgSender.sendT(batch)
}

val downstream = config.getString("batcher.use_downstream") match {
case "sns" => SNSDownstream
case "stdio" => STDIODownstream
}

// This is the entry point for the lambda

override def handleRequest(
event: SQSEvent,
context: Context
Expand All @@ -29,17 +44,6 @@ object LambdaMain extends RequestHandler[SQSEvent, String] with Logging {
implicit val ec: ExecutionContext =
actorSystem.dispatcher

object SNSDownstream extends Downstream {
private val msgSender = SNSBuilder
.buildSNSMessageSender(config, subject = "Sent from batcher")
override def notify(batch: Batch): Try[Unit] = msgSender.sendT(batch)
}

val downstream = config.getString("batcher.use_downstream") match {
case "sns" => SNSDownstream
case "stdio" => STDIODownstream
}

val f = PathsProcessor(
config.requireInt("batcher.max_batch_size"),
event.extractPaths,
Expand Down

0 comments on commit f7ecb34

Please sign in to comment.