🍉 Meet Flexmonster Pivot Table & Charts 2.9.Check out all hot features!
Get Free Trial

Flexmonster Headless Export

Answered
Scott Oliver asked on December 1, 2020

Hello,
 
We have implemented your code for a headless export with puppeteer. We have also combined this with PM2, a service which can monitor a file for changes/failures.
 
To apply context, this provides us with the ability of swapping out the pivot.js file with differing data sources and slices in the set report section, looping through them one by one.
 
I realise that this may not be your domain, and will understand you turning me away, but I thought I would ask nonetheless.
 
Everything is working as expected with these two services (puppeteer and PM2) however, rather than waiting for the file to be updated, PM2 is continuously restarting, perhaps because of some code in the pivot.js file. Is there anyone who has experience with PM2 and puppeteer that I may speak to?
 
I have a stack overflow thread which I posted here if you are interested in taking a look at the code samples.

6 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster December 2, 2020

Hello,
 
Thank you for reaching out to us.
 
We tested our Puppeteer example under PM2 control on our side. It did manage to bring some light on the nature of the issue.
 
The --watch option mentioned on the StackOverflow thread monitors the directory for changes and restarts the process if any changes are noticed. In its turn, the pivot.js file generates and saves exported files within the directory.
It means the process will be restarted every time pivot.js saves the exported file to the storage folder. After the restart, pivot.js will try to save the file again. As a result, the infinite loop appears.
 
To avoid this behavior, we suggest configuring the ignore_watch parameter to exclude the storage folder from the list of observed directories:

pm2 start pivot.js --watch --ignore-watch="storage"

In this case, the storage folder will be ignored by PM2.
 
Another option is to create and adjust the configuration file: https://pm2.keymetrics.io/docs/usage/application-declaration/#generate-configuration.
Use it to store the configuration of the watch and ignore_watch options:

module.exports = {
apps : [{
script: 'pivot.js',
watch: '.',
ignore_watch : ["node_modules", "storage"]
}],
...
};

Start the process using the following command:

pm2 start ecosystem.config.js

Where ecosystem is a name of the JSON file with the configuration.
 
Please let us know if it works for you.
Feel free to contact us in case further questions arise.
 
Regards,
Illia

Public
Scott Oliver December 3, 2020

Thank you for the assistance, works perfectly!

Public
Scott Oliver June 9, 2021

I’m having some issues exporting to PDF with the attached javascript file.
 
Please note that when I have both lines 58 (export to PDF) and 61 (export to excel) live, it works. It will produce a PDF for me. However when I have just 58 live (which is my preference) no PDF report is generated.
 
This isn’t the exact file that we are using, because of the sensitivity of our data, but it should be a good indication of what we are working with (regarding the headless function).

Attachments:
pivot.js

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster June 10, 2021

Hello, Scott,
 
Thank you for posting on our forum.
 
We made an attempt to recreate the described issue. However, in our case, the PDF file seems to be successfully generated and saved. We prepared a screen record demonstrating this behavior (see attachments).
 
Do you think you could provide us with more details that would help us reproduce the issue? Maybe some steps to reproduce are missing in the mentioned screen record?
 
Looking forward to your reply.
 
Best regards,
Illia

Attachments:
exporting to pdf.gif

Public
Scott Oliver June 10, 2021

Hello,
 
Yes, you are correct, I apologise, I’m not sure why that wasn’t working for me.
 
On a side note, for that particular report (not others), the formatting is rather strange, perhaps you can help me understand why. I’ve attached the javascript file.

Attachments:
pivot.js

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster June 11, 2021

Hello, Scott,
 
We are happy to hear exporting works for you now.
 
Concerning the formatting, could you please specify what exact aspects of the exported grid seem strange to you?
 
Looking forward to your reply.
 
Best regards,
Illia

Please login or Register to Submit Answer