Skip to content

Commit ce23e77

Browse files
committed
fix: comments
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent cc4700f commit ce23e77

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

services/apps/automatic_onboarding_worker/src/activities/activities.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ export async function fetchProjectsPendingOnboarding(
2424
return projects
2525
}
2626

27+
async function findAlreadyOnboarded(
28+
qx: ReturnType<typeof pgpQx>,
29+
projectId: string,
30+
): Promise<IDbProjectCatalog | null> {
31+
const fresh = await findProjectCatalogById(qx, projectId)
32+
return fresh?.onboardedAt ? fresh : null
33+
}
34+
2735
export async function onboardAndUpdateProject(project: IDbProjectCatalog): Promise<void> {
2836
const qx = pgpQx(svc.postgres.writer.connection())
2937
const startTime = Date.now()
3038

31-
// Guard: fetch fresh state to ensure the API is called at most once per project.
32-
// Uses the writer connection to avoid replica lag missing a just-written onboardedAt.
33-
const fresh = await findProjectCatalogById(qx, project.id)
34-
if (fresh?.onboardedAt) {
39+
// Guard: uses the writer connection to avoid replica lag missing a just-written onboardedAt.
40+
const fresh = await findAlreadyOnboarded(qx, project.id)
41+
if (fresh) {
3542
log.info(
3643
{ id: project.id, repoUrl: project.repoUrl, onboardedAt: fresh.onboardedAt },
3744
'Project already onboarded, skipping API call.',
@@ -70,6 +77,16 @@ export async function markProjectOnboardingFailed(
7077
): Promise<void> {
7178
const qx = pgpQx(svc.postgres.writer.connection())
7279

80+
// Guard: the write may have succeeded after the API call before retries were exhausted.
81+
const fresh = await findAlreadyOnboarded(qx, projectId)
82+
if (fresh) {
83+
log.info(
84+
{ id: projectId, onboardedAt: fresh.onboardedAt },
85+
'Project was already onboarded despite the reported failure, not marking as error.',
86+
)
87+
return
88+
}
89+
7390
await updateProjectCatalog(qx, projectId, {
7491
action: 'error',
7592
onboardingError: reason,

services/apps/automatic_onboarding_worker/src/schedules/scheduleProjectsOnboarding.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ export const scheduleProjectsOnboarding = async () => {
1919
},
2020
policies: {
2121
overlap: ScheduleOverlapPolicy.SKIP,
22-
catchupWindow: '1 minute',
22+
catchupWindow: '1 hour',
2323
},
2424
action: {
2525
type: 'startWorkflow',
2626
workflowType: onboardProjects,
2727
taskQueue: 'automatic-onboarding',
2828
args: [ONBOARDING_ARGS],
29-
// 50 projects × up to ~2min per attempt, up to 2 attempts each = ~3.3h worst case; set ceiling with margin.
30-
workflowExecutionTimeout: '6 hours',
29+
workflowExecutionTimeout: '14 hours',
3130
retry: {
3231
initialInterval: '30 seconds',
3332
backoffCoefficient: 2,

services/apps/automatic_onboarding_worker/src/workflows/onboardProjects.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ const fetchActivities = proxyActivities<typeof activities>({
99
retry: { maximumAttempts: 3 },
1010
})
1111

12-
// Each onboarding call chains a segment create/query plus GitHub enrichment and integration calls; give generous headroom per project.
12+
// Each onboarding call chains a segment create/query plus GitHub enrichment and integration calls,
13+
// each of which can individually approach a ~30s backend timeout; give generous headroom per project.
1314
const onboardActivities = proxyActivities<typeof activities>({
15+
startToCloseTimeout: '5 minutes',
16+
retry: { maximumAttempts: 2 },
17+
})
18+
19+
const failureActivities = proxyActivities<typeof activities>({
1420
startToCloseTimeout: '2 minutes',
1521
retry: { maximumAttempts: 2 },
1622
})
@@ -49,7 +55,7 @@ export async function onboardProjects(input: IOnboardProjectsInput = {}): Promis
4955
)
5056

5157
try {
52-
await onboardActivities.markProjectOnboardingFailed(project.id, reason)
58+
await failureActivities.markProjectOnboardingFailed(project.id, reason)
5359
} catch (markErr) {
5460
// Don't let a failure to record the error state abort the rest of the batch.
5561
log.error(`Failed to mark project id=${project.id} as errored: ${String(markErr)}`)

services/libs/data-access-layer/src/project-catalog/projectCatalog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export async function upsertProjectCatalog(
336336
"repoName" = EXCLUDED."repoName",
337337
"source" = COALESCE(EXCLUDED."source", "projectCatalog"."source"),
338338
"action" = CASE
339-
WHEN "projectCatalog"."action" IN ('onboard', 'skip', 'unsure') THEN "projectCatalog"."action"
339+
WHEN "projectCatalog"."action" IN ('onboard', 'skip', 'unsure', 'error') THEN "projectCatalog"."action"
340340
WHEN EXCLUDED.action = 'evaluate' THEN 'evaluate'
341341
ELSE "projectCatalog"."action"
342342
END,
@@ -409,7 +409,7 @@ export async function bulkUpsertProjectCatalog(
409409
"repoName" = EXCLUDED."repoName",
410410
"source" = COALESCE(EXCLUDED."source", "projectCatalog"."source"),
411411
"action" = CASE
412-
WHEN "projectCatalog"."action" IN ('onboard', 'skip', 'unsure') THEN "projectCatalog"."action"
412+
WHEN "projectCatalog"."action" IN ('onboard', 'skip', 'unsure', 'error') THEN "projectCatalog"."action"
413413
WHEN EXCLUDED.action = 'evaluate' THEN 'evaluate'
414414
ELSE "projectCatalog"."action"
415415
END,

0 commit comments

Comments
 (0)