Error setting up jsreport local in an azure function on a linux machine



  • 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



  • I'm not sure where the error originated, however, I would recommend running the azure function with node.js runtime. Its a natural environment for jsreport and we have also dedicated tutorial for it here
    https://jsreport.net/learn/azure-functions-serverless
    Would this work for you?



  • I wanted to achieve the exakte behavior as in the node.js example but in a .net core environment with the jsreport binaries, local client and azure function. So you have also no experience or example with such a setup? Because when I start the azure function locally on my windows machine it is working.
    Is there any possibility in the node.js example to point to the /data file stored in a blob storage? If yes can you give me a short example?



  • I looked better at the error Object.execute (/snapshot/jsreport/node_modules/jsreport-static-pdf/lib/main.js:43:39) and it seems you are using static-pdf recipe, but the template doesn't have an asset with pdf associated. Could you double-check it?

    Is there any possibility in the node.js example to point to the /data file stored in a blob storage?

    You should be able to reach the same with nodejs as with c#.
    The jsreport.Binary embeds inside compiled jsreport sources into a modified node.js executable which gets extracted during the startup and jsreport.Local communicates with it using the command line. And this whole runs with .net at the top. You see there is quite many levels of boundaries. This makes sense only if you want a quick win and embed jsreport into the existing .net app. It doesn't make so much sense when you want to run a standalone serverless function.



  • As in the code example I'm using "Recipe = Recipe.ChromePdf" and no staticPDF recipe. And locally on my windows machine the rendering with the azure function in .net is working fine. If I switch there to "staticPDF" then I get the same error as on the linux machine on the azure cloud. So it seams there the chromepdf is somehow ignored or a fallback goes to staticPDF?

    Another question: I tried running the node.js example on a static azure plan (OS: linux, Plan: (B1: 1)) and I get the following error:

    Error: Failed to launch chrome!
    [0330/091143.853361:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
    
    
    TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
    
    at onClose (/home/site/wwwroot/node_modules/puppeteer/lib/Launcher.js:348:14)
    at Interface.<anonymous> (/home/site/wwwroot/node_modules/puppeteer/lib/Launcher.js:337:50)
    at Interface.emit (events.js:326:22)
    at Interface.close (readline.js:416:8)
    at Socket.onend (readline.js:194:10)
    at Socket.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
    

    On a consumption Azure plan, as it is mentioned in the example, this is working. Has someone any idea?


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.