@@ -7,9 +7,16 @@ class DestroyService < BaseService
7
7
DestroyError = Class . new ( StandardError )
8
8
9
9
DELETED_FLAG = '+deleted' . freeze
10
+ REPO_REMOVAL_DELAY = 5 . minutes . to_i
10
11
11
12
def async_execute
12
13
project . update_attribute ( :pending_delete , true )
14
+
15
+ # Ensure no repository +deleted paths are kept,
16
+ # regardless of any issue with the ProjectDestroyWorker
17
+ # job process.
18
+ schedule_stale_repos_removal
19
+
13
20
job_id = ProjectDestroyWorker . perform_async ( project . id , current_user . id , params )
14
21
Rails . logger . info ( "User #{ current_user . id } scheduled destruction of project #{ project . full_path } with job ID #{ job_id } " )
15
22
end
@@ -92,14 +99,23 @@ def remove_repository(path)
92
99
log_info ( %Q{Repository "#{ path } " moved to "#{ new_path } " for project "#{ project . full_path } "} )
93
100
94
101
project . run_after_commit do
95
- # self is now project
96
- GitlabShellWorker . perform_in ( 5 . minutes , :remove_repository , self . repository_storage , new_path )
102
+ GitlabShellWorker . perform_in ( REPO_REMOVAL_DELAY , :remove_repository , self . repository_storage , new_path )
97
103
end
98
104
else
99
105
false
100
106
end
101
107
end
102
108
109
+ def schedule_stale_repos_removal
110
+ repo_paths = [ removal_path ( repo_path ) , removal_path ( wiki_path ) ]
111
+
112
+ # Ideally it should wait until the regular removal phase finishes,
113
+ # so let's delay it a bit further.
114
+ repo_paths . each do |path |
115
+ GitlabShellWorker . perform_in ( REPO_REMOVAL_DELAY * 2 , :remove_repository , project . repository_storage , path )
116
+ end
117
+ end
118
+
103
119
def rollback_repository ( old_path , new_path )
104
120
# There is a possibility project does not have repository or wiki
105
121
return true unless repo_exists? ( old_path )
@@ -113,13 +129,11 @@ def repo_exists?(path)
113
129
end
114
130
# rubocop: enable CodeReuse/ActiveRecord
115
131
116
- # rubocop: disable CodeReuse/ActiveRecord
117
132
def mv_repository ( from_path , to_path )
118
- return true unless gitlab_shell . exists? ( project . repository_storage , from_path + '.git' )
133
+ return true unless repo_exists? ( from_path )
119
134
120
135
gitlab_shell . mv_repository ( project . repository_storage , from_path , to_path )
121
136
end
122
- # rubocop: enable CodeReuse/ActiveRecord
123
137
124
138
def attempt_rollback ( project , message )
125
139
return unless project
0 commit comments