Skip to content

feat: [AAP-46254] trigger project resync after project update #1323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kaiokmo
Copy link
Member

@kaiokmo kaiokmo commented Jun 2, 2025

This commit causes auto sync/import of a project when one of its url, scm_branch, or scm_refspec is updated,
without the user having to manually trigger the sync via the UI/API.

https://issues.redhat.com/browse/AAP-46254

@kaiokmo kaiokmo requested a review from a team as a code owner June 2, 2025 17:44
@kaiokmo kaiokmo added enhancement New feature or request run-e2e labels Jun 2, 2025
@kaiokmo kaiokmo force-pushed the AAP-46254 branch 2 times, most recently from 183e8ed to a54107e Compare June 2, 2025 17:50
@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2025

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.91%. Comparing base (05598a1) to head (44608a8).

Files with missing lines Patch % Lines
src/aap_eda/api/views/project.py 77.77% 2 Missing ⚠️
@@            Coverage Diff             @@
##             main    #1323      +/-   ##
==========================================
- Coverage   93.91%   93.91%   -0.01%     
==========================================
  Files         318      318              
  Lines       18741    18762      +21     
==========================================
+ Hits        17601    17620      +19     
- Misses       1140     1142       +2     
Flag Coverage Δ
unit-int-tests-3.11 93.85% <90.47%> (-0.01%) ⬇️
unit-int-tests-3.12 93.91% <90.47%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
tests/integration/api/test_project.py 99.45% <100.00%> (+0.01%) ⬆️
src/aap_eda/api/views/project.py 95.23% <77.77%> (-1.64%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -185,3 +185,44 @@ def _monitor_project_tasks(queue_name: str) -> None:
project.save(update_fields=["import_task_id", "modified_at"])

logger.info("Task complete: Monitor project tasks")


def trigger_project_sync_or_import(
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO this logic is in the wrong place. This is not a task logic, is project logic and it should not be in this file. Deciding when to sync or import the project should be consistent with what we already do in create and sync views by calling tasks.import_project, so it should be placed in the view.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't that add unnecessary logic to the view, by checking whether the fields are being passed in the request and are indeed different from the fields in the existing project, and then calling the needed function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, if we leave it in the view, it means the partial_update function should check if there's an import or sync already running before triggering, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, this is not so trivial. In /sync we already raise conflict if it is pending or running. Here we are in a similar situation. The problem is that we don't have a request queue like we have for activations, so we can not enqueue more than one task for the same project. There are two possible scenarios where this is a potential problem:

  • Project is updated when it has not been imported yet at creation (unlikely but possible)
  • Project is updated when a sync is already pending or running.

In both cases, there would be a possibility that the project would not be imported with the most recent data because we would not be running the import/sync task because there is another one in process that might be executed with the data prior the update.

So, at this point, I only see two possibilities:

  1. We raise conflict if you try to update a project that is pending or running same as we already do with sync.
  2. We implement a full request-queue logic, maybe better to be implemented with the future job management feature.

I would say for now we can go with option 1. Thoughts? @bzwei

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not raise conflict. We should wait and continue the project sync after the current has finished. Consider two users work on the same project at the same time, one issues a sync command and the other changes the project url.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The view can compare the updated fields and decide whether to start a resync task. There is no need to detect whether git_hash exists or not. project_sync can handle the case when the previous import failed and there was no rulebook imported.

This commit causes auto sync/import of a project when one of its
url or scm_branch/tag/commit is updated, without the user having
to manually trigger the sync via the UI/API.
Copy link

sonarqubecloud bot commented Jun 9, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request run-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants