diff options
author | Marcia Ramos <virtua.creative@gmail.com> | 2019-04-10 17:05:46 +0100 |
---|---|---|
committer | Marcia Ramos <virtua.creative@gmail.com> | 2019-04-10 17:05:46 +0100 |
commit | cbd6841cac8185f181a5dcec33704f6e7c040732 (patch) | |
tree | 423bbc4fb873ab51590d0be4ae594769c80b739b /app/workers | |
parent | 3402f8c817e9798eed9d86555f3f85fd10f49abf (diff) | |
parent | 490b31f740d23b54a62588cd9fd0e0cf7fdd9370 (diff) | |
download | gitlab-ce-docs-pages-intro.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into docs-pages-introdocs-pages-intro
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/all_queues.yml | 1 | ||||
-rw-r--r-- | app/workers/concerns/application_worker.rb | 2 | ||||
-rw-r--r-- | app/workers/email_receiver_worker.rb | 16 | ||||
-rw-r--r-- | app/workers/object_storage/migrate_uploads_worker.rb | 14 | ||||
-rw-r--r-- | app/workers/post_receive.rb | 2 | ||||
-rw-r--r-- | app/workers/project_cache_worker.rb | 20 | ||||
-rw-r--r-- | app/workers/update_project_statistics_worker.rb | 18 |
7 files changed, 50 insertions, 23 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index 3e8c2a1209a..f9b2e698fc9 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -143,6 +143,7 @@ - repository_remove_remote - system_hook_push - update_merge_requests +- update_project_statistics - upload_checksum - web_hook - repository_update_remote_mirror diff --git a/app/workers/concerns/application_worker.rb b/app/workers/concerns/application_worker.rb index d64c2f82a09..25c3a945077 100644 --- a/app/workers/concerns/application_worker.rb +++ b/app/workers/concerns/application_worker.rb @@ -53,7 +53,7 @@ module ApplicationWorker schedule = now + delay.to_i if schedule <= now - raise ArgumentError, 'The schedule time must be in the future!' + raise ArgumentError, _('The schedule time must be in the future!') end Sidekiq::Client.push_bulk('class' => self, 'args' => args_list, 'at' => schedule) diff --git a/app/workers/email_receiver_worker.rb b/app/workers/email_receiver_worker.rb index bf637f82df2..c4bcda2da16 100644 --- a/app/workers/email_receiver_worker.rb +++ b/app/workers/email_receiver_worker.rb @@ -24,22 +24,22 @@ class EmailReceiverWorker reason = case error when Gitlab::Email::UnknownIncomingEmail - "We couldn't figure out what the email is for. Please create your issue or comment through the web interface." + s_("EmailError|We couldn't figure out what the email is for. Please create your issue or comment through the web interface.") when Gitlab::Email::SentNotificationNotFoundError - "We couldn't figure out what the email is in reply to. Please create your comment through the web interface." + s_("EmailError|We couldn't figure out what the email is in reply to. Please create your comment through the web interface.") when Gitlab::Email::ProjectNotFound - "We couldn't find the project. Please check if there's any typo." + s_("EmailError|We couldn't find the project. Please check if there's any typo.") when Gitlab::Email::EmptyEmailError can_retry = true - "It appears that the email is blank. Make sure your reply is at the top of the email, we can't process inline replies." + s_("EmailError|It appears that the email is blank. Make sure your reply is at the top of the email, we can't process inline replies.") when Gitlab::Email::UserNotFoundError - "We couldn't figure out what user corresponds to the email. Please create your comment through the web interface." + s_("EmailError|We couldn't figure out what user corresponds to the email. Please create your comment through the web interface.") when Gitlab::Email::UserBlockedError - "Your account has been blocked. If you believe this is in error, contact a staff member." + s_("EmailError|Your account has been blocked. If you believe this is in error, contact a staff member.") when Gitlab::Email::UserNotAuthorizedError - "You are not allowed to perform this action. If you believe this is in error, contact a staff member." + s_("EmailError|You are not allowed to perform this action. If you believe this is in error, contact a staff member.") when Gitlab::Email::NoteableNotFoundError - "The thread you are replying to no longer exists, perhaps it was deleted? If you believe this is in error, contact a staff member." + s_("EmailError|The thread you are replying to no longer exists, perhaps it was deleted? If you believe this is in error, contact a staff member.") when Gitlab::Email::InvalidAttachment error.message when Gitlab::Email::InvalidRecordError diff --git a/app/workers/object_storage/migrate_uploads_worker.rb b/app/workers/object_storage/migrate_uploads_worker.rb index 206eb71b898..12400d4e025 100644 --- a/app/workers/object_storage/migrate_uploads_worker.rb +++ b/app/workers/object_storage/migrate_uploads_worker.rb @@ -20,7 +20,7 @@ module ObjectStorage end def to_s - success? ? "Migration successful." : "Error while migrating #{upload.id}: #{error.message}" + success? ? _("Migration successful.") : _("Error while migrating %{upload_id}: %{error_message}") % { upload_id: upload.id, error_message: error.message } end end @@ -47,7 +47,7 @@ module ObjectStorage end def header(success, failures) - "Migrated #{success.count}/#{success.count + failures.count} files." + _("Migrated %{success_count}/%{total_count} files.") % { success_count: success.count, total_count: success.count + failures.count } end def failures(failures) @@ -75,9 +75,9 @@ module ObjectStorage model_types = uploads.map(&:model_type).uniq model_has_mount = mounted_as.nil? || model_class.uploaders[mounted_as] == uploader_class - raise(SanityCheckError, "Multiple uploaders found: #{uploader_types}") unless uploader_types.count == 1 - raise(SanityCheckError, "Multiple model types found: #{model_types}") unless model_types.count == 1 - raise(SanityCheckError, "Mount point #{mounted_as} not found in #{model_class}.") unless model_has_mount + raise(SanityCheckError, _("Multiple uploaders found: %{uploader_types}") % { uploader_types: uploader_types }) unless uploader_types.count == 1 + raise(SanityCheckError, _("Multiple model types found: %{model_types}") % { model_types: model_types }) unless model_types.count == 1 + raise(SanityCheckError, _("Mount point %{mounted_as} not found in %{model_class}.") % { mounted_as: mounted_as, model_class: model_class }) unless model_has_mount end # rubocop: disable CodeReuse/ActiveRecord @@ -110,9 +110,9 @@ module ObjectStorage return if args.count == 4 case args.count - when 3 then raise SanityCheckError, "Job is missing the `model_type` argument." + when 3 then raise SanityCheckError, _("Job is missing the `model_type` argument.") else - raise SanityCheckError, "Job has wrong arguments format." + raise SanityCheckError, _("Job has wrong arguments format.") end end diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index 396f44396a3..a5554f07699 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -3,7 +3,7 @@ class PostReceive include ApplicationWorker - def perform(gl_repository, identifier, changes, push_options = []) + def perform(gl_repository, identifier, changes, push_options = {}) project, repo_type = Gitlab::GlRepository.parse(gl_repository) if project.nil? diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb index b31099bc670..b2e0701008a 100644 --- a/app/workers/project_cache_worker.rb +++ b/app/workers/project_cache_worker.rb @@ -18,7 +18,7 @@ class ProjectCacheWorker return unless project && project.repository.exists? - update_statistics(project, statistics.map(&:to_sym)) + update_statistics(project, statistics) project.repository.refresh_method_caches(files.map(&:to_sym)) @@ -26,20 +26,28 @@ class ProjectCacheWorker end # rubocop: enable CodeReuse/ActiveRecord + # NOTE: triggering both an immediate update and one in 15 minutes if we + # successfully obtain the lease. That way, we only need to wait for the + # statistics to become accurate if they were already updated once in the + # last 15 minutes. def update_statistics(project, statistics = []) return if Gitlab::Database.read_only? - return unless try_obtain_lease_for(project.id, :update_statistics) + return unless try_obtain_lease_for(project.id, statistics) - Rails.logger.info("Updating statistics for project #{project.id}") + Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute - project.statistics.refresh!(only: statistics) + UpdateProjectStatisticsWorker.perform_in(LEASE_TIMEOUT, project.id, statistics) end private - def try_obtain_lease_for(project_id, section) + def try_obtain_lease_for(project_id, statistics) Gitlab::ExclusiveLease - .new("project_cache_worker:#{project_id}:#{section}", timeout: LEASE_TIMEOUT) + .new(project_cache_worker_key(project_id, statistics), timeout: LEASE_TIMEOUT) .try_obtain end + + def project_cache_worker_key(project_id, statistics) + ["project_cache_worker", project_id, *statistics.sort].join(":") + end end diff --git a/app/workers/update_project_statistics_worker.rb b/app/workers/update_project_statistics_worker.rb new file mode 100644 index 00000000000..9a29cc12707 --- /dev/null +++ b/app/workers/update_project_statistics_worker.rb @@ -0,0 +1,18 @@ + +# frozen_string_literal: true + +# Worker for updating project statistics. +class UpdateProjectStatisticsWorker + include ApplicationWorker + + # project_id - The ID of the project for which to flush the cache. + # statistics - An Array containing columns from ProjectStatistics to + # refresh, if empty all columns will be refreshed + # rubocop: disable CodeReuse/ActiveRecord + def perform(project_id, statistics = []) + project = Project.find_by(id: project_id) + + Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute + end + # rubocop: enable CodeReuse/ActiveRecord +end |