Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Replace existing queue item by singletonKey instead of discarding the new item?Β #548

@khromov

Description

@khromov

πŸ‘‹ We have a queue that works on incoming news articles. Sometimes, an updated version of an article comes in before we have time to process the old version. Since there is no longer a point in processing an old version of the article, we would like to discard the old entry (as long as it's not in active state already).

We can easily create a singletonKey by article id, but singletonKey appears to discard the new queue item rather than replacing the old one.

I've gone up and down in the docs but I don't see an option to configure this, and I also don't see any way to connect to the pg-boss SQL table directly. Perhaps it would be possible to expose the executeSql so we can easily make a query to check for existing jobs for the same article ID and cancel them? Something like:

 const findQuery = `
    SELECT id FROM pgboss.job 
    WHERE name = 'process-article' 
    AND state = 'created' 
    AND data->>'articleId' = $1`;
  
  // Using pg-boss's direct db access
  const { rows } = await boss.db.executeSql(findQuery, [articleId]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions