From e53a560af06c7a477c00c54225550a8118c1d9d6 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 7 Dec 2020 13:36:09 -0300 Subject: [PATCH] =?UTF-8?q?solo=20descargar=20archivos=20del=20sitio,=20fa?= =?UTF-8?q?ltaba=20la=20migraci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/backtrace_job.rb | 13 ++++++++++--- .../20201207152354_add_api_key_to_sites.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20201207152354_add_api_key_to_sites.rb diff --git a/app/jobs/backtrace_job.rb b/app/jobs/backtrace_job.rb index 559e0a1d..6f2425e9 100644 --- a/app/jobs/backtrace_job.rb +++ b/app/jobs/backtrace_job.rb @@ -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 diff --git a/db/migrate/20201207152354_add_api_key_to_sites.rb b/db/migrate/20201207152354_add_api_key_to_sites.rb new file mode 100644 index 00000000..0c1240fb --- /dev/null +++ b/db/migrate/20201207152354_add_api_key_to_sites.rb @@ -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