Skip to content

Commit

Permalink
Merge branch 'develop' into fix/CV2-6041-side-kiq-dead-jobs-active-re…
Browse files Browse the repository at this point in the history
…cord-statement-invalid-confirmed-relationship
  • Loading branch information
melsawy committed Feb 26, 2025
2 parents d7dd02f + 8c3871a commit 029943b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
12 changes: 6 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ deploy_qa:
script:
- pip install setuptools==68.0.0
- pip install urllib3==2.0.6
- pip install botocore==1.31.62
- pip install boto3==1.28.62
- pip install botocore==1.34.162
- pip install boto3==1.34.162
- pip install ecs-deploy==1.15.0
- pip install awscli==1.31.13
- pip install awscli==1.33.44
- alias aws='docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION --rm amazon/aws-cli'
- aws ssm get-parameters-by-path --region $AWS_DEFAULT_REGION --path /qa/check-api/ --recursive --with-decryption --output text --query "Parameters[].[Name]" | sed -E 's#/qa/check-api/##' > env.qa.names
- for NAME in `cat env.qa.names`; do echo -n "-s qa-check-api-migration $NAME /qa/check-api/$NAME " >> qa-check-api-migration.env.args; done
Expand Down Expand Up @@ -109,10 +109,10 @@ deploy_live:
script:
- pip install setuptools==68.0.0
- pip install urllib3==2.0.6
- pip install botocore==1.31.62
- pip install boto3==1.28.62
- pip install botocore==1.34.162
- pip install boto3==1.34.162
- pip install ecs-deploy==1.15.0
- pip install awscli==1.31.13
- pip install awscli==1.33.44
- alias aws='docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION --rm amazon/aws-cli'
- aws ssm get-parameters-by-path --region $AWS_DEFAULT_REGION --path /live/check-api/ --recursive --with-decryption --output text --query "Parameters[].[Name]" | sed -E 's#/live/check-api/##' > env.live.names
- for NAME in `cat env.live.names`; do echo -n "-s live-check-api-migration $NAME /live/check-api/$NAME " >> live-check-api-migration.env.args; done
Expand Down
2 changes: 1 addition & 1 deletion app/models/bot/alegre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def self.relationship_model_not_allowed(relationship_model)

def self.report_exception_if_bad_relationship(relationship, pm_id_scores, relationship_type)
if relationship.model.nil? || relationship.weight.nil? || relationship.source_field.nil? || relationship.target_field.nil? || self.relationship_model_not_allowed(relationship.model)
CheckSentry.notify(Bot::Alegre::Error.new("[Alegre] Bad relationship was stored without required metadata"), **{trace: Thread.current.backtrace.join("\n"), relationship: relationship.attributes, relationship_type: relationship_type, pm_id_scores: pm_id_scores})
CheckSentry.notify(Bot::Alegre::Error.new("[Alegre] Bad relationship with ID [#{relationship.id}] was stored without required metadata"), **{trace: Thread.current.backtrace.join("\n"), relationship: relationship.attributes, relationship_type: relationship_type, pm_id_scores: pm_id_scores})
end
end

Expand Down
20 changes: 17 additions & 3 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def create_or_update_parent_id
def self.create_unless_exists(source_id, target_id, relationship_type, options = {})
# Verify that the target is not part of another source; in this case, we should return the existing relationship.
r = Relationship.where(target_id: target_id).where.not(source_id: source_id).last
r.update_options(options) unless r.nil?
return r unless r.nil?
# otherwise we should get the existing relationship based on source, target and type
r = Relationship.where(source_id: source_id, target_id: target_id).last
Expand Down Expand Up @@ -196,9 +197,12 @@ def self.create_unless_exists(source_id, target_id, relationship_type, options =
exception_message = e.message
exception_class = e.class.name
end
elsif r.relationship_type != relationship_type && relationship_type == Relationship.confirmed_type
r.relationship_type = relationship_type
r.save!
else
if r.relationship_type != relationship_type && relationship_type == Relationship.confirmed_type
r.relationship_type = relationship_type
r.save!
end
r.update_options(options)
end
if r.nil?
Rails.logger.error("[Relationship::create_unless_exists] returning nil: source_id #{source_id}, target_id #{target_id}, relationship_type #{relationship_type}.")
Expand Down Expand Up @@ -230,6 +234,16 @@ def self.sync_statuses(item, status)
end
end

def update_options(options)
# should update options if exists and at least on field has a value
if self.model.blank? && !options.values.compact.empty?
options.each do |key, value|
self.send("#{key}=", value) if self.respond_to?("#{key}=")
end
self.save!
end
end

protected

def update_elasticsearch_parent(action = 'create_or_update')
Expand Down
3 changes: 3 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ def filtered_explainers(filters = {})
# Filter by text
query = self.filter_by_keywords(query, filters, 'Explainer') if filters[:text].to_s.size > 2

# Filter by language
query = query.where('explainers.language' => filters[:language].to_a) unless filters[:language].blank?

# Exclude the ones already applied to a target item
target = ProjectMedia.find_by_id(filters[:target_id].to_i)
query = query.where.not(id: target.explainer_ids) unless target.nil?
Expand Down
12 changes: 10 additions & 2 deletions test/models/relationship_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,17 @@ def setup
target = create_project_media team: t
r = nil
assert_difference 'Relationship.count' do
r = Relationship.create_unless_exists(source.id, target.id, Relationship.confirmed_type, { user_id: u.id })
r = Relationship.create_unless_exists(source.id, target.id, Relationship.confirmed_type)
end
assert_equal u.id, r.user_id
# should update options if relationship already exists
assert_nil r.model
another_source = create_project_media team: t
r2 = nil
assert_no_difference 'Relationship.count' do
r2 = Relationship.create_unless_exists(another_source.id, target.id, Relationship.confirmed_type, { model: 'elasticsearch' })
end
assert_equal r, r2
assert_equal 'elasticsearch', r2.model
r2 = nil
assert_no_difference 'Relationship.count' do
r2 = Relationship.create_unless_exists(source.id, target.id, Relationship.confirmed_type)
Expand Down

0 comments on commit 029943b

Please sign in to comment.