Class: Ci::JobArtifacts::CreateService

Inherits:
BaseService show all
Includes:
Gitlab::Utils::UsageData
Defined in:
app/services/ci/job_artifacts/create_service.rb

Constant Summary collapse

ArtifactsExistError =
Class.new(StandardError)
LSIF_ARTIFACT_TYPE =
'lsif'
METRICS_REPORT_UPLOAD_EVENT_NAME =
'i_testing_metrics_report_artifact_uploaders'
OBJECT_STORAGE_ERRORS =
[
  Errno::EIO,
  Google::Apis::ServerError,
  Signet::RemoteServerError
].freeze

Constants included from Gitlab::Utils::UsageData

Gitlab::Utils::UsageData::DISTRIBUTED_HLL_FALLBACK, Gitlab::Utils::UsageData::FALLBACK, Gitlab::Utils::UsageData::HISTOGRAM_FALLBACK, Gitlab::Utils::UsageData::MAX_BUCKET_SIZE

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params

Instance Method Summary collapse

Methods included from Gitlab::Utils::UsageData

#add, #add_metric, #alt_usage_data, #count, #distinct_count, #epics_deepest_relationship_level, #estimate_batch_distinct_count, #histogram, #jira_integration_data, #maximum_id, #measure_duration, #minimum_id, #redis_usage_data, #sum, #track_usage_event, #with_duration, #with_finished_at, #with_prometheus_client

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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(job) ⇒ CreateService

Returns a new instance of CreateService.


19
20
21
22
23
# File 'app/services/ci/job_artifacts/create_service.rb', line 19

def initialize(job)
  @job = job
  @project = job.project
  @pipeline = job.pipeline if ::Feature.enabled?(:ci_update_unlocked_job_artifacts, @project)
end

Instance Method Details

#authorize(artifact_type:, filesize: nil) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/ci/job_artifacts/create_service.rb', line 25

def authorize(artifact_type:, filesize: nil)
  result = validate_requirements(artifact_type: artifact_type, filesize: filesize)
  return result unless result[:status] == :success

  headers = JobArtifactUploader.workhorse_authorize(has_length: false, maximum_size: max_size(artifact_type))

  if lsif?(artifact_type)
    headers[:ProcessLsif] = true
    track_usage_event('i_source_code_code_intelligence', project.id)
  end

  success(headers: headers)
end

#execute(artifacts_file, params, metadata_file: nil) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/services/ci/job_artifacts/create_service.rb', line 39

def execute(artifacts_file, params, metadata_file: nil)
  result = validate_requirements(artifact_type: params[:artifact_type], filesize: artifacts_file.size)
  return result unless result[:status] == :success

  return success if sha256_matches_existing_artifact?(params[:artifact_type], artifacts_file)

  artifact,  = build_artifact(artifacts_file, params, )
  result = parse_artifact(artifact)

  track_artifact_uploader(artifact)

  return result unless result[:status] == :success

  persist_artifact(artifact, , params)
end