Class: Repositories::HousekeepingService

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

Defined Under Namespace

Classes: LeaseTaken

Constant Summary collapse

LEASE_TIMEOUT =

Timeout set to 24h

86400
GC_PERIOD =
200

Instance Attribute Summary

Attributes inherited from BaseService

#repository

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#ignore_git_errors, #move_error, #repo_exists?

Methods included from Gitlab::ShellAdapter

#gitlab_shell

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?, #can_all?, #can_any?

Constructor Details

#initialize(resource, task = nil) ⇒ HousekeepingService

Returns a new instance of HousekeepingService.



21
22
23
24
# File 'app/services/repositories/housekeeping_service.rb', line 21

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

Instance Method Details

#executeObject

Raises:



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

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



39
40
41
42
43
# File 'app/services/repositories/housekeeping_service.rb', line 39

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

#needed?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/services/repositories/housekeeping_service.rb', line 35

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