Skip to content

Conversation

@ElePT
Copy link
Collaborator

@ElePT ElePT commented Oct 14, 2025

Summary

Details and comments

Follow-up of #1707

@ElePT ElePT force-pushed the refactor-runtime-endpoints branch from e1c927f to a1cac25 Compare October 17, 2025 08:32
…Add use cases for associating and retrieving runtime jobs. Adapt tests to new messages.
@ElePT ElePT force-pushed the refactor-runtime-endpoints branch from c6363cf to acf8201 Compare November 4, 2025 14:39
Copy link
Contributor

@korgan00 korgan00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise it looks good to me.
Should we control something about permissions in the Post?

@Tansito
Copy link
Member

Tansito commented Nov 6, 2025

@ElePT I think you said this was ready for review, right? Can I click on "Ready of review"?

Co-authored-by: Goyo <korgan00@gmail.com>
@ElePT ElePT marked this pull request as ready for review November 7, 2025 08:31
@ElePT ElePT requested a review from a team as a code owner November 7, 2025 08:31
@Tansito Tansito self-requested a review November 17, 2025 15:40
Comment on lines +40 to +44
RuntimeJob.objects.create(
job=job,
runtime_job=runtime_job,
runtime_session=runtime_session,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know accessing to the Django orm in use cases is tempting, but if we are following the Repository approach, all the database accesses (that means, any call to Model.objects.whatever()) should be done through a repository.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific case, this use case is very simple. I guess you can get rid of the use case and call to the repository directly from the endpoint. Having one single call to one repository in the controller is acceptable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point, this case is so simple that I struggled to find the balance between following the approach of other endpoints and adding too much boilerplate. I am fine updating it.

Comment on lines +13 to +36
class GetRuntimeJobsUseCase:
"""Retrieve all RuntimeJob objects associated to a given Job."""

jobs_repository = JobsRepository()

def execute(self, job_id: UUID) -> list[RuntimeJob]:
"""
Return all RuntimeJob objects associated to a given Job.
Args:
job_id: Target Job ID.
Returns:
The list of RuntimeJobs.
Raises:
NotFoundError: If the job does not exist or access is denied.
"""
job = self.jobs_repository.get_job_by_id(job_id)

if job is None:
raise NotFoundError(f"Job [{job_id}] not found")

return job.runtime_jobs.all()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, just create (or reuse) a repository RuntimeRepository with this logic and call it from the endpoint. In the repository, you can safely call to any Model.objects.whatever() method you want :)

Copy link
Member

@Tansito Tansito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this refactor Elena we should be able also to remove this file and also rename the folder jobs_new to just jobs.

I'm fine if we do this last thing later to facilitate the review of the PR also.

@@ -1,8 +1,9 @@
"""
Django Rest framework Job views for api application:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially now that we removed the end-points from this file we should be able to remove it entirely 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants