Commit 1c931f07 authored by Shinya Maeda's avatar Shinya Maeda

Rework to minimize changes

parent 2e87923d
module Projects module Projects
class UpdatePagesService < BaseService class UpdatePagesService < BaseService
InvaildStateError = Class.new(StandardError)
BLOCK_SIZE = 32.kilobytes BLOCK_SIZE = 32.kilobytes
MAX_SIZE = 1.terabyte MAX_SIZE = 1.terabyte
SITE_PATH = 'public/'.freeze SITE_PATH = 'public/'.freeze
...@@ -11,13 +12,15 @@ module Projects ...@@ -11,13 +12,15 @@ module Projects
end end
def execute def execute
register_attempt
# Create status notifying the deployment of pages # Create status notifying the deployment of pages
@status = create_status @status = create_status
@status.enqueue! @status.enqueue!
@status.run! @status.run!
raise 'missing pages artifacts' unless build.artifacts? raise InvaildStateError, 'missing pages artifacts' unless build.artifacts?
raise 'pages are outdated' unless latest? raise InvaildStateError, 'pages are outdated' unless latest?
# Create temporary directory in which we will extract the artifacts # Create temporary directory in which we will extract the artifacts
FileUtils.mkdir_p(tmp_path) FileUtils.mkdir_p(tmp_path)
...@@ -26,24 +29,22 @@ module Projects ...@@ -26,24 +29,22 @@ module Projects
# Check if we did extract public directory # Check if we did extract public directory
archive_public_path = File.join(archive_path, 'public') archive_public_path = File.join(archive_path, 'public')
raise 'pages miss the public folder' unless Dir.exist?(archive_public_path) raise InvaildStateError, 'pages miss the public folder' unless Dir.exist?(archive_public_path)
raise 'pages are outdated' unless latest? raise InvaildStateError, 'pages are outdated' unless latest?
deploy_page!(archive_public_path) deploy_page!(archive_public_path)
success success
end end
rescue => e rescue InvaildStateError => e
register_failure register_failure
error(e.message) error(e.message)
ensure
register_attempt
build.erase_artifacts! unless build.has_expiring_artifacts?
end end
private private
def success def success
@status.success @status.success
delete_artifact!
super super
end end
...@@ -52,6 +53,7 @@ module Projects ...@@ -52,6 +53,7 @@ module Projects
@status.allow_failure = !latest? @status.allow_failure = !latest?
@status.description = message @status.description = message
@status.drop(:script_failure) @status.drop(:script_failure)
delete_artifact!
super super
end end
...@@ -163,6 +165,11 @@ module Projects ...@@ -163,6 +165,11 @@ module Projects
build.artifacts_file.path build.artifacts_file.path
end end
def delete_artifact!
build.reload
build.erase_artifacts! unless build.has_expiring_artifacts?
end
def latest_sha def latest_sha
project.commit(build.ref).try(:sha).to_s project.commit(build.ref).try(:sha).to_s
end end
......
class PagesWorker class PagesWorker
include ApplicationWorker include ApplicationWorker
sidekiq_options retry: false sidekiq_options retry: 3
def perform(action, *arg) def perform(action, *arg)
send(action, *arg) # rubocop:disable GitlabSecurity/PublicSend send(action, *arg) # rubocop:disable GitlabSecurity/PublicSend
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment