Skip to content

Commit

Permalink
use env var for concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Holifield committed Sep 17, 2024
1 parent bfd2f0d commit 3cf575d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions deploy/clowdapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ parameters:
- description: Retention time span for pdf in MS (8 hours default)
name: ENTRY_TIMEOUT
value: "28800000"
- description: Amount of worker threads that puppeteer-cluster will use
name: MAX_CONCURRENCY
value: 2
8 changes: 7 additions & 1 deletion src/common/pdfCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,21 @@ class PdfCache {
return [];
}

// Function to sort PDFComponents by order
// Sort the components by their internal `order` and
// return the sorted components in ascending order
private sortComponents(components: PDFComponent[]): PDFComponent[] {
// No point in sorting a slice of length 1
if (components.length < 2) {
return components;
}
return components.slice().sort((a, b) => {
const orderA = a.order || Number.MAX_VALUE;
const orderB = b.order || Number.MAX_VALUE;

return orderA - orderB;
});
}

private updateCollectionState(
collectionId: string,
status: PdfStatus,
Expand Down
3 changes: 2 additions & 1 deletion src/server/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const BROWSER_TIMEOUT = 60_000;
import { CHROMIUM_PATH } from '../browser/helpers';

export const GetPupCluster = async () => {
const CONCURRENCY_DEFAULT = 2;
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 3,
maxConcurrency: Number(process.env.MAX_CONCURRENCY) || CONCURRENCY_DEFAULT,
// If a queued task fails, how many times will it retry before returning an error
retryLimit: 2,
puppeteerOptions: {
Expand Down

0 comments on commit 3cf575d

Please sign in to comment.