I would like to implement irregular batch processing (only when the request was made).(Use a gem like whenever.)

Asked 2 months ago, Updated 2 months ago, 2 views

We would like to implement the following batch processing.
However, it is not a regular thing like once a day, but only when a request is made.
Therefore, on many days, batch processing may run five times a day, or on the contrary, it may not run once a day.

 Enter the date and time you want to run from the screen and submit a request
↓
Batch processing starts at that time of day


To achieve periodic batch processing in Rails whenever seemed good.

However, as mentioned above, I was not sure what kind of design I should use to achieve irregular batch processing.

Also, I thought about how to register with cron every hour to check if there is a request or not, but I think it's not a very good design, so if there's any other good way, I'd like to design based on it.

Thank you for your cooperation.

以下 I would like to make it happen with the following image.

#params[:batch_requests] contains multiple dates and times

every params [:batch_requests] do
  rake'my:rake:task'
end

Also, I have a question for you.
Thank you for your understanding.
https://teratail.com/questions/42781

ruby-on-rails ruby

2022-09-30 11:51

1 Answers

I would use ActiveJob.

As an image, this is what it looks like.

class BatchController <ApplicationController
  def create(batch_at)
    BatchJob.set(wait_until:batch_at).perform_later
  end
end

Since whenever is cron, I don't think it's suitable for irregular execution, but I wonder what it is like.


2022-09-30 11:51

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.