I'm not going to paste any code here because it looks like you're pretty familiar with how jobs should be written but think about the following idea:
You should have a resque job which gets and array of ids to process. This resque jobs creates a single resque job for each of the ids so they will be processed in parallel. After creating the resque jobs for specific ids it will create another resque jobs which gets the list of ids and periodically checks on them to see if they're finished. When they're done, this job will send the user an email.
With this paradigm you enjoy all of the worlds:
- Each ID has its own job.
- Parallel execution.
- Status check is done on the background thus the user won't get timeout.
UPDATE:
A pseudo code for the check resque job:
class CheckerJob
@queue = :long
def self.perform(ids)
finished = []
while finished.size < ids.size
ids.each do |id|
finished << id if job_finished?(id)
end
sleep 10
end
send_email_to_user
end
end
Now all you left to do is to implement both job_finished?(id)
and send_email_to_user
methods.