in docker/services/recommendation_history_service.py [0:0]
def _create_or_update_recent(self, instance_id, job_id, customer, tenant,
region, current_instance_type,
current_month_price_usd, recommendation_type,
recommendation, savings, instance_meta):
recent_recommendations = self.get_recent_recommendation(
instance_id=instance_id,
recommendation_type=recommendation_type,
without_feedback=True
)
if recommendation is not None and not isinstance(recommendation, list):
recommendation = [recommendation]
if not recent_recommendations:
_LOG.debug(f'No recent \'{recommendation_type}\' recommendation '
f'found for instance \'{instance_id}\'. Creating new '
f'record.')
return RecommendationHistory(
instance_id=instance_id,
job_id=job_id,
customer=customer,
tenant=tenant,
region=region,
current_instance_type=current_instance_type,
current_month_price_usd=current_month_price_usd,
recommendation_type=recommendation_type,
recommendation=recommendation,
savings=savings,
instance_meta=instance_meta
)
recent_recommendations = list(recent_recommendations)
if len(recent_recommendations) > 1:
_LOG.error(f'More than one recent recommendation found. '
f'Deleting all except the most recent')
for recommendation in recent_recommendations[1:]:
self.delete(recommendation=recommendation)
recent_recommendation: RecommendationHistory = recent_recommendations[0]
_LOG.debug(f'Recent recommendation found, updating.')
recent_recommendation.update(
job_id=job_id,
customer=customer,
tenant=tenant,
region=region,
added_at=datetime.datetime.utcnow(),
current_instance_type=current_instance_type,
current_month_price_usd=current_month_price_usd,
recommendation=recommendation,
savings=savings,
instance_meta=instance_meta
)
return recent_recommendation