summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-09-01 00:56:40 -0700
committerStan Hu <stanhu@gmail.com>2015-09-11 00:34:04 -0700
commit9995f0806b29934cf498607f59d2c5ec358a0d5a (patch)
treead197f6e023553b20bb1317c57dddffe34da68b5 /app/workers
parenta5bb85f8a234b2d8463656877712faf10f5bb842 (diff)
downloadgitlab-ce-9995f0806b29934cf498607f59d2c5ec358a0d5a.tar.gz
Import forked repositories asynchronously to prevent large repositories from timing out
Use import_status to track async import status and give feedback to the user Closes #2388 Closes #2400
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/repository_fork_worker.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/workers/repository_fork_worker.rb b/app/workers/repository_fork_worker.rb
new file mode 100644
index 00000000000..acd1c43f06b
--- /dev/null
+++ b/app/workers/repository_fork_worker.rb
@@ -0,0 +1,34 @@
+class RepositoryForkWorker
+ include Sidekiq::Worker
+ include Gitlab::ShellAdapter
+
+ sidekiq_options queue: :gitlab_shell
+
+ def perform(project_id, source_path, target_path)
+ project = Project.find_by_id(project_id)
+
+ unless project.present?
+ logger.error("Project #{project_id} no longer exists!")
+ return
+ end
+
+ result = gitlab_shell.fork_repository(source_path, target_path)
+
+ unless result
+ logger.error("Unable to fork project #{project_id} for repository #{source_path} -> #{target_path}")
+ project.import_fail
+ project.save
+ return
+ end
+
+ if project.valid_repo?
+ ProjectCacheWorker.perform_async(project.id)
+ project.import_finish
+ else
+ project.import_fail
+ logger.error("Project #{id} had an invalid repository after fork")
+ end
+
+ project.save
+ end
+end