Class: Hyrax::UserStatImporter
- Inherits:
-
Object
- Object
- Hyrax::UserStatImporter
- Defined in:
- app/services/hyrax/user_stat_importer.rb
Overview
Cache work view, file view & file download stats for all users this is called by ‘rake hyrax:stats:user_stats’
Defined Under Namespace
Classes: UserRecord
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(options = {}) ⇒ UserStatImporter
constructor
A new instance of UserStatImporter.
-
#sorted_users ⇒ Object
Returns an array of users sorted by the date of their last stats update.
Constructor Details
#initialize(options = {}) ⇒ UserStatImporter
Returns a new instance of UserStatImporter.
8 9 10 11 12 13 14 15 16 17 |
# File 'app/services/hyrax/user_stat_importer.rb', line 8 def initialize( = {}) if [:verbose] stdout_logger = Logger.new(STDOUT) stdout_logger.level = Logger::INFO Hyrax.logger.extend(ActiveSupport::Logger.broadcast(stdout_logger)) end @logging = [:logging] @delay_secs = [:delay_secs].to_f @number_of_tries = [:number_of_retries].to_i + 1 end |
Instance Method Details
#import ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/hyrax/user_stat_importer.rb', line 21 def import ('Begin import of User stats.') sorted_users.each do |user| start_date = date_since_last_cache(user) # this user has already been processed today continue without delay next if start_date.to_date >= Time.zone.today stats = {} process_files(stats, user, start_date) process_works(stats, user, start_date) create_or_update_user_stats(stats, user) end ('User stats import complete.') end |
#sorted_users ⇒ Object
Returns an array of users sorted by the date of their last stats update. Users that have not been recently updated will be at the top of the array.
40 41 42 43 44 45 46 |
# File 'app/services/hyrax/user_stat_importer.rb', line 40 def sorted_users users = [] ::User.find_each do |user| users.push(UserRecord.new(user.id, user.user_key, date_since_last_cache(user))) end users.sort_by(&:last_stats_update) end |