Skip to content

Instantly share code, notes, and snippets.

@daniel-sim
Created February 2, 2021 11:08
Show Gist options
  • Save daniel-sim/c1d11e21ee5499dd81bbce7995bdb276 to your computer and use it in GitHub Desktop.
Save daniel-sim/c1d11e21ee5499dd81bbce7995bdb276 to your computer and use it in GitHub Desktop.
def throttle(start_time)
stop_time = Time.zone.now
processing_duration = stop_time - start_time
wait_time = (0.3 - processing_duration).round(1)
Rails.logger.info("THROTTLING: #{wait_time}")
sleep wait_time if wait_time > 0.0
Time.zone.now
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment