Managing loaner chromebooks for students and teachers in the HUUSD school district.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

STATS

+118 -73
-2
app/controllers/concerns/authenticatable.rb
··· 1 - # frozen_string_literal: true 2 - 3 1 module Authenticatable 4 2 extend ActiveSupport::Concern 5 3
+28 -10
app/models/authentication.rb
··· 7 7 # updated_at :datetime not null 8 8 # 9 9 class Authentication < ApplicationRecord 10 - # frozen_string_literal: true 11 - 12 10 # Track creation of an Authentication instance 13 - after_create :track_creation 11 + after_create :measure_creation 14 12 15 13 # Track destruction of an Authentication instance 16 - after_destroy :track_destruction 14 + after_destroy :measure_destruction 17 15 18 16 def initialize(session, user) 19 17 StatsD.increment("authentication.initialized") 20 - session[:current_authentication] = self 21 - @user_id = user.id 18 + StatsD.measure("authentication.initialization_time") do 19 + session[:current_authentication] = self 20 + @user_id = user.id 21 + end 22 22 end 23 23 24 24 def destroy(session) 25 25 StatsD.increment("authentication.destroyed") 26 - session[:current_authentication] = nil 27 - @user_id = nil 26 + StatsD.measure("authentication.destruction_time") do 27 + session[:current_authentication] = nil 28 + @user_id = nil 29 + end 28 30 end 29 31 30 32 def user 31 33 StatsD.increment("authentication.user_lookup") 32 - User.find_by(id: @user_id) 34 + StatsD.measure("authentication.user_lookup_time") do 35 + User.find_by(id: @user_id) 36 + end 33 37 end 34 38 35 39 def user=(user) 36 40 StatsD.increment("authentication.user_set") 37 - @user_id = user.id 41 + StatsD.measure("authentication.user_set_time") do 42 + @user_id = user.id 43 + end 38 44 end 39 45 40 46 private 41 47 48 + def measure_creation 49 + StatsD.measure("authentication.creation_time") do 50 + track_creation 51 + end 52 + end 53 + 42 54 def track_creation 43 55 StatsD.increment("authentication.created") 56 + end 57 + 58 + def measure_destruction 59 + StatsD.measure("authentication.destruction_time") do 60 + track_destruction 61 + end 44 62 end 45 63 46 64 def track_destruction
+28 -4
app/models/borrower.rb
··· 35 35 has_many :loans 36 36 validates :email, presence: true, student_email: true 37 37 38 - before_create :parse_email 39 - after_create :track_creation 40 - after_update :track_update 41 - after_destroy :track_destruction 38 + before_create :measure_parse_email 39 + after_create :measure_creation 40 + after_update :measure_update 41 + after_destroy :measure_destruction 42 42 43 43 def full_name 44 44 StatsD.increment("borrower.full_name_accessed") ··· 92 92 93 93 private 94 94 95 + def measure_parse_email 96 + StatsD.measure("borrower.parse_email_time") do 97 + parse_email 98 + end 99 + end 100 + 95 101 def parse_email 96 102 StatsD.increment("borrower.parse_email_started") 97 103 # Split the email address before the "@" symbol ··· 106 112 self.graduation_year = graduation_year 107 113 108 114 StatsD.increment("borrower.parse_email_completed") 115 + end 116 + 117 + def measure_creation 118 + StatsD.measure("borrower.creation_time") do 119 + track_creation 120 + end 109 121 end 110 122 111 123 def track_creation 112 124 StatsD.increment("borrower.created") 113 125 end 114 126 127 + def measure_update 128 + StatsD.measure("borrower.update_time") do 129 + track_update 130 + end 131 + end 132 + 115 133 def track_update 116 134 StatsD.increment("borrower.updated") 135 + end 136 + 137 + def measure_destruction 138 + StatsD.measure("borrower.destruction_time") do 139 + track_destruction 140 + end 117 141 end 118 142 119 143 def track_destruction
+35 -32
app/models/loan.rb
··· 33 33 validates :reason, presence: true 34 34 35 35 def extend 36 - StatsD.increment("loan.extended") 37 - self.due_date += 1.day 38 - self.save 36 + StatsD.measure("loan.extend_time") do 37 + StatsD.increment("loan.extended") 38 + self.due_date += 1.day 39 + self.save 40 + end 39 41 end 40 42 41 43 aasm :column => 'status' do ··· 49 51 transitions from: :pending, to: :out 50 52 51 53 after do 52 - StatsD.increment("loan.loaned") 53 - self.update(loaned_at: Time.now) 54 + StatsD.measure("loan.loan_time") do 55 + StatsD.increment("loan.loaned") 56 + self.update(loaned_at: Time.now) 54 57 55 - if self.reason == "device_repair" 56 - StatsD.increment("loan.reason.device_repair") 58 + if self.reason == "device_repair" 59 + StatsD.increment("loan.reason.device_repair") 57 60 58 - elsif self.reason == "charging" 59 - StatsD.increment("loan.reason.charging") 60 - self.update(due_date: Date.today + 2.hours) 61 + elsif self.reason == "charging" 62 + StatsD.increment("loan.reason.charging") 63 + self.update(due_date: Date.today + 2.hours) 61 64 62 - elsif self.reason == "forgot_at_home" 63 - StatsD.increment("loan.reason.forgot_at_home") 64 - self.update(due_date: Date.today + 1.day) 65 - else 66 - StatsD.increment("loan.reason.unknown") 67 - self.update(due_date: Date.today + 1.day) 68 - end 65 + elsif self.reason == "forgot_at_home" 66 + StatsD.increment("loan.reason.forgot_at_home") 67 + self.update(due_date: Date.today + 1.day) 68 + else 69 + StatsD.increment("loan.reason.unknown") 70 + self.update(due_date: Date.today + 1.day) 71 + end 69 72 70 - due_date_time = self.due_date.present? ? self.due_date.to_time : nil 73 + due_date_time = self.due_date.present? ? self.due_date.to_time : nil 71 74 72 - if due_date_time != nil 73 - DisableDeviceJob.set(wait_until: due_date_time).perform_later(self.id) 74 - # Schedule reminder jobs 75 - (1..7).each do |day| 76 - StatsD.increment("loan.reminder_job_scheduled", tags: ["day:#{day}"]) 77 - RemindBorrowerToReturnLoanerJob.set(wait_until: due_date_time + day.days).perform_later(self.id) 78 - end 79 - StatsD.increment("loan.borrower_unreturned_after_seven_days_job_scheduled") 80 - BorrowerUnreturnedAfterSevenDaysJob.set(wait_until: due_date_time + 8.days).perform_later(self.id) 81 - else 82 - Rails.logger.warn "Due date is nil for loan #{self.id}. DisableDeviceJob will not be scheduled." 75 + if due_date_time.present? 76 + StatsD.measure("loan.jobs_scheduling_time") do 77 + DisableDeviceJob.set(wait_until: due_date_time).perform_later(self.id) 78 + # Schedule reminder jobs 79 + (1..7).each do |day| 80 + StatsD.increment("loan.reminder_job_scheduled", tags: ["day:#{day}"]) 81 + RemindBorrowerToReturnLoanerJob.set(wait_until: due_date_time + day.days).perform_later(self.id) 82 + end 83 + StatsD.increment("loan.borrower_unreturned_after_seven_days_job_scheduled") 84 + BorrowerUnreturnedAfterSevenDaysJob.set(wait_until: due_date_time + 8.days).perform_later(self.id) 85 + end 86 + else 87 + Rails.logger.warn "Due date is nil for loan #{self.id}. DisableDeviceJob will not be scheduled." 88 + end 83 89 end 84 90 end 85 91 end 86 - 87 92 end 88 93 89 94 def log_status_change ··· 93 98 94 99 enum reason: { charging: 1, device_repair: 2, forgot_at_home: 3 } 95 100 96 - # if the loaner reason is set to device_repair then borrowed_device_repaired should be set to true when the loan is created (but not on save) 97 101 before_create :set_borrowed_device_repaired 98 102 99 103 def set_borrowed_device_repaired 100 104 self.borrowed_device_repaired = true if self.reason == "device_repair" 101 105 end 102 - 103 106 end
+13 -10
app/models/loaner.rb
··· 149 149 private 150 150 151 151 def set_loaner_id 152 - # Find the maximum current loaner_id 153 - max_id = Loaner.maximum(:loaner_id) || 0 154 - self.loaner_id = max_id + 1 155 - StatsD.increment("loaner.id_set") 152 + StatsD.measure("loaner.set_loaner_id_time") do 153 + max_id = Loaner.maximum(:loaner_id) || 0 154 + self.loaner_id = max_id + 1 155 + StatsD.increment("loaner.id_set") 156 + end 156 157 end 157 158 158 159 def assign_current_loan 159 - current_loan = loans.pending.first 160 - if current_loan 161 - self.current_loan_id = current_loan.id 162 - save! 163 - StatsD.increment("loaner.current_loan_assigned") 164 - current_loan.loan! 160 + StatsD.measure("loaner.assign_current_loan_time") do 161 + current_loan = loans.pending.first 162 + if current_loan 163 + self.current_loan_id = current_loan.id 164 + save! 165 + StatsD.increment("loaner.current_loan_assigned") 166 + current_loan.loan! 167 + end 165 168 end 166 169 end 167 170 end
+14
app/models/user.rb
··· 23 23 24 24 # Callbacks to track user creation and updates 25 25 after_create :track_user_creation 26 + around_create :measure_user_creation 26 27 after_update :track_user_update 28 + around_update :measure_user_update 27 29 28 30 validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP } 29 31 ··· 35 37 Rails.logger.info "User created: #{email}" 36 38 end 37 39 40 + def measure_user_creation 41 + StatsD.measure("user.creation_time") do 42 + yield 43 + end 44 + end 45 + 38 46 def track_user_update 39 47 StatsD.increment("user.updated") 40 48 if saved_change_to_role? 41 49 StatsD.increment("user.role_changed", tags: ["from:#{saved_change_to_role[0]}", "to:#{saved_change_to_role[1]}"]) 42 50 end 43 51 Rails.logger.info "User updated: #{email}" 52 + end 53 + 54 + def measure_user_update 55 + StatsD.measure("user.update_time") do 56 + yield 57 + end 44 58 end 45 59 end
-2
bin/bundle
··· 1 1 #!/usr/bin/env ruby 2 - # frozen_string_literal: true 3 - 4 2 # 5 3 # This file was generated by Bundler. 6 4 #
-1
bin/update
··· 1 1 #!/usr/bin/env ruby 2 - # frozen_string_literal: true 3 2 4 3 require "fileutils" 5 4 include FileUtils
-2
config/initializers/active_storage.rb
··· 1 - # frozen_string_literal: true 2 - 3 1 Rails.application.configure do 4 2 # Whatever is added to variable_content_types but is also not in config.active_storage.web_image_content_types 5 3 # will be auto-converted to png by ActiveStorage
-2
config/initializers/assets.rb
··· 1 - # frozen_string_literal: true 2 - 3 1 # Be sure to restart your server when you modify this file. 4 2 5 3 # Version of your assets, change this if you want to expire all your assets.
-2
config/initializers/google_apis.rb
··· 1 - # frozen_string_literal: true 2 - 3 1 require "google/apis/admin_directory_v1" 4 2 require "googleauth" 5 3 require "googleauth/stores/file_token_store"
-2
config/initializers/permissions_policy.rb
··· 1 - # frozen_string_literal: true 2 - 3 1 # Be sure to restart your server when you modify this file. 4 2 5 3 # Define an application-wide HTTP permissions policy. For further
-2
config/initializers/statsd.rb
··· 1 - # frozen_string_literal: true 2 - 3 1 Rails.application.configure do 4 2 # StatsD config here 5 3 ENV["STATSD_ENV"] = "production" # This won't send data unless set to production
-2
lib/util.rb
··· 1 - # frozen_string_literal: true 2 - 3 1 module Util 4 2 5 3 def self.unixtime(unixtime)