diff options
Diffstat (limited to 'app/workers/gitlab/github_gists_import')
-rw-r--r-- | app/workers/gitlab/github_gists_import/finish_import_worker.rb | 14 | ||||
-rw-r--r-- | app/workers/gitlab/github_gists_import/import_gist_worker.rb | 24 |
2 files changed, 30 insertions, 8 deletions
diff --git a/app/workers/gitlab/github_gists_import/finish_import_worker.rb b/app/workers/gitlab/github_gists_import/finish_import_worker.rb index 1989b6314ea..284e5833f0c 100644 --- a/app/workers/gitlab/github_gists_import/finish_import_worker.rb +++ b/app/workers/gitlab/github_gists_import/finish_import_worker.rb @@ -18,14 +18,15 @@ module Gitlab INTERVAL = 30.seconds.to_i BLOCKING_WAIT_TIME = 5 + GISTS_ERRORS_BY_ID = 'gitlab:github-gists-import:%{user_id}:errors' def perform(user_id, waiter_key, remaining) waiter = wait_for_jobs(waiter_key, remaining) if waiter.nil? Gitlab::GithubGistsImport::Status.new(user_id).finish! - Gitlab::GithubImport::Logger.info(user_id: user_id, message: 'GitHub Gists import finished') + send_email_if_errors(user_id) else self.class.perform_in(INTERVAL, user_id, waiter.key, waiter.jobs_remaining) end @@ -41,6 +42,17 @@ module Gitlab waiter end + + def send_email_if_errors(user_id) + key = format(GISTS_ERRORS_BY_ID, user_id: user_id) + errors = ::Gitlab::Cache::Import::Caching.values_from_hash(key) + + return if errors.blank? + + Notify.github_gists_import_errors_email(user_id, errors).deliver_now + ensure + ::Gitlab::Cache::Import::Caching.expire(key, ::Gitlab::Cache::Import::Caching::SHORTER_TIMEOUT) + end end end end diff --git a/app/workers/gitlab/github_gists_import/import_gist_worker.rb b/app/workers/gitlab/github_gists_import/import_gist_worker.rb index 7e2b3709597..fb7fb661f4c 100644 --- a/app/workers/gitlab/github_gists_import/import_gist_worker.rb +++ b/app/workers/gitlab/github_gists_import/import_gist_worker.rb @@ -6,6 +6,8 @@ module Gitlab include ApplicationWorker include Gitlab::NotifyUponDeath + GISTS_ERRORS_BY_ID = 'gitlab:github-gists-import:%{user_id}:errors' + data_consistency :always queue_namespace :github_gists_importer feature_category :importers @@ -33,16 +35,16 @@ module Gitlab ::Gitlab::GithubGistsImport::Importer::GistImporter end - def with_logging(user_id, gist_id) - info(user_id, 'start importer', gist_id) + def with_logging(user_id, github_identifiers) + info(user_id, 'start importer', github_identifiers) yield - info(user_id, 'importer finished', gist_id) + info(user_id, 'importer finished', github_identifiers) end - def log_and_track_error(user_id, exception, gist_id) - error(user_id, exception.message, gist_id) + def log_and_track_error(user_id, exception, github_identifiers) + error(user_id, exception.message, github_identifiers) Gitlab::ErrorTracking.track_exception(exception, import_type: :github_gists, @@ -50,15 +52,17 @@ module Gitlab ) end - def error(user_id, error_message, gist_id) + def error(user_id, error_message, github_identifiers) attributes = { user_id: user_id, - github_identifiers: gist_id, + github_identifiers: github_identifiers, message: 'importer failed', 'error.message': error_message } Gitlab::GithubImport::Logger.error(structured_payload(attributes)) + + cache_error_for_email(user_id, github_identifiers[:id], error_message) end def info(user_id, message, gist_id) @@ -70,6 +74,12 @@ module Gitlab Gitlab::GithubImport::Logger.info(structured_payload(attributes)) end + + def cache_error_for_email(user_id, gist_id, error_message) + key = format(GISTS_ERRORS_BY_ID, user_id: user_id) + + ::Gitlab::Cache::Import::Caching.hash_add(key, gist_id, error_message) + end end end end |