Skip to content

Commit

Permalink
WIP: writing the event data to the event table
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmw committed Mar 14, 2024
1 parent 67f7fb5 commit 7375884
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
16 changes: 12 additions & 4 deletions typescript/src/feast/pubsub/pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import { parsePayload, toSqsSubReference } from "../../pubsub/apple";
import { StatusUpdateNotification, parsePayload, toDynamoEvent, toSqsSubReference } from "../../pubsub/apple";
import { AppleSubscriptionReference } from "../../models/subscriptionReference";
import Sqs from 'aws-sdk/clients/sqs';
import { sendToSqs } from "../../utils/aws";
import { sendToSqs, dynamoMapper } from "../../utils/aws";
import { AWSError } from "aws-sdk";
import { PromiseResult } from "aws-sdk/lib/request";
import { HTTPResponses } from "../../models/apiGatewayHttp";
Expand All @@ -12,6 +12,11 @@ export async function handler(request: APIGatewayProxyEvent): Promise<APIGateway
return processEvent()(request)
}

function storeEventInDynamo(event: StatusUpdateNotification): Promise<void> {
const item = toDynamoEvent(event);
return dynamoMapper.put({ item }).then(_ => undefined);
}

export function processEvent(
sendMessageToSqs: (queueUrl: string, message: AppleSubscriptionReference) => Promise<PromiseResult<Sqs.SendMessageResult, AWSError>> = sendToSqs
): (request: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult> {
Expand All @@ -30,12 +35,15 @@ export function processEvent(
const queueUrl = process.env.QueueUrl;
if (queueUrl === undefined) throw new Error("No QueueUrl env parameter provided");

await sendMessageToSqs(queueUrl, appleSubscriptionReference)
await Promise.all([
sendMessageToSqs(queueUrl, appleSubscriptionReference),
storeEventInDynamo(statusUpdateNotification),
]);

return HTTPResponses.OK
} catch (e) {
console.error("Internal server error", e);
return HTTPResponses.INTERNAL_ERROR
}
}
}
}
5 changes: 3 additions & 2 deletions typescript/src/models/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export enum Platform {
IosEdition = "ios-edition",
AndroidEdition = "android-edition",
IosPuzzles = "ios-puzzles",
AndroidPuzzles = "android-puzzles"
}
AndroidPuzzles = "android-puzzles",
IosFeast = "ios-feast",
}
5 changes: 3 additions & 2 deletions typescript/src/services/appToPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {Platform} from "../models/platform";
const bundleToPlatform: {[bundle: string]: Platform} = {
"uk.co.guardian.iphone2": Platform.Ios,
"uk.co.guardian.gce": Platform.IosEdition,
"uk.co.guardian.puzzles": Platform.IosPuzzles
"uk.co.guardian.puzzles": Platform.IosPuzzles,
"uk.co.guardian.feast": Platform.IosFeast
};

export function fromAppleBundle(bundle?: string): Platform | undefined {
Expand All @@ -19,4 +20,4 @@ const packageToPlatform: {[packageName: string]: Platform} = {

export function fromGooglePackageName(packageName: string): Platform | undefined {
return packageToPlatform[packageName];
}
}

0 comments on commit 7375884

Please sign in to comment.