You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
561 B

1 year ago
1 year ago
1 year ago
1 year ago
  1. class ApplicationController < ActionController::Base
  2. MAX_DURATION_TO_COMPLETE_IN_SECONDS = 3
  3. around_action do |_, action|
  4. start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  5. begin
  6. action.call
  7. ensure
  8. ActionView::Base.logger.level = :info
  9. duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
  10. if duration > MAX_DURATION_TO_COMPLETE_IN_SECONDS
  11. logger.warn("processing took too long to complete, please review your code as asynchronous job!", duration: duration * 1_000)
  12. end
  13. end
  14. end
  15. end