summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/pipeline.rb6
-rw-r--r--app/models/ci/ref.rb13
-rw-r--r--app/models/concerns/enums/internal_id.rb3
-rw-r--r--app/models/ml/candidate.rb9
4 files changed, 18 insertions, 13 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 7c4da0bc01e..a1db808feb5 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -325,12 +325,6 @@ module Ci
end
end
- after_transition running: ::Ci::Pipeline.completed_statuses + [:manual] do |pipeline|
- pipeline.run_after_commit do
- ::Ci::UnlockRefArtifactsOnPipelineStopWorker.perform_async(pipeline.id)
- end
- end
-
after_transition any => [:success, :failed] do |pipeline|
ref_status = pipeline.ci_ref&.update_status_by!(pipeline)
diff --git a/app/models/ci/ref.rb b/app/models/ci/ref.rb
index 32ea63b63d1..199e1cd07e7 100644
--- a/app/models/ci/ref.rb
+++ b/app/models/ci/ref.rb
@@ -30,6 +30,15 @@ module Ci
state :fixed, value: 3
state :broken, value: 4
state :still_failing, value: 5
+
+ after_transition any => [:fixed, :success] do |ci_ref|
+ # Do not try to unlock if no artifacts are locked
+ next unless ci_ref.artifacts_locked?
+
+ ci_ref.run_after_commit do
+ Ci::PipelineSuccessUnlockArtifactsWorker.perform_async(ci_ref.last_finished_pipeline_id)
+ end
+ end
end
class << self
@@ -46,10 +55,6 @@ module Ci
Ci::Pipeline.last_finished_for_ref_id(self.id)&.id
end
- def last_successful_pipeline
- pipelines.ci_sources.success.order(id: :desc).take
- end
-
def artifacts_locked?
self.pipelines.where(locked: :artifacts_locked).exists?
end
diff --git a/app/models/concerns/enums/internal_id.rb b/app/models/concerns/enums/internal_id.rb
index a8227363a22..8e161c1513f 100644
--- a/app/models/concerns/enums/internal_id.rb
+++ b/app/models/concerns/enums/internal_id.rb
@@ -17,7 +17,8 @@ module Enums
sprints: 9, # iterations
design_management_designs: 10,
incident_management_oncall_schedules: 11,
- ml_experiments: 12
+ ml_experiments: 12,
+ ml_candidates: 13
}
end
end
diff --git a/app/models/ml/candidate.rb b/app/models/ml/candidate.rb
index 02da09e6b51..c1409da05ec 100644
--- a/app/models/ml/candidate.rb
+++ b/app/models/ml/candidate.rb
@@ -3,7 +3,9 @@
module Ml
class Candidate < ApplicationRecord
include Sortable
+ include AtomicInternalId
include IgnorableColumns
+
ignore_column :iid, remove_with: '16.0', remove_after: '2023-05-01'
PACKAGE_PREFIX = 'ml_candidate_'
@@ -16,6 +18,7 @@ module Ml
belongs_to :experiment, class_name: 'Ml::Experiment'
belongs_to :user
belongs_to :package, class_name: 'Packages::Package'
+ belongs_to :project
has_many :metrics, class_name: 'Ml::CandidateMetric'
has_many :params, class_name: 'Ml::CandidateParam'
has_many :metadata, class_name: 'Ml::CandidateMetadata'
@@ -23,6 +26,10 @@ module Ml
attribute :eid, default: -> { SecureRandom.uuid }
+ has_internal_id :internal_id,
+ scope: :project,
+ init: AtomicInternalId.project_init(self, :internal_id)
+
scope :including_relationships, -> { includes(:latest_metrics, :params, :user, :package) }
scope :by_name, ->(name) { where("ml_candidates.name LIKE ?", "%#{sanitize_sql_like(name)}%") } # rubocop:disable GitlabSecurity/SqlInjection
scope :order_by_metric, ->(metric, direction) do
@@ -49,8 +56,6 @@ module Ml
)
end
- delegate :project_id, :project, to: :experiment
-
alias_attribute :artifact, :package
# Remove alias after https://gitlab.com/gitlab-org/gitlab/-/merge_requests/115401