I've used something like this in the past:
SLEEP_WINDOW = 60 * 1 # minutes
csv_array.each_slice(10) do |chunk|
start_time = Time.now
chunk.each do |x|
make_api_call(x)
end
sleep_time = SLEEP_WINDOW - (Time.now - start_time)
sleep sleep_time if (sleep_time > 0)
end
The assumption is it's OK to blast through the chunks, then any remaining delay time will case the code to sleep. If the API calls took over a minute the code will loop immediately.