2015-10-21 09:15:54 -04:00
|
|
|
# Projects::HousekeepingService class
|
|
|
|
#
|
|
|
|
# Used for git housekeeping
|
|
|
|
#
|
|
|
|
# Ex.
|
2015-11-19 09:16:54 -05:00
|
|
|
# Projects::HousekeepingService.new(project).execute
|
2015-10-21 09:15:54 -04:00
|
|
|
#
|
|
|
|
module Projects
|
|
|
|
class HousekeepingService < BaseService
|
|
|
|
include Gitlab::ShellAdapter
|
|
|
|
|
2016-03-14 10:18:52 -04:00
|
|
|
LEASE_TIMEOUT = 3600
|
|
|
|
|
2015-10-21 09:15:54 -04:00
|
|
|
def initialize(project)
|
|
|
|
@project = project
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2016-03-14 10:18:52 -04:00
|
|
|
if !try_obtain_lease
|
|
|
|
return "Housekeeping was already triggered in the past #{LEASE_TIMEOUT / 60} minutes"
|
|
|
|
end
|
|
|
|
|
2015-11-19 10:04:07 -05:00
|
|
|
GitlabShellWorker.perform_async(:gc, @project.path_with_namespace)
|
2016-03-14 10:18:52 -04:00
|
|
|
return "Housekeeping successfully started"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def try_obtain_lease
|
|
|
|
lease = ::Gitlab::ExclusiveLease.new("project_housekeeping:#{@project.id}", timeout: LEASE_TIMEOUT)
|
|
|
|
lease.try_obtain
|
2015-10-21 09:15:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|