Class: Ci::ResourceGroup

Inherits:
ApplicationRecord show all
Extended by:
Gitlab::Ci::Model
Defined in:
app/models/ci/resource_group.rb

Instance Method Summary collapse

Methods included from Gitlab::Ci::Model

model_name, table_name_prefix

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#assign_resource_to(build) ⇒ Object

NOTE: This is concurrency-safe method that the subquery in the `UPDATE` works as explicit locking.


22
23
24
# File 'app/models/ci/resource_group.rb', line 22

def assign_resource_to(build)
  resources.free.limit(1).update_all(build_id: build.id) > 0
end

#release_resource_from(build) ⇒ Object


26
27
28
# File 'app/models/ci/resource_group.rb', line 26

def release_resource_from(build)
  resources.retained_by(build).update_all(build_id: nil) > 0
end