diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 12:07:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 12:07:48 +0000 |
commit | ef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b (patch) | |
tree | f0ee2b8bdffd7f91ad0b31388562c90825179585 /app/workers | |
parent | 7e019504f5ac6decde690565857238e7e59aa034 (diff) | |
download | gitlab-ce-ef31adeb0fb9a02b2c6a4529ec4e38d7082a4b2b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
6 files changed, 61 insertions, 4 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index 16520519a0b..7dc47c55a04 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -556,6 +556,13 @@ :resource_boundary: :unknown :weight: 1 :idempotent: +- :name: jira_importer:jira_import_import_issue + :feature_category: :importers + :has_external_dependencies: + :urgency: :low + :resource_boundary: :unknown + :weight: 1 + :idempotent: - :name: jira_importer:jira_import_stage_finish_import :feature_category: :importers :has_external_dependencies: diff --git a/app/workers/gitlab/jira_import/import_issue_worker.rb b/app/workers/gitlab/jira_import/import_issue_worker.rb new file mode 100644 index 00000000000..832916a03b6 --- /dev/null +++ b/app/workers/gitlab/jira_import/import_issue_worker.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module JiraImport + class ImportIssueWorker # rubocop:disable Scalability/IdempotentWorker + include ApplicationWorker + include NotifyUponDeath + include Gitlab::JiraImport::QueueOptions + include Gitlab::Import::DatabaseHelpers + + def perform(project_id, jira_issue_id, issue_attributes, waiter_key) + issue_id = insert_and_return_id(issue_attributes, Issue) + cache_issue_mapping(issue_id, jira_issue_id, project_id) + rescue => ex + # Todo: Record jira issue id(or better jira issue key), + # so that we can report the list of failed to import issues to the user + # see https://gitlab.com/gitlab-org/gitlab/-/issues/211653 + # + # It's possible the project has been deleted since scheduling this + # job. In this case we'll just skip creating the issue. + Gitlab::ErrorTracking.track_exception(ex, project_id: project_id) + JiraImport.increment_issue_failures(project_id) + ensure + # ensure we notify job waiter that the job has finished + JobWaiter.notify(waiter_key, jid) if waiter_key + end + + private + + def cache_issue_mapping(issue_id, jira_issue_id, project_id) + cache_key = JiraImport.jira_issue_cache_key(project_id, jira_issue_id) + Gitlab::Cache::Import::Caching.write(cache_key, issue_id) + end + end + end +end diff --git a/app/workers/gitlab/jira_import/stage/finish_import_worker.rb b/app/workers/gitlab/jira_import/stage/finish_import_worker.rb index 5b1661d68c6..f053037e78a 100644 --- a/app/workers/gitlab/jira_import/stage/finish_import_worker.rb +++ b/app/workers/gitlab/jira_import/stage/finish_import_worker.rb @@ -11,6 +11,7 @@ module Gitlab def import(project) project.after_import ensure + JiraImport.cache_cleanup(project.id) project.import_data.becomes(JiraImportData).finish_import! project.import_data.save! end diff --git a/app/workers/gitlab/jira_import/stage/import_issues_worker.rb b/app/workers/gitlab/jira_import/stage/import_issues_worker.rb index 79ed8e1f2da..7e257afc4d9 100644 --- a/app/workers/gitlab/jira_import/stage/import_issues_worker.rb +++ b/app/workers/gitlab/jira_import/stage/import_issues_worker.rb @@ -9,12 +9,19 @@ module Gitlab private def import(project) - # fake issues import workers for now - # new job waiter will have zero jobs_remaining by default, so it will just pass on to next stage - jobs_waiter = JobWaiter.new + jobs_waiter = Gitlab::JiraImport::IssuesImporter.new(project).execute + project.import_state.refresh_jid_expiration - Gitlab::JiraImport::AdvanceStageWorker.perform_async(project.id, { jobs_waiter.key => jobs_waiter.jobs_remaining }, :attachments) + Gitlab::JiraImport::AdvanceStageWorker.perform_async( + project.id, + { jobs_waiter.key => jobs_waiter.jobs_remaining }, + next_stage(project) + ) + end + + def next_stage(project) + Gitlab::JiraImport.get_issues_next_start_at(project.id) < 0 ? :attachments : :issues end end end diff --git a/app/workers/gitlab/jira_import/stage/start_import_worker.rb b/app/workers/gitlab/jira_import/stage/start_import_worker.rb index 8abbfab647b..ae4864064e4 100644 --- a/app/workers/gitlab/jira_import/stage/start_import_worker.rb +++ b/app/workers/gitlab/jira_import/stage/start_import_worker.rb @@ -26,6 +26,7 @@ module Gitlab def start_import return false unless project return false if Feature.disabled?(:jira_issue_import, project) + return false unless project.jira_force_import? return true if start(project.import_state) Gitlab::Import::Logger.info( diff --git a/app/workers/reactive_caching_worker.rb b/app/workers/reactive_caching_worker.rb index 716b1de2bf5..1921ac6619b 100644 --- a/app/workers/reactive_caching_worker.rb +++ b/app/workers/reactive_caching_worker.rb @@ -13,6 +13,11 @@ class ReactiveCachingWorker # rubocop:disable Scalability/IdempotentWorker urgency :high worker_resource_boundary :cpu + def self.context_for_arguments(arguments) + class_name, *_other_args = arguments + Gitlab::ApplicationContext.new(related_class: class_name) + end + def perform(class_name, id, *args) klass = begin class_name.constantize |