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
Constants included from ResetOnUnionError
ResetOnUnionError::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
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 29 30 31 32 33 34 35 36 |
# File 'app/models/ci/resource_group.rb', line 26 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
61 62 63 |
# File 'app/models/ci/resource_group.rb', line 61 def current_processable Ci::Processable.find_by('(id, partition_id) IN (?)', resources.select('build_id, partition_id')) end |
#release_resource_from(processable) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/models/ci/resource_group.rb', line 38 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
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/ci/resource_group.rb', line 47 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 |