Commit 8a6ddca0 authored by rpereira2's avatar rpereira2

Create concern for self-monitoring workers

* Move common code from the creation and deletion workers into the
concern.

* Remove the lib/gitlab/self_monitoring.rb file since the constant it
contained is now in the concern.
parent a856f668
# frozen_string_literal: true
module SelfMonitoringProjectWorker
extend ActiveSupport::Concern
included do
# This worker falls under Self-monitoring with Monitor::APM group. However,
# self-monitoring is not classified as a feature category but rather as
# Other Functionality. Metrics seems to be the closest feature_category for
# this worker.
feature_category :metrics
end
LEASE_TIMEOUT = 15.minutes.to_i
EXCLUSIVE_LEASE_KEY = 'self_monitoring_service_creation_deletion'
class_methods do
# @param job_id [String]
# Job ID that is used to construct the cache keys.
# @return [Hash]
# Returns true if the job is enqueued or in progress and false otherwise.
def in_progress?(job_id)
Gitlab::SidekiqStatus.job_status(Array.wrap(job_id)).first
end
end
private
def lease_key
EXCLUSIVE_LEASE_KEY
end
def lease_timeout
self.class::LEASE_TIMEOUT
end
end
...@@ -3,36 +3,11 @@ ...@@ -3,36 +3,11 @@
class SelfMonitoringProjectCreateWorker class SelfMonitoringProjectCreateWorker
include ApplicationWorker include ApplicationWorker
include ExclusiveLeaseGuard include ExclusiveLeaseGuard
include SelfMonitoringProjectWorker
# This worker falls under Self-monitoring with Monitor::APM group. However,
# self-monitoring is not classified as a feature category but rather as
# Other Functionality. Metrics seems to be the closest feature_category for
# this worker.
feature_category :metrics
LEASE_TIMEOUT = 15.minutes.to_i
def perform def perform
try_obtain_lease do try_obtain_lease do
Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService.new.execute Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService.new.execute
end end
end end
# @param job_id [String]
# Job ID that is used to construct the cache keys.
# @return [Hash]
# Returns true if the job is enqueued or in progress and false otherwise.
def self.in_progress?(job_id)
Gitlab::SidekiqStatus.job_status(Array.wrap(job_id)).first
end
private
def lease_key
Gitlab::SelfMonitoring::PROJECT_CREATION_DELETION_WORKER_EXCLUSIVE_LEASE_KEY
end
def lease_timeout
LEASE_TIMEOUT
end
end end
...@@ -3,36 +3,11 @@ ...@@ -3,36 +3,11 @@
class SelfMonitoringProjectDeleteWorker class SelfMonitoringProjectDeleteWorker
include ApplicationWorker include ApplicationWorker
include ExclusiveLeaseGuard include ExclusiveLeaseGuard
include SelfMonitoringProjectWorker
# This worker falls under Self-monitoring with Monitor::APM group. However,
# self-monitoring is not classified as a feature category but rather as
# Other Functionality. Metrics seems to be the closest feature_category for
# this worker.
feature_category :metrics
LEASE_TIMEOUT = 15.minutes.to_i
def perform def perform
try_obtain_lease do try_obtain_lease do
Gitlab::DatabaseImporters::SelfMonitoring::Project::DeleteService.new.execute Gitlab::DatabaseImporters::SelfMonitoring::Project::DeleteService.new.execute
end end
end end
# @param job_id [String]
# Job ID that is used to construct the cache keys.
# @return [Hash]
# Returns true if the job is enqueued or in progress and false otherwise.
def self.in_progress?(job_id)
Gitlab::SidekiqStatus.job_status(Array.wrap(job_id)).first
end
private
def lease_key
Gitlab::SelfMonitoring::PROJECT_CREATION_DELETION_WORKER_EXCLUSIVE_LEASE_KEY
end
def lease_timeout
LEASE_TIMEOUT
end
end end
# frozen_string_literal: true
module Gitlab
module SelfMonitoring
PROJECT_CREATION_DELETION_WORKER_EXCLUSIVE_LEASE_KEY = 'self_monitoring_service_creation_deletion'
end
end
...@@ -8,7 +8,7 @@ RSpec.shared_examples 'executes service' do ...@@ -8,7 +8,7 @@ RSpec.shared_examples 'executes service' do
allow(service_class).to receive(:new) { service } allow(service_class).to receive(:new) { service }
end end
it 'runs the SelfMonitoring::Project::CreateService' do it 'runs the service' do
expect(service).to receive(:execute) expect(service).to receive(:execute)
subject.perform subject.perform
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment