Skip to content

Commit

Permalink
chore: update based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Schwitter committed Sep 9, 2024
1 parent f1bd740 commit 871d2de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
6 changes: 3 additions & 3 deletions load-test/boom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function main(): Promise<void> {
createCP(),
createCP(),
]);
console.log(`block ${i} done`);
console.log(`\nblock ${i} done`);
}
}

Expand All @@ -48,13 +48,13 @@ async function createCP(): Promise<void> {

const startTime = Date.now();
const fetchOptions: RequestInit = requestFetchOptions();
console.log(`calling CP`);
process.stdout.write(".");
response = await fetch(targetUrl + 'document-generation', {
...fetchOptions,
});
const endTime = Date.now();
const a = endTime - startTime;
console.log(`CP create finished; time taken: ${a}ms`);
process.stdout.write(`\nCP create finished; time taken: ${a}ms`);
const contentType = response.headers.get("content-type") ?? '';

if (response.status >= 200 && response.status < 300) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ public class GeneratorFunction
private readonly PdfGenerator _generator;
private readonly ILogger _logger;

static GeneratorFunction()
static GeneratorFunction()
{
var logger = Logger.Create<GeneratorFunction>();
logger.LogDebug("Static Generator Function triggered");
PdfGenerator.InitializeIronPdf(logger);

AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

logger.LogDebug("Static Generator Function finished.");
}

Expand Down Expand Up @@ -83,6 +86,11 @@ public APIGatewayProxyResponse DocumentGeneratorHandler(APIGatewayProxyRequest r
IsBase64Encoded = false
};
}
finally
{
//enable this to fix the issue.
//GC.Collect();
}
}
private static ServiceProvider BuildServiceProvider()
{
Expand All @@ -96,5 +104,18 @@ private static ServiceProvider BuildServiceProvider()

return serviceCollection.BuildServiceProvider();
}

static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
try
{
var logger = Logger.Create<GeneratorFunction>();
logger.LogError("Unhandled Exception: {Exception}", e.ExceptionObject);
}
catch
{
//to nothing since we can't log
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public PdfGenerator(DocumentGenerationSettings documentGenerationSettings, ILogg
RenderingOptions =
{
UseMarginsOnHeaderAndFooter = UseMargins.None,
CreatePdfFormsFromHtml = true
CreatePdfFormsFromHtml = true,

}
};

Expand All @@ -36,8 +37,8 @@ public static void InitializeIronPdf(ILogger logger)
//add additional Iron Pdf logging when debug level is set
if (logLevel == "Debug")
{
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
IronPdf.Logging.Logger.CustomLogger = logger;
// IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
// IronPdf.Logging.Logger.CustomLogger = logger;
}

// we configure the dependencies ourselves in the Dockerfile
Expand All @@ -50,12 +51,13 @@ public static void InitializeIronPdf(ILogger logger)
Environment.SetEnvironmentVariable("TEMP", awsTmpPath, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("TMP", awsTmpPath, EnvironmentVariableTarget.Process);
Installation.TempFolderPath = awsTmpPath;
Installation.CustomDeploymentDirectory = awsTmpPath;

Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
Installation.ChromeBrowserCachePath = awsTmpPath;
Installation.CustomDeploymentDirectory = awsTmpPath;

Installation.ChromeBrowserLimit = 1;
Installation.SingleProcess = true;

Installation.Initialize();
}

Expand Down

0 comments on commit 871d2de

Please sign in to comment.