Class: Projects::UpdatePagesService

Inherits:
BaseService show all
Defined in:
app/services/projects/update_pages_service.rb

Constant Summary collapse

InvalidStateError =
Class.new(StandardError)
WrongUploadedDeploymentSizeError =
Class.new(StandardError)
BLOCK_SIZE =
32.kilobytes
PUBLIC_DIR =
'public'
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.freeze

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.


17
18
19
20
# File 'app/services/projects/update_pages_service.rb', line 17

def initialize(project, build)
  @project = project
  @build = build
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.


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

def build
  @build
end

Instance Method Details

#executeObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/projects/update_pages_service.rb', line 22

def execute
  register_attempt

  # Create status notifying the deployment of pages
  @commit_status = build_commit_status
  ::Ci::Pipelines::AddJobService.new(@build.pipeline).execute!(@commit_status) do |job|
    job.enqueue!
    job.run!
  end

  validate_state!
  validate_max_size!
  validate_public_folder!
  validate_max_entries!

  build.artifacts_file.use_file do |artifacts_path|
    create_pages_deployment(artifacts_path, build)
    success
  end
rescue InvalidStateError => e
  error(e.message)
rescue WrongUploadedDeploymentSizeError => e
  error("Uploading artifacts to pages storage failed")
  raise e
rescue StandardError => e
  error(e.message)
  raise e
end