solo descargar archivos del sitio, faltaba la migración

This commit is contained in:
f 2020-12-07 13:36:09 -03:00
parent 0ce42f17b5
commit e53a560af0
2 changed files with 26 additions and 3 deletions

View file

@ -4,11 +4,14 @@
class BacktraceJob < ApplicationJob
queue_as :low_priority
attr_reader :errors
attr_reader :errors, :site_id
def perform(site_id:, errors:)
@site_id = site_id
@errors = errors
return if files.empty?
errors.each do |error|
error['backtrace'].each do |backtrace|
offset = SourceMap::Offset.new(backtrace['line'], backtrace['column'])
@ -25,15 +28,19 @@ class BacktraceJob < ApplicationJob
begin
raise NoMethodError
rescue NoMethodError => e
ExceptionNotifier.notify_exception(e, data: { errors: errors })
ExceptionNotifier.notify_exception(e, data: { site: site.name, errors: errors })
end
end
private
def site
@site ||= Site.find(site_id)
end
# Obtiene todos los archivos del backtrace
def files
@files ||= errors.map { |x| x['backtrace'] }.flatten.map { |x| x['file'].split('@').last }.uniq
@files ||= errors.map { |x| x['backtrace'] }.flatten.map { |x| x['file'].split('@').last }.uniq.select { |x| x.start_with? site.url }
end
# Asume que todos los sourcemaps comparten la misma URL, lo

View file

@ -0,0 +1,16 @@
class AddApiKeyToSites < ActiveRecord::Migration[6.0]
def up
add_column :sites, :api_key_ciphertext, :string
begin
Site.find_each do |site|
site.update_attribute :api_key, SecureRandom.hex(64)
end
rescue Errno::ENOENT
end
end
def down
remove_column :sites, :api_key_ciphertext
end
end