Class: Ci::ResourceGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ApplicationRecord
- Ci::ResourceGroup
- Defined in:
- app/models/ci/resource_group.rb
Constant Summary collapse
- RESOURCE_GROUP_PROCESS_MODES =
{ unordered: 0, oldest_first: 1, newest_first: 2, newest_ready_first: 3 }.freeze
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
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.
- #current_processable ⇒ Object
- #release_resource_from(processable) ⇒ Object
- #upcoming_processables ⇒ Object
- #waiting_processables ⇒ Object
Methods inherited from ApplicationRecord
Methods inherited from ApplicationRecord
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::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.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/ci/resource_group.rb', line 29 def assign_resource_to(processable) attrs = { build_id: processable.id, partition_id: processable.partition_id } success = resources.free.limit(1).update_all(attrs) > 0 log_event(success: success, processable: processable, action: "assign resource to processable") success end |
#current_processable ⇒ Object
71 72 73 |
# File 'app/models/ci/resource_group.rb', line 71 def current_processable Ci::Processable.find_by('(id, partition_id) IN (?)', resources.select('build_id, partition_id')) end |
#release_resource_from(processable) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'app/models/ci/resource_group.rb', line 41 def release_resource_from(processable) attrs = { build_id: nil, partition_id: nil } success = resources.retained_by(processable).update_all(attrs) > 0 log_event(success: success, processable: processable, action: "release resource from processable") success end |
#upcoming_processables ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/ci/resource_group.rb', line 50 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}")) elsif newest_ready_first? processables.waiting_for_resource .order(Arel.sql("commit_id DESC, #{sort_by_job_status}")) else Ci::Processable.none end end |
#waiting_processables ⇒ Object
67 68 69 |
# File 'app/models/ci/resource_group.rb', line 67 def waiting_processables processables.waiting_for_resource end |