pofider / phantom-html-to-pdf

Highly scalable html to pdf conversion using phantom workers
MIT License
159 stars 33 forks source link

knowing when the PDF has finished to generate #61

Closed rich25200 closed 7 years ago

rich25200 commented 7 years ago

Hi,

I have a file system watcher that watch a folder. When a file is detected, I read the file and I convert it into PDF with phantom-html-to-pdf.

My concern is when too many files is handled, Phantomsjs crashs.

I would like tell at phantomjs to manage a maximum 20 files for exemple. Is it possible?

Or would you advise me how I can make this without this error?

Thanks

bjrmatos commented 7 years ago

hi @rich25200 , if you are experimenting problems with the maximum amount of files that phantomjs can process just implement a basic limit in your code:

// pseudo-code
var currentFilesProcessing = 0;
var MAX_CONCURRENT_FILES = 5;
var pendingFiles = [];

dir.on('watch', function (file) {
  pendingFiles.push(file);
});

setInterval(function () {
  if (currentFilesProcessing >= MAX_CONCURRENT_FILES || pendingFiles.length === 0) {
    return;
  }

  currentFilesProcessing++;

  startConversion(pendingFiles.shift(), function () {
    currentFilesProcessing--;
  });
}, 3000);

function startConversion(file, cb) {
  // ..use phantom-html-to-pdf here..
}

i'm afraid i can't help you more here, i'm going to close the issue since this is not a problem related with the library.