Skip to content

Commit 9e7cc18

Browse files
authored
fix: prevent concurrent processing for automotivelinux repos [CM-1103] (#4015)
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent a456787 commit 9e7cc18

File tree

1 file changed

+17
-1
lines changed
  • services/apps/git_integration/src/crowdgit/database

1 file changed

+17
-1
lines changed

services/apps/git_integration/src/crowdgit/database/crud.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,30 @@ async def acquire_repository(query: str, params: tuple = None) -> Repository | N
125125
async def acquire_recurrent_repo() -> Repository | None:
126126
"""Acquire a regular (non-onboarding) repository, that were not processed in the last x hours (REPOSITORY_UPDATE_INTERVAL_HOURS)"""
127127
recurrent_repo_sql_query = f"""
128-
WITH selected_repo AS (
128+
-- Rate-limit guard: Gerrit (automotivelinux) aggressively rate-limits concurrent connections.
129+
-- This CTE checks if any automotivelinux repo is already being processed,
130+
-- so we skip picking another one from the same host until the current one finishes.
131+
WITH automotivelinux_processing AS (
132+
SELECT 1
133+
FROM git."repositoryProcessing" rp2
134+
JOIN public.repositories r2 ON r2.id = rp2."repositoryId"
135+
WHERE rp2.state = 'processing'
136+
AND rp2."lockedAt" IS NOT NULL
137+
AND r2.url LIKE '%gerrit.automotivelinux.org%'
138+
LIMIT 1
139+
),
140+
selected_repo AS (
129141
SELECT r.id
130142
FROM public.repositories r
131143
JOIN git."repositoryProcessing" rp ON rp."repositoryId" = r.id
132144
WHERE NOT (rp.state = ANY($2))
133145
AND rp."lockedAt" IS NULL
134146
AND r."deletedAt" IS NULL
135147
AND rp."lastProcessedAt" < NOW() - INTERVAL '1 hour' * $3
148+
AND NOT (
149+
r.url LIKE '%gerrit.automotivelinux.org%'
150+
AND EXISTS (SELECT 1 FROM automotivelinux_processing)
151+
)
136152
ORDER BY rp.priority ASC, rp."lastProcessedAt" ASC
137153
LIMIT 1
138154
FOR UPDATE OF rp SKIP LOCKED

0 commit comments

Comments
 (0)