Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with simple example #15

Open
sabativi opened this issue Sep 24, 2022 · 2 comments
Open

Help with simple example #15

sabativi opened this issue Sep 24, 2022 · 2 comments
Labels
question Further information is requested

Comments

@sabativi
Copy link

Hello,

I am currently using https://github.com/msavin/SteveJobs for handling jobs, but I have one intensive CPU jobs that I want to be able to move to this package.
This job is simple, it just call a meteor method with some params.

I have read the blog article, forum thread and README, but is is unclear to me what to do, is there any way you can make an example so that I can relate to ?

Thanks

@nathanschwarz nathanschwarz added the question Further information is requested label Sep 24, 2022
@nathanschwarz
Copy link
Owner

Hello, sure a simple example would be :

import { Meteor } from 'meteor/meteor'
import { Cluster, TaskQueue } from 'meteor/nschwarz:cluster'

function computeSomeHeavyThings(x) {
    const computedValue = 36 + x
    // you can also fetch from any collection here or call a meteor method
    return computedValue
}

const taskMap = {
    'MyHeavyJob': job => computeSomeHeavyThings(job.data.x),
}

function onJobsDone({ value, task }) {
    console.log(value) // 36 + (3 * 6 * 8) => 180
}

const cluster = new Cluster(taskMap)
Meteor.startup(() => {
    if (Cluster.isMaster()) {
        TaskQueue.addEventListener('done', onJobsDone)
        TaskQueue.addTask({ taskType: 'MyHeavyJob', data: { x: 3 * 6 * 8 }})
    }
})

@sabativi
Copy link
Author

Thank you so much, I had this feeling that this was simple to set up, but could not grasp it ! Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants