Despite the COVID-19 outbreak, our team continues operating at full speed. We are always here to support and answer all your questions.

Feel free to reach out by filling this quick form.

Fill the form
Get Free Trial

Flexmonster Headless Export

Scott Oliver asked on December 1, 2020

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.

2 answers

Illia Yatsyshyn Illia Yatsyshyn Flexmonster December 2, 2020

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:
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.

Scott Oliver December 3, 2020

Thank you for the assistance, works perfectly!

Please login or Register to Submit Answer