Class: Analytics::CycleAnalytics::StageAggregation

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Parentable
Defined in:
app/models/analytics/cycle_analytics/stage_aggregation.rb

Constant Summary collapse

STATS_SIZE_LIMIT =
10

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

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

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.load_batch(batch_size = 100) ⇒ Object



19
20
21
# File 'app/models/analytics/cycle_analytics/stage_aggregation.rb', line 19

def self.load_batch(batch_size = 100)
  enabled.incomplete.prioritized.limit(batch_size)
end

Instance Method Details

#completeObject



45
46
47
# File 'app/models/analytics/cycle_analytics/stage_aggregation.rb', line 45

def complete
  self.last_completed_at = Time.current
end

#cursor_for(model) ⇒ Object



23
24
25
26
27
28
# File 'app/models/analytics/cycle_analytics/stage_aggregation.rb', line 23

def cursor_for(model)
  {
    updated_at: self["last_#{model.table_name}_updated_at"],
    id: self["last_#{model.table_name}_id"]
  }.compact
end

#refresh_last_runObject



35
36
37
# File 'app/models/analytics/cycle_analytics/stage_aggregation.rb', line 35

def refresh_last_run
  self.last_run_at = Time.current
end

#set_cursor(model, cursor) ⇒ Object



30
31
32
33
# File 'app/models/analytics/cycle_analytics/stage_aggregation.rb', line 30

def set_cursor(model, cursor)
  self["last_#{model.table_name}_id"] = cursor[:id]
  self["last_#{model.table_name}_updated_at"] = cursor[:updated_at]
end

#set_stats(runtime, processed_records) ⇒ Object



39
40
41
42
43
# File 'app/models/analytics/cycle_analytics/stage_aggregation.rb', line 39

def set_stats(runtime, processed_records)
  # We only store the last 10 data points
  self.runtimes_in_seconds = (runtimes_in_seconds + [runtime]).last(STATS_SIZE_LIMIT)
  self.processed_records = (self.processed_records + [processed_records]).last(STATS_SIZE_LIMIT)
end