Class: Projects::HousekeepingService

Inherits:
BaseService show all
Defined in:
app/services/projects/housekeeping_service.rb

Defined Under Namespace

Classes: LeaseTaken

Constant Summary collapse

LEASE_TIMEOUT =

Timeout set to 24h

86400
PACK_REFS_PERIOD =
6

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(project, task = nil) ⇒ HousekeepingService

Returns a new instance of HousekeepingService.


22
23
24
25
# File 'app/services/projects/housekeeping_service.rb', line 22

def initialize(project, task = nil)
  @project = project
  @task = task
end

Instance Method Details

#executeObject

Raises:


27
28
29
30
31
32
33
34
# File 'app/services/projects/housekeeping_service.rb', line 27

def execute
  lease_uuid = try_obtain_lease
  raise LeaseTaken unless lease_uuid.present?

  yield if block_given?

  execute_gitlab_shell_gc(lease_uuid)
end

#increment!Object


40
41
42
43
44
# File 'app/services/projects/housekeeping_service.rb', line 40

def increment!
  Gitlab::Metrics.measure(:increment_pushes_since_gc) do
    @project.increment_pushes_since_gc
  end
end

#needed?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/services/projects/housekeeping_service.rb', line 36

def needed?
  pushes_since_gc > 0 && period_match? && housekeeping_enabled?
end