Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dispatch/cost_model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CostModelActivity(Base):
id = Column(Integer, primary_key=True)
plugin_event_id = Column(Integer, ForeignKey(PluginEvent.id, ondelete="CASCADE"))
plugin_event = relationship(PluginEvent, backref="plugin_event")
response_time_seconds = Column(Integer, default=300)
response_time_seconds = Column(Integer, default=0)
enabled = Column(Boolean, default=True)


Expand All @@ -69,7 +69,7 @@ class CostModelActivityBase(DispatchBase):
"""Base class for cost model activity resources"""

plugin_event: PluginEventRead
response_time_seconds: int | None = 300
response_time_seconds: int | None = None
enabled: bool | None = Field(True, nullable=True)


Expand Down
11 changes: 6 additions & 5 deletions src/dispatch/cost_model/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_default(*, db_session, project_id: int) -> CostModel:
return (
db_session.query(CostModel)
.filter(CostModel.project_id == project_id)
.order_by(CostModel.created_at.desc())
.order_by(CostModel.created_at.asc())
.first()
)

Expand Down Expand Up @@ -70,7 +70,7 @@ def update_cost_model_activity(*, db_session, cost_model_activity_in: CostModelA
db_session=db_session, cost_model_activity_id=cost_model_activity_in.id
)

cost_model_activity.response_time_seconds = cost_model_activity_in.response_time_seconds
cost_model_activity.response_time_seconds = 0
cost_model_activity.enabled = cost_model_activity_in.enabled
cost_model_activity.plugin_event_id = cost_model_activity_in.plugin_event.id

Expand Down Expand Up @@ -104,12 +104,12 @@ def delete(*, db_session, cost_model_id: int):
db_session.commit()


def update(*, db_session, cost_model_in: CostModelUpdate) -> CostModel:
def update(*, db_session, cost_model_in: CostModelUpdate, cost_model_id: int) -> CostModel:
"""Updates a cost model."""
if not has_unique_plugin_event(cost_model_in):
raise KeyError("Unable to update cost model. Duplicate plugin event ids detected.")

cost_model = get_cost_model_by_id(db_session=db_session, cost_model_id=cost_model_in.id)
cost_model = get_cost_model_by_id(db_session=db_session, cost_model_id=cost_model_id)
if not cost_model:
raise ValueError("Unable to update cost model. No cost model found with that id.")

Expand All @@ -121,6 +121,8 @@ def update(*, db_session, cost_model_in: CostModelUpdate) -> CostModel:
cost_model_in.updated_at if cost_model_in.updated_at else datetime.utcnow()
)

cost_model.updated_at = cost_model.created_at

# Update all recognized activities. Delete all removed activities.
update_activities = []
delete_activities = []
Expand All @@ -132,7 +134,6 @@ def update(*, db_session, cost_model_in: CostModelUpdate) -> CostModel:
update_activities.append((activity, activity_in))
cost_model_in.activities.pop(idx_in)
updated = True
break
if updated:
continue

Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/cost_model/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_cost_model(

@router.put(
"/{cost_model_id}",
summary="Modifies an existing cost model.",
summary="Creates a new cost model.",
response_model=CostModelRead,
dependencies=[Depends(PermissionsDependency([SensitiveProjectActionPermission]))],
)
Expand Down