-
Notifications
You must be signed in to change notification settings - Fork 5
/
Handler.scala
38 lines (32 loc) · 1.28 KB
/
Handler.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.gu.holidaystopprocessor
import java.time.LocalDate
import cats.implicits._
import com.amazonaws.services.lambda.runtime.Context
import com.gu.holiday_stops.Config
import io.circe.generic.auto._
import io.github.mkotsur.aws.handler.Lambda
import io.github.mkotsur.aws.handler.Lambda._
object Handler extends Lambda[Option[LocalDate], List[HolidayStopResponse]] {
/**
* @param processDateOverride
* The date for which relevant holiday stop requests will be processed.
* This is to facilitate testing.
* In normal use it will be missing and a default value will apply instead.
*/
override def handle(processDateOverride: Option[LocalDate], context: Context): Either[Throwable, List[HolidayStopResponse]] = {
Config() match {
case Left(msg) =>
Left(new RuntimeException(s"Config failure: $msg"))
case Right(config) =>
val result = HolidayStopProcess(config, processDateOverride)
ProcessResult.log(result)
result.overallFailure match {
case Some(failure) =>
Left(new RuntimeException(failure.reason))
case None =>
val (_, successfulZuoraResponses) = result.holidayStopResults.separate
Right(successfulZuoraResponses)
}
}
}
}