0

In cluster.task, I added some event like framenavigated with complex logic.

I use puppeteer-cluster in my API server, when request get in, adding in the queue, and workers do the job sequencely.

But every time request comes, framenavigated event register again with use of cpu.

How can I reuse event added page in workers?


I don't want to close event added page in cluster.task, and reuse in next request. Is it possible?

if can't, I would like to customize your library not to open/close pages at every request, would you please point where is the part of cluster.task's page open/close part?


EDIT : smaple code!

await cluster.task(async ({ page, data : url }) => {       
    /* 
        DO NOT WANT TO DO THIS EVENT REGISTERING JOB WITH EVERY REQUEST.
        ONLY WANT TO DO THIS ONCE, AND REUSE WITH NEXT `queue`, `execute` REQEUST COMES.
    */
    page.on("framenavigated", async () =>  {
            // Some complex job here.        
    })



    /* 
        WANT TO DO WITH EVERY REQUEST WITH REUSING EVENT REGISTERED `PAGE` 
        example : page jobs, I want to do this with every requests comes.
    */
    await page.goto(url)
    console.log(page.url())
})

I just want to reuse page object in cluster.task with framenavigated event registered.

Thank you. @ThomasDondorf

Yangha Koo
  • 17
  • 3

0 Answers0