Class: Ci::UnlockArtifactsService

Inherits:
BaseService show all
Defined in:
app/services/ci/unlock_artifacts_service.rb

Constant Summary collapse

BATCH_SIZE =
100

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

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

This class inherits a constructor from BaseService

Instance Method Details

#execute(ci_ref, before_pipeline = nil) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/ci/unlock_artifacts_service.rb', line 7

def execute(ci_ref, before_pipeline = nil)
  query = <<~SQL.squish
    UPDATE "ci_pipelines"
    SET    "locked" = #{::Ci::Pipeline.lockeds[:unlocked]}
    WHERE  "ci_pipelines"."id" in (
        #{collect_pipelines(ci_ref, before_pipeline).select(:id).to_sql}
        LIMIT  #{BATCH_SIZE}
        FOR  UPDATE SKIP LOCKED
    )
    RETURNING "ci_pipelines"."id";
  SQL

  loop do
    break if ActiveRecord::Base.connection.exec_query(query).empty?
  end
end