Class: Projects::HousekeepingService

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

Defined Under Namespace

Classes: LeaseTaken

Constant Summary collapse

LEASE_TIMEOUT =
3600

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::ShellAdapter

#gitlab_shell

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

#initialize(project) ⇒ HousekeepingService

Returns a new instance of HousekeepingService


20
21
22
# File 'app/services/projects/housekeeping_service.rb', line 20

def initialize(project)
  @project = project
end

Instance Method Details

#executeObject


24
25
26
27
28
29
30
31
32
# File 'app/services/projects/housekeeping_service.rb', line 24

def execute
  raise LeaseTaken if !try_obtain_lease

  GitlabShellOneShotWorker.perform_async(:gc, @project.path_with_namespace)
ensure
  Gitlab::Metrics.measure(:reset_pushes_since_gc) do
    @project.update_column(:pushes_since_gc, 0)
  end
end

#increment!Object


38
39
40
41
42
# File 'app/services/projects/housekeeping_service.rb', line 38

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

#needed?Boolean

Returns:

  • (Boolean)

34
35
36
# File 'app/services/projects/housekeeping_service.rb', line 34

def needed?
  @project.pushes_since_gc >= 10
end