class RequestMaster::ReqMaster
Attributes
action_count[RW]
domain[RW]
Public Class Methods
new()
click to toggle source
# File lib/request_master.rb, line 57 def initialize @database = RequestMaster.reqs_db @action_count = 0 end
Public Instance Methods
all_ip_stats(dom_id)
click to toggle source
# File lib/request_master/req_stats.rb, line 58 def all_ip_stats (dom_id) all_ips = IpAddress.select(:public_ip).to_a all_ips.map!(&:public_ip) all_avg = Numbers([]) all_total = Numbers([]) output = all_ips.inject([]) { |acc, ip| stats = ip_stats(ip, dom_id) if stats.num >= 50 all_total << stats.num all_avg << stats.avg acc << {ip => stats.avg} else acc end } total_stats = { min_total: all_total.min, max_total: all_total.max, avg_total: all_total.average.round, min_avg: all_avg.min, max_avg: all_avg.max, avg_avg: all_avg.average.round } output << total_stats end
alloc_exhaust?()
click to toggle source
# File lib/request_master/actions.rb, line 49 def alloc_exhaust? @allocation == 0 end
allocate(first_run = false)
click to toggle source
# File lib/request_master/actions.rb, line 25 def allocate (first_run = false) my_ip = RequestMaster.my_ip checks_out = first_run ? check(my_ip) : false until checks_out script = RequestMaster.alloc_args my_ip = script.object.send(script.method_name, *script.args) checks_out = check(my_ip) unless checks_out sputs "failed because #{RequestMaster.details.to_h}" end end sputs "ip #{my_ip} passed checks" sputs ip_stats(my_ip, RequestMaster.check_args.dom_id).to_h.to_s comp_alloc(my_ip) sputs "allocation = #{@allocation}" @allocation end
Also aliased as: reallocate
check(ip, dom_id = RequestMaster.check_args.dom_id, avg_freq = RequestMaster.check_args.avg_freq)
click to toggle source
# File lib/request_master/ip_checks.rb, line 41 def check (ip, dom_id = RequestMaster.check_args.dom_id, avg_freq = RequestMaster.check_args.avg_freq) check_status(ip, dom_id) && check_freq(ip, dom_id, avg_freq) end
check_frequency(ip, dom_id, avg_freq)
click to toggle source
# File lib/request_master/ip_checks.rb, line 27 def check_frequency (ip, dom_id, avg_freq) result = ip_stats(ip, dom_id).avg if result.nil? || result <= avg_freq true else RequestMaster.details = { ip: ip, dom_id: dom_id, avg_freq: result } false end end
Also aliased as: check_freq
check_status(ip, dom_id)
click to toggle source
# File lib/request_master/ip_checks.rb, line 8 def check_status (ip, dom_id) record = IpStatus[public_ip: ip, website: dom_id] if record.nil? true else status = record.status if ['blocked', 'shielded'].include?(status) RequestMaster.details = { ip: ip, dom_id: dom_id, status: status } false else true end end end
comp_alloc(ip, dom_id = RequestMaster.check_args.dom_id, avg_freq = RequestMaster.check_args.avg_freq)
Alias for: compute_allowance
compute_allowance(ip, dom_id = RequestMaster.check_args.dom_id, avg_freq = RequestMaster.check_args.avg_freq)
click to toggle source
# File lib/request_master/ip_details.rb, line 8 def compute_allowance (ip, dom_id = RequestMaster.check_args.dom_id, avg_freq = RequestMaster.check_args.avg_freq) stats = ip_stats(ip, dom_id) @allocation = avg_freq * (stats.days + 1) - stats.num end
Also aliased as: comp_alloc
dom_id(url)
click to toggle source
# File lib/request_master/req_stats.rb, line 36 def dom_id (url) Website[domain_url: url].id end
ip_stats(ip, dom_id)
click to toggle source
# File lib/request_master/req_stats.rb, line 40 def ip_stats (ip, dom_id) requests = BrowserRequest.where(domain: dom_id, ip_address: ip) num = requests.count if num >= 2 time_span = (requests.last.time.to_date - requests.first.time.to_date + 1).to_f avg = (num / time_span).to_f.round(1) elsif num == 1 avg = num time_span = 1.0 else avg = nil time_span = 0.0 end OpenStruct.new(num: num, avg: avg, days: time_span.round(1)) end
run_action()
click to toggle source
# File lib/request_master/actions.rb, line 8 def run_action script = RequestMaster.action_args result = script.object.send(script.method_name, *script.args) @action_count += 1 unless script.divider.nil? if @action_count % script.divider == 0 puts '------------------------' end end @allocation -= 1 result end