Class: Ci::ResourceGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ApplicationRecord
- Ci::ResourceGroup
- Defined in:
- app/models/ci/resource_group.rb
Constant Summary
Constants inherited from ApplicationRecord
Instance Method Summary collapse
-
#assign_resource_to(processable) ⇒ Object
NOTE: This is concurrency-safe method that the subquery in the `UPDATE` works as explicit locking.
- #release_resource_from(processable) ⇒ Object
- #upcoming_processables ⇒ Object
Methods inherited from ApplicationRecord
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Instance Method Details
#assign_resource_to(processable) ⇒ Object
NOTE: This is concurrency-safe method that the subquery in the `UPDATE` works as explicit locking.
26 27 28 |
# File 'app/models/ci/resource_group.rb', line 26 def assign_resource_to(processable) resources.free.limit(1).update_all(build_id: processable.id) > 0 end |
#release_resource_from(processable) ⇒ Object
30 31 32 |
# File 'app/models/ci/resource_group.rb', line 30 def release_resource_from(processable) resources.retained_by(processable).update_all(build_id: nil) > 0 end |
#upcoming_processables ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/ci/resource_group.rb', line 34 def upcoming_processables if unordered? processables.waiting_for_resource elsif oldest_first? processables.waiting_for_resource_or_upcoming .order(Arel.sql("commit_id ASC, #{sort_by_job_status}")) elsif newest_first? processables.waiting_for_resource_or_upcoming .order(Arel.sql("commit_id DESC, #{sort_by_job_status}")) else Ci::Processable.none end end |