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

Question: What would be the best way to push thousands of jobs at once? #81

Closed
bcgianni opened this issue Jan 13, 2023 · 2 comments
Closed
Labels
question Further information is requested

Comments

@bcgianni
Copy link

Not sure if batch would be the way to go though.

@alachaum
Copy link
Member

Hey @bcgianni ! I've been digging into the Cloud Tasks API docs (both REST and gRPC) once again and it seems that Cloud Task does not provide a way to create tasks in bulk at this stage.

The batch capability of Cloudtasker won't really give you an edge here considering it enqueues jobs sequentially.

From there you have several options:

Option 1: sequential enqueuing
Assuming you have an array of [WorkerClass, args], you can simply do something like this:

job_list.each { |(klass, args)| klass.perform_async(*args) }

If you prefer you can also initialize the workers with MyWorker.new(job_args: args) then invoke schedule on them.

job_list.each(&:schedule)

Option 2: use a gem like parallel
Taking the first example above, you should be able to do:

Parallel.each(job_list) { |(klass, args)| klass.perform_async(*args) }

I haven't tried it but it should work just fine. In any case, feel free to reply here with any issue you find!

@alachaum alachaum added the question Further information is requested label Jan 19, 2023
@bcgianni
Copy link
Author

Thank you @alachaum for the answer, that is exactly the way we went with, and it has worked pretty well actually.

Phenomenal job on the lib and documentation btw, we didn't have any issues to have it rolling in just a few days.

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