Class: Projects::UpdatePagesService

Inherits:
BaseService show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/projects/update_pages_service.rb

Constant Summary collapse

OLD_DEPLOYMENTS_DESTRUCTION_DELAY =

old deployment can be cached by pages daemon so we need to give pages daemon some time update cache 10 minutes is enough, but 30 feels safer

30.minutes

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(project, build) ⇒ UpdatePagesService

Returns a new instance of UpdatePagesService.



14
15
16
17
18
# File 'app/services/projects/update_pages_service.rb', line 14

def initialize(project, build)
  @project = project
  @build = build
  @deployment_update = ::Gitlab::Pages::DeploymentUpdate.new(project, build)
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



12
13
14
# File 'app/services/projects/update_pages_service.rb', line 12

def build
  @build
end

#deployment_updateObject (readonly)

Returns the value of attribute deployment_update.



12
13
14
# File 'app/services/projects/update_pages_service.rb', line 12

def deployment_update
  @deployment_update
end

Instance Method Details

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/projects/update_pages_service.rb', line 20

def execute
  register_attempt

  ::Ci::Pipelines::AddJobService.new(@build.pipeline).execute!(commit_status) do |job|
    job.enqueue!
    job.run!
  end

  return error(deployment_update.errors.first.full_message) unless deployment_update.valid?

  build.artifacts_file.use_file do |artifacts_path|
    deployment = create_pages_deployment(artifacts_path, build)

    break error('The uploaded artifact size does not match the expected value') unless deployment
    break error(deployment_update.errors.first.full_message) unless deployment_update.valid?

    update_project_pages_deployment(deployment)
    success
  end
rescue StandardError => e
  error(e.message)
  raise e
end