GithubHelp home page GithubHelp logo

[feat] Dynamic jobs about bree HOT 6 CLOSED

breejs avatar breejs commented on May 14, 2024
[feat] Dynamic jobs

from bree.

Comments (6)

corzani avatar corzani commented on May 14, 2024 3

@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...

from bree.

ggb88 avatar ggb88 commented on May 14, 2024

Just from my little investigation, would using bree.add(..) work?

from bree.

corzani avatar corzani commented on May 14, 2024

Just from my little investigation, would using bree.add(..) work?

Hi @ggb88 , first of all, thanks...
As far as I understood, add doesn't let you specify different parameters either. In my example, every job is started with different currencies because they are treated as a function and not as an external file dynamically loaded/required.
By adding a lazy approach you can execute your task only when you need them (like the current implementation) and at the same time having the best from a functional approach (parametrized jobs, lazy loading...). Let's say you have 1000 jobs, every job differs only by its parameters and not its implementation. How would you implement it with this current implementation?
Consider my example, if you have 1000 currencies that code would work, it's not optimal regarding the interval bit... but it's working.

from bree.

corzani avatar corzani commented on May 14, 2024

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

from bree.

fernandolguevara avatar fernandolguevara commented on May 14, 2024

@niftylettuce this could be a very useful/great feature for the library, there is a better way to do this?

from bree.

tamaker avatar tamaker commented on May 14, 2024

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!

from bree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.