diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-03-05 15:57:48 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-03-06 10:53:24 +0300 |
commit | 1c931f0784fc15601101fe356585812c93ac1587 (patch) | |
tree | 3253b1506e5a38c6a37afd9bb489f5e8a7ff68aa /app/services/projects/update_pages_service.rb | |
parent | 2e87923dcb1cf7984690f5b5fdfc61bddfba923e (diff) |
Rework to minimize changes
Diffstat (limited to 'app/services/projects/update_pages_service.rb')
-rw-r--r-- | app/services/projects/update_pages_service.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/app/services/projects/update_pages_service.rb b/app/services/projects/update_pages_service.rb index c760bd3b626..d3e792b9232 100644 --- a/app/services/projects/update_pages_service.rb +++ b/app/services/projects/update_pages_service.rb @@ -1,5 +1,6 @@ module Projects class UpdatePagesService < BaseService + InvaildStateError = Class.new(StandardError) BLOCK_SIZE = 32.kilobytes MAX_SIZE = 1.terabyte SITE_PATH = 'public/'.freeze @@ -11,13 +12,15 @@ module Projects end def execute + register_attempt + # Create status notifying the deployment of pages @status = create_status @status.enqueue! @status.run! - raise 'missing pages artifacts' unless build.artifacts? - raise 'pages are outdated' unless latest? + raise InvaildStateError, 'missing pages artifacts' unless build.artifacts? + raise InvaildStateError, 'pages are outdated' unless latest? # Create temporary directory in which we will extract the artifacts FileUtils.mkdir_p(tmp_path) @@ -26,24 +29,22 @@ module Projects # Check if we did extract public directory archive_public_path = File.join(archive_path, 'public') - raise 'pages miss the public folder' unless Dir.exist?(archive_public_path) - raise 'pages are outdated' unless latest? + raise InvaildStateError, 'pages miss the public folder' unless Dir.exist?(archive_public_path) + raise InvaildStateError, 'pages are outdated' unless latest? deploy_page!(archive_public_path) success end - rescue => e + rescue InvaildStateError => e register_failure error(e.message) - ensure - register_attempt - build.erase_artifacts! unless build.has_expiring_artifacts? end private def success @status.success + delete_artifact! super end @@ -52,6 +53,7 @@ module Projects @status.allow_failure = !latest? @status.description = message @status.drop(:script_failure) + delete_artifact! super end @@ -163,6 +165,11 @@ module Projects build.artifacts_file.path end + def delete_artifact! + build.reload + build.erase_artifacts! unless build.has_expiring_artifacts? + end + def latest_sha project.commit(build.ref).try(:sha).to_s end |