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.

How to control the speed of performing a job

See original GitHub issue

I need to make a request to an API, but the API limits the speed of requests to 10 per sec. when the redis queue A has 1000 jobs called jobB to perform, how to control the speed of performing the job, or performing it at a constant speed, e.g. 10 jobs per second.

  const jobs = {
    jobB: {
      plugins: ["JobLock"],
      pluginOptions: {
        JobLock: {}
      },
      perform: async (a, b) => {
        // request a api
      }
    }
  };

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
juneappcommented, Aug 2, 2020

Hi @evershy can you provide me with your final RateLimit version? Thanks a lot and best regards Henning

1reaction
evantahlercommented, Mar 13, 2020

At a quick glance that looks a good stat! Be sure to write some tests for it.

There’s a race condition you can get into where you read the key (it has a value of 9) and by the time you write back to it, another worker has started the 10th job before this worker did. You can use watch to prevent this - https://redis.io/topics/transactions#optimistic-locking-using-check-and-set

Here’s an example of the node-resque scheduler using watch to precent a command if someone else changes the key https://github.com/actionhero/node-resque/blob/master/src/core/scheduler.ts#L268-L280

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Get an Employee to Work Faster
Confront them with data on how they are slow compared to others. · Leave it all to them to make changes to their...
Read more >
5 Ways to Speed Up Employee Work Execution | Smartsheet
Start by listening. Sit down with the employee and ask how they feel about the pace of their performance. Focus on listening to...
Read more >
How To Work Faster (With Tips and Examples) | Indeed.com
1. Use a timer while you work ... You can use a timer or a stopwatch to track how long you work on...
Read more >
4 Ways to Speed Up Your Productivity and Work - Cflow
1. Sharpen your focus: ... Narrowing down your focus on work-related stuff helps in increasing productivity. Steering clear from distractions and ...
Read more >
Speed Up Your Productivity By Slowing Down Your Work Habits
Here's a better strategy: Work slowly. Yes, you should tackle your in-box aggressively. But from a place of stillness that you must consciously ......
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