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.

[feat] Dynamic jobs

See original GitHub issue

Hi, is there a way to create a dynamic set of jobs? How can I pass custom parameters to a job? I was wondering if a similar approach to the following one can be used…

const currencies = ['USD', 'EUR','GBP'];
const currencyJob = currency => () => {
// job
console.log(currency)
};

const jobs = currencies.map(currency => ({task: currencyJob(currency), interval: '2m'}));
const bree = new Bree({jobs});

// start...

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
corzanicommented, Nov 30, 2020

@tamaker When you create a task you need to specify also the workerData property.

    {
      name: 'task1',
      worker: {
        workerData: {
          foo: 'something',
          fie: 'something else'
        }
      }

Considering the case above you can retrieve those properties from your job (task1.js) using worker threads.

const { workerData } = require('worker_threads');
console.dir(workerData); // This is what you need

See https://nodejs.org/api/worker_threads.html#worker_threads_worker_workerdata

I did notice the following method when I was looking for an example (2 mins ago)… Check => https://github.com/breejs/bree#using-functions-for-jobs So, it seems you can specify a function… I didn’t even noticed that when I was reading the docs… my bad 😃

So currently you might have 2 ways to do it…

0reactions
tamakercommented, Nov 29, 2020

I did find a possible solution, workerData to pass parameters to the dynamically created job list. It would have been more “elegant” having functions but that would work well anyway. Thanks @ggb88

@corzani Can you share a rough example of how you’re achieving this? I’m exploring options along the same lines as your approach. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Industries Jobs, Employment in Louisiana | Indeed.com
Dynamic Industries jobs in Louisiana. 1,209 jobs. Cable Installation Technician. DCOMM, INC2.2. Alexandria, LA. $800 - $1,300 a week. Full-time +1.
Read more >
getsentry/sentry@884f9bf · GitHub - feat(dynamic-sampling)
Developer-first error tracking and performance monitoring - feat(dynamic-sampling): Improve log styling · getsentry/sentry@884f9bf.
Read more >
The Ultimate Guide to Dynamic Work | Okta
A Dynamic Work model allows employees, partners, and contractors to work wherever, whenever, and however they want. We launched Dynamic Work as a...
Read more >
Dynamic Sports Development Careers - AngelList
Dynamic Performance Insoles are the only product to provide active support , cushion, and gait control in one insole. Featuring FLEX ARCH patent...
Read more >
Dynamic Work | Spotify
Listen to Dynamic Work on Spotify. Artist · 30 monthly listeners. ... Featuring Dynamic Work. Dynamic Work Radio. Fans also like. In-Motion. Jobeth....
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