I'm want to run jsreporting with local reporting in an azure function for scalability.
My function code is:
[FunctionName("PDFCreator")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ExecutionContext context)
{
Report report = null;
try
{
var reportingService = new LocalReporting()
.UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
jsreport.Binary.JsReportBinary.GetBinary() :
jsreport.Binary.Linux.JsReportBinary.GetBinary())
.KillRunningJsReportProcesses()
.AsUtility()
.Create();
var report = await reportingService.RenderAsync(new RenderRequest()
{
Template = new Template()
{
Content = "<span>hello {{:Message}}</span>",
Engine = Engine.Handlebars,
Recipe = Recipe.ChromePdf
},
Data = new { Message = "world" }
});
report.Content.Position = 0; //resets stream
var fileStream = new FileStreamResult(report.Content, "application/pdf");
return fileStream;
}
catch (Exception ex)
{
}
}
used jsreport packages:
- jsreport.binary.linux 2.11
- jsreport.binary 2.11 (for locally windows machine)
- jsreport.local 2.3.1
If I start the azure function locally on a windows machine it is working fine.
Now I deployed the function into an azure function app on a linux machine.
- Operatin system: linux
- Plan B1:1 mode basic
But I get an error: Rendering does not finish and gets an error after 4 min.
Error rendering report: instance has been daemonized and initialized successfully (pid: 93)rendering has finished with errors:A critical error occurred while trying to execute the render command (2). Cannot read property 'pdfAsset' of undefined (1). caused by error (2):-> stackError: at onCriticalError (/snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:302:19) at /snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:256:14 at processTicksAndRejections (internal/process/task_queues.js:97:5)caused by error (1):-> stackError: at Client.render (/snapshot/jsreport/node_modules/jsreport-client/lib/client.js) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async startRender (/snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:319:24) at async /snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:226:22 at async Commander.executeCommand (/snapshot/jsreport/node_modules/jsreport-cli/lib/commander.js:242:22)Remote stack: TypeError: at Object.execute (/snapshot/jsreport/node_modules/jsreport-static-pdf/lib/main.js:43:39) at invokeRender (/snapshot/jsreport/node_modules/jsreport-core/lib/render/render.js:99:17) at async /snapshot/jsreport/node_modules/jsreport-core/lib/render/render.js:150:5
trace:
"at jsreport.Local.Internal.LocalUtilityReportingService.RenderAsync(String requestString, CancellationToken ct)",
"at ESEC.QueueWorker.DataAccess.PDFCreator.RenderHelloWorld() in C:\Users\hg\Documents\Git\Queue-Worker\ESEC.QueueWorker.Functions\PDFCreator.cs:line 82",
"at ESEC.QueueWorker.DataAccess.PDFCreator.Run(HttpRequest req, ExecutionContext context) in C:\Users\hg\Documents\Git\Queue-Worker\ESEC.QueueWorker.Functions\PDFCreator.cs:line 48"
Am I doing something wrong with my setup?
Thanks