Skip to content

Commit

Permalink
move use case creation into handler body
Browse files Browse the repository at this point in the history
  • Loading branch information
lkostrowski committed Oct 15, 2024
1 parent 6bc38f4 commit b587642
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-apes-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-avatax": patch
---

Experimentally move creating dependencies (checkout-calculate-taxes) into handler body. This is a hypothesis that lambda will start up faster.
27 changes: 15 additions & 12 deletions apps/avatax/src/pages/api/webhooks/checkout-calculate-taxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ export const config = {
},
};

const logger = createLogger("checkoutCalculateTaxesSyncWebhook");

const withMetadataCache = wrapWithMetadataCache(metadataCache);

const subscriptionErrorChecker = new SubscriptionPayloadErrorChecker(logger, captureException);
const useCase = new CalculateTaxesUseCase({
configExtractor: new AppConfigExtractor(),
logWriterFactory: new LogWriterFactory(),
payloadLinesTransformer: new AvataxCalculateTaxesPayloadLinesTransformer(
new AvataxCalculateTaxesTaxCodeMatcher(),
),
calculateTaxesResponseTransformer: new AvataxCalculateTaxesResponseTransformer(),
});

const handler = checkoutCalculateTaxesSyncWebhook.createHandler(async (req, res, ctx) => {
const logger = createLogger("checkoutCalculateTaxesSyncWebhook");

/**
* Create deps in handler, so it's potentially faster and reduce lambda start
*/
const subscriptionErrorChecker = new SubscriptionPayloadErrorChecker(logger, captureException);
const useCase = new CalculateTaxesUseCase({
configExtractor: new AppConfigExtractor(),
logWriterFactory: new LogWriterFactory(),
payloadLinesTransformer: new AvataxCalculateTaxesPayloadLinesTransformer(
new AvataxCalculateTaxesTaxCodeMatcher(),
),
calculateTaxesResponseTransformer: new AvataxCalculateTaxesResponseTransformer(),
});

try {
const { payload, authData } = ctx;

Expand Down

0 comments on commit b587642

Please sign in to comment.