Javier Valencia
Javier Valencia

Reputation: 695

ActiveJobs Queue

I have a RoR app with some model that need to do a provision to remote APIs. But in two of them, I need to do many provisioning HTTP requests and I use ActiveJob to this task.

The problem's what I need to maintain a creation order for these HTTP request, but ActiveJob doesn't.

How to process many async tasks with ActiveJob in a certain sequence?

Upvotes: 0

Views: 59

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230276

One way is to put those jobs on a special queue

class MyHttpJob < ApplicationJob
  queue_as :serial_creation
  #....
end

And have only one worker on that queue. No concurrency => automatic serialization. Of course, this has serious performance limitations. But if your one worker can handle the traffic, it's a good easy approach.

Upvotes: 1

Related Questions