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

Attempt to overwrite Cluster Queue not working #554

Open
dainguyenvie opened this issue Jan 18, 2025 · 0 comments
Open

Attempt to overwrite Cluster Queue not working #554

dainguyenvie opened this issue Jan 18, 2025 · 0 comments

Comments

@dainguyenvie
Copy link

dainguyenvie commented Jan 18, 2025

This is not an actual issue but more like a question
I am trying to overwrite the default behavior of cluster.queue(data , taskFunction)
by extending the Class Queue and modifying the push() method

but its not working :(
Can you please spot anything i did wrong ?

Thanks alot

import Queue from 'puppeteer-cluster/dist/Queue.js'
import { Cluster } from 'puppeteer-cluster'

class CustomQueue extends Queue.default {
    constructor() {
        super()
    }

    #smartQueue(item) {
        if (item.data?.priority) {
            const index = this.list.findIndex(job => job.data?.pid === item.data?.pid)

            if (index !== -1) {
                this.list.splice(index, 1)
            }

            this.list.unshift(item)
        } else {
            this.list.push(item)
        }
    }

    push(item, options = {}) {
        if (options && options.delayUntil && options.delayUntil > Date.now()) {
            this.delayedItems += 1;
            setTimeout(() => {
                this.delayedItems -= 1;
                this.#smartQueue(item);
            }, (options.delayUntil - Date.now()));
        }
        else {
            this.#smartQueue(item);
        }
    }
}

class CustomCluster extends Cluster {
    constructor(options) {
        super(options)
        this.jobQueue = new CustomQueue()
    }
}
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

1 participant