constructor()

in notificationworkerlambda/cdk/lib/senderworker.ts [224:307]


  constructor(scope: App, id: string, props: GuStackProps) {
    super(scope, id, props)

    const senderTooFewInvocationsAlarmPeriodParam = new cdk.CfnParameter(this, "SenderTooFewInvocationsAlarmPeriodParam", {
      type: "Number",
      description: "How long until no execution is suspicious, in seconds"
    })

    const reservedConcurrencyParam = new cdk.CfnParameter(this, "ReservedConcurrency", {
      type: "Number",
      description: "How many concurrent execution to provision the lamdba with"
    })

    const buildIdParam = new cdk.CfnParameter(this, "BuildId", {
      type: "String",
      description: "build id from teamcity, the image should be tagged with this"
    })

    const alarmTopicArnParam = new cdk.CfnParameter(this, "AlarmTopicArn", {
      type: "String",
      description: "The ARN of the SNS topic to send all the cloudwatch alarms to"
    })

    const cleanerQueueArnParam = new cdk.CfnParameter(this, "CleanerQueueArnParam", {
      type: "String",
      description: "The ARN of the cleaner SQS queue"
    });

    const notificationEcrRepo =
      ecr.Repository.fromRepositoryAttributes(this, "NotificationLambdaRepository", {
        repositoryArn: cdk.Fn.importValue("NotificationLambdaRepositoryArn"),
        repositoryName: cdk.Fn.importValue("NotificationLambdaRepositoryName")
      })

    let sharedOpts = {
      imageRepo: notificationEcrRepo,
      buildId: buildIdParam.valueAsString,
      reservedConcurrency: reservedConcurrencyParam.valueAsNumber,
      alarmTopic: sns.Topic.fromTopicArn(this, 'AlarmTopic', alarmTopicArnParam.valueAsString),
      tooFewInvocationsAlarmPeriod: cdk.Duration.seconds(senderTooFewInvocationsAlarmPeriodParam.valueAsNumber),
      tooFewInvocationsEnabled: props.stage === 'PROD',
      cleanerQueueArn: cleanerQueueArnParam.valueAsString
    }

    let workerQueueArns: string[] = []

    const addWorker = (workerName: string, paramPrefix: string, handler: string, isBatchingSqsMessages: boolean = false, dailyAlarmPeriod: boolean = false, tooFewNotificationByTypeAlarms: boolean = false) => {
      let worker = new SenderWorker(this, workerName, {
        ...props,
        platform: workerName,
        paramPrefix: paramPrefix,
        handler: handler,
        isBatchingSqsMessages,
        ...sharedOpts,
        dailyAlarmPeriod: dailyAlarmPeriod,
        tooFewNotificationByTypeAlarms: tooFewNotificationByTypeAlarms,
      })
      workerQueueArns.push(worker.senderSqs.queueArn)
    }

    /*
     * add each of the worker lambdas, where each one handles a different
     * platform or app by talking to a different lambda handler function
     */

    addWorker("ios", "iosLive", "com.gu.notifications.worker.IOSSender::handleChunkTokens", false, false, true)
    addWorker("android", "androidLive", "com.gu.notifications.worker.AndroidSender::handleChunkTokens", true, false, true)
        // edition apps only send one notification a day in order to get content for that day
    addWorker("ios-edition", "iosEdition", "com.gu.notifications.worker.IOSSender::handleChunkTokens", false, true)
    addWorker("android-edition", "androidEdition", "com.gu.notifications.worker.AndroidSender::handleChunkTokens", false, true)

    addWorker("android-beta", "androidBeta", "com.gu.notifications.worker.AndroidSender::handleChunkTokens")

    /*
     * each worker has been assigned an SQS queue which, when written to, will
     * trigger it to send its notifications. Here, we export the list of worker
     * queue ARNs so that it can be used in other stacks, for example, Harvester
     * needs to give itself permission to write to these queues.
     */
    new cdk.CfnOutput(this, "NotificationSenderWorkerQueueArns", {
      exportName: "NotificationSenderWorkerQueueArns-" + this.stage,
      value: cdk.Fn.join(",", workerQueueArns)
    })
  }