bandwidth management with rails?

前端 未结 1 1304
猫巷女王i
猫巷女王i 2021-02-06 14:01

I was wondering if anyone knew of a way that you could manage bandwidth within a rails application in some way that isn\'t dependent on the web server. For example each account

相关标签:
1条回答
  • 2021-02-06 14:31

    One option would be to add an after_filter in application.rb (so that it applies to all actions) and do the following:

    def store_bandwidth_usage
       response_size = response.body.size
       # Assuming the User model has a bandwidth_usage attribute
       @current_user.increment!(:bandwidth_usage, response_size) 
    end
    

    Of course then you would need a before_filter which checked that a user had not gone over their allocated bandwidth otherwise they should be denied access.

    Keep in mind that this will only be counted for requests that hit the rails server, any requests that are filled by an front-end server (e.g. images) will not be included.

    0 讨论(0)
提交回复
热议问题