Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding timeout and styling for a ChromePdf recipe #867

Closed
NN89 opened this issue Jan 27, 2022 · 1 comment
Closed

Adding timeout and styling for a ChromePdf recipe #867

NN89 opened this issue Jan 27, 2022 · 1 comment

Comments

@NN89
Copy link

NN89 commented Jan 27, 2022

I have a rather complicated html code in the view and the report needs a longer time than the default 30 seconds to generate the structure. I'm using JSReport version 2.7.1. Initially, I tried modifying the jsreport.config.json file from "chrome": { "timeout": 180000 } to a very big number but that did not work.

And so ,I have been trying to extend jsreport timeout and here is where I am at.

 HttpContext.JsReportFeature()
            .Recipe(Recipe.ChromePdf)
            .Configure((r) => r.Template.Chrome = new Chrome
            {
                Landscape = true,
                Format = "Legal",
                HeaderTemplate = header,
                FooterTemplate = footer,
                DisplayHeaderFooter = true,
                MarginTop = "95px",
                MarginLeft = "20px",
                MarginRight = "20px",
                MarginBottom = "40px"
            }
            )
            .Configure((r) => r.Options = new jsreport.Types.RenderOptions
             {
                 Timeout = 600000
             });

In the above case the styling works but the timeout is not implemented. However if i reverse the order of the configure and put the timeout first and the styling next, the timeout works but not the styling.

I have also tried the below method and even here it's either a case of report loading without the style or timing out with the error "JsReportBinaryException: Error rendering report: starting rendering process..rendering has finished with errors:A critical error occurred while trying to execute the render command (2). Timeout Error: pdf generation not completed after 30000ms (1). caused by error (2):-> stackError: at onCriticalError (D:\snapshot\jsreport\node_modules\jsreport-cli\lib\commands\render.js:302:19) at D:\snapshot\jsreport\node_modules\jsreport-cli\lib\commands\render.js:298:12caused by error (1):-> meta = {"workerTimeout":true,"logged":true}-> stackError: at Timeout. (D:\snapshot\jsreport\node_modules\jsreport-chrome-pdf\lib\conversion.js:293:19) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7)"

 HttpContext.JsReportFeature()
 .Recipe(Recipe.ChromePdf)
 .Configure(cfg =>
 {
     cfg.Options = new RenderOptions
     {
         Timeout = 600000
      };
      cfg.Template.Chrome = new Chrome
      {
                     Landscape = true,
                     Format = "Legal",
                     HeaderTemplate = header,
                     FooterTemplate = footer,
                     DisplayHeaderFooter = true,
                     MarginTop = "95px",
                     MarginLeft = "20px",
                     MarginRight = "20px",
                     MarginBottom = "40px",
                     PrintBackground = true
      };                     
      })

Is there a way I can combine both and have both working?

@pofider
Copy link
Contributor

pofider commented Jan 31, 2022

It should have nothing to do with the order you call Configure.
However, there are two approaches to configure timeout.

You can set it globally for the whole instance.

 services.AddJsReport(new LocalReporting()
                .UseBinary(JsReportBinary.GetBinary())
                .Configure(cfg =>
                {
                    cfg.ReportTimeout = 600000;                    
                    return cfg;
                })
                .KillRunningJsReportProcesses()
                .AsUtility()
                .Create());

Or you can set the timeout for a particular request as you are trying to do, but in this case, you need to opt in the configuration when starting jsreport

services.AddJsReport(new LocalReporting()
                .UseBinary(JsReportBinary.GetBinary())
                .Configure(cfg =>
                {                    
                    cfg.EnableRequestReportTimeout = true;
                    return cfg;
                })
                .KillRunningJsReportProcesses()
                .AsUtility()
                .Create());

Then you can pass the Options.Timeout and it gets applied

 HttpContext
                .JsReportFeature()
                .Recipe(Recipe.ChromePdf)               
                .Configure((r) => r.Options = new jsreport.Types.RenderOptions
                {
                    Timeout = 600000
                });

@pofider pofider closed this as completed Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants