Class: Ml::Experiment

Inherits:
ApplicationRecord show all
Includes:
AtomicInternalId, Presentable, Sortable
Defined in:
app/models/ml/experiment.rb

Constant Summary collapse

PACKAGE_PREFIX =
'ml_experiment_'

Constants included from AtomicInternalId

AtomicInternalId::MissingValueError

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 included from Presentable

#present

Methods included from AtomicInternalId

group_init, #internal_id_read_scope, #internal_id_scope_attrs, #internal_id_scope_usage, namespace_init, project_init, scope_attrs, scope_usage

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

.by_project_id_and_iid(project_id, iid) ⇒ Object



54
55
56
# File 'app/models/ml/experiment.rb', line 54

def by_project_id_and_iid(project_id, iid)
  find_by(project_id: project_id, iid: iid)
end

.by_project_id_and_name(project_id, name) ⇒ Object



58
59
60
# File 'app/models/ml/experiment.rb', line 58

def by_project_id_and_name(project_id, name)
  find_by(project_id: project_id, name: name)
end

.find_or_create(project, name, user) ⇒ Object



70
71
72
# File 'app/models/ml/experiment.rb', line 70

def find_or_create(project, name, user)
  create_with(user: user).find_or_create_by(project: project, name: name)
end

.package_for_experiment?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'app/models/ml/experiment.rb', line 62

def package_for_experiment?(package_name)
  return false unless package_name&.starts_with?(PACKAGE_PREFIX)

  iid = package_name.delete_prefix(PACKAGE_PREFIX)

  numeric?(iid)
end

Instance Method Details

#for_model?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/ml/experiment.rb', line 40

def for_model?
  model.present?
end

#package_nameObject



34
35
36
37
38
# File 'app/models/ml/experiment.rb', line 34

def package_name
  return model.name if for_model?

  "#{PACKAGE_PREFIX}#{iid}"
end

#stop_destroyObject



44
45
46
47
48
49
50
51
# File 'app/models/ml/experiment.rb', line 44

def stop_destroy
  return unless model_id

  errors.add(:base, "Cannot delete an experiment associated to a model")
  # According to docs, throw is the correct way to stop on a callback
  # https://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#module-ActiveRecord::Callbacks-label-Canceling+callbacks
  throw :abort # rubocop:disable Cop/BanCatchThrow
end