question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Job upsert

See original GitHub issue

Hi all,

I am attempting to use BullMQ to debounce an event stream on the trailing edge using delayed jobs. The debounce window can vary depending on the use case (from several seconds to months).

My first shot at this was to use job.name as a key to group jobs that correspond to the same window. Here is some pseudo code for a job scheduler:

// get all delayed jobs with the same name
// should never return length > 1 😄 
const [delayedJob] = await queue
  .getDelayed()
  .then((jobs = []) => jobs.filter((j) => j?.name === jobName))

if (delayedJob) {
  await job.remove()
}

await queue.add(jobName, jobData, {
  delay: jobDelay
})

Obviously this approach does not guarantee an atomic read+remove+add operation, and my test cases definitely repro race conditions when experiencing high stream throughput (i.e. > 1 delayedJob is present in the queue). I want to preserve the trailing edge since it contains most recent jobData state, so it’s critical that the last event is queued.

Maybe a less transient approach could be read+update / read+add but there is currently no way to update the delay. There is an open issue in bull for this https://github.com/OptimalBits/bull/issues/1733

I assume this feature will require lua scripting, but I have zero experience there and very minimal experience with Redis data structures in general.

If there is an alternative approach or advice on tackling the lua script I would be happy to hear/discuss it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
manastcommented, Nov 26, 2020

@jamesholcomb ok, so you mean that if the the job has started is because the debounce window has “expired” and now adding would imply adding a new job whereas the one that has started will continue normally until completion?

0reactions
jamesholcombcommented, Nov 26, 2020

Yes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request: Upsert · Issue #139 · ent/ent - GitHub
Is it possible to have atomic upsert functionality similar to postresql's INSERT ON CONFLICT or mysql's INSERT ON DUPLICATE KEY UPDATE ...
Read more >
Upsert in SQL: What is an upsert, and when should you use ...
The UPSERT command in CockroachDB performs an upsert based on the uniqueness of the primary key column or columns, and it will perform...
Read more >
Upsert Feature in API - Planview Customer Success Center
Send a PUT HTTP request, and if it fails, send a POST http request. You can read more about the operation in our...
Read more >
What Is a Feature Request? Definition and Examples - Airfocus
If your product is an app, then the new features might come in the form of an app update. If it's a physical...
Read more >
7 Useful Tips to Manage Feature Requests - Craft.io
For example, if the feature is in the backlog and you are planning to develop it in the next quarter, update them. Communication...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found