Skip to content

Commit

Permalink
fix: PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
dzehnder committed Oct 19, 2023
1 parent 83e34ce commit 2f90385
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { logger } from '@adobe/helix-universal-logger';
import { helixStatus } from '@adobe/helix-status';
import DB from './db.js';
import PSIClient from './psi-client.js';
import { queueWrapper } from './queue-wrapper.js';
import queueWrapper from './queue-wrapper.js';

/**
* This is the main function
Expand All @@ -25,13 +25,13 @@ import { queueWrapper } from './queue-wrapper.js';
*/
async function run(request, context) {
const db = DB({
region: process.env.REGION,
region: context.env.REGION,
});
const { message } = JSON.parse(context.invocation.event.Records[0].body);

const psiClient = PSIClient({
apiKey: process.env.PAGESPEED_API_KEY,
baseUrl: process.env.PAGESPEED_API_BASE_URL,
apiKey: context.env.PAGESPEED_API_KEY,
baseUrl: context.env.PAGESPEED_API_BASE_URL,
});

const site = {
Expand Down
11 changes: 3 additions & 8 deletions src/queue-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@

import SqsQueue from './sqs-queue.js';

function queueWrapper(func) {
export default function queueWrapper(func) {
return async (request, context) => {
const region = process.env.AWS_REGION;
const queueUrl = process.env.AUDIT_RESULTS_QUEUE_URL;
const region = context.env.AWS_REGION;
const queueUrl = context.env.AUDIT_RESULTS_QUEUE_URL;
const { log } = context;

if (!region) {
throw new Error('AWS_REGION env variable is empty/not provided');
}
if (!queueUrl) {
throw new Error('AUDIT_RESULTS_QUEUE_URL env variable is empty/not provided');
}
Expand All @@ -32,5 +29,3 @@ function queueWrapper(func) {
return func(request, context);
};
}

export default queueWrapper;
4 changes: 1 addition & 3 deletions src/sqs-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs';

let sqsClient;

function SQSQueue(region, queueUrl, log) {
export default function SQSQueue(region, queueUrl, log) {
if (!sqsClient) {
sqsClient = new SQSClient({ region });
log.info(`Creating SQS client in region ${region}`);
Expand Down Expand Up @@ -41,5 +41,3 @@ function SQSQueue(region, queueUrl, log) {
}
return { sendAuditResult };
}

export default SQSQueue;

0 comments on commit 2f90385

Please sign in to comment.