Skip to content

Commit 0cddf49

Browse files
fix(app): fix AWS cloud test error caused by improper usage of batchTriggerAndWait (#1608)
Co-authored-by: chasprowebdev <chasgarciaprowebdev@gmail.com>
1 parent 159df61 commit 0cddf49

2 files changed

Lines changed: 100 additions & 46 deletions

File tree

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use server';
22

3-
import { sendIntegrationResults } from '@/jobs/tasks/integration/integration-results';
3+
import { runIntegrationTests } from '@/jobs/tasks/integration/run-integration-tests';
44
import { auth } from '@/utils/auth';
5-
import { db } from '@db';
65
import { tasks } from '@trigger.dev/sdk';
76
import { revalidatePath } from 'next/cache';
87
import { headers } from 'next/headers';
@@ -27,54 +26,29 @@ export const runTests = async () => {
2726
};
2827
}
2928

30-
const integrations = await db.integration.findMany({
31-
where: {
29+
try {
30+
const handle = await tasks.trigger<typeof runIntegrationTests>('run-integration-tests', {
3231
organizationId: orgId,
33-
integrationId: {
34-
in: ['aws', 'gcp', 'azure'],
35-
},
36-
},
37-
select: {
38-
id: true,
39-
name: true,
40-
integrationId: true,
41-
settings: true,
42-
userSettings: true,
43-
organization: {
44-
select: {
45-
id: true,
46-
name: true,
47-
},
48-
},
49-
},
50-
});
32+
});
33+
34+
const headersList = await headers();
35+
let path =
36+
headersList.get("x-pathname") || headersList.get("referer") || "";
37+
path = path.replace(/\/[a-z]{2}\//, "/");
38+
39+
revalidatePath(path);
5140

52-
if (!integrations) {
41+
return {
42+
success: true,
43+
errors: null,
44+
taskId: handle.id,
45+
};
46+
} catch (error) {
47+
console.error('Error triggering integration tests:', error);
48+
5349
return {
5450
success: false,
55-
errors: ['No integrations found'],
51+
errors: [error instanceof Error ? error.message : 'Failed to trigger integration tests'],
5652
};
5753
}
58-
59-
const batchHandle = await tasks.batchTriggerAndWait<typeof sendIntegrationResults>(
60-
'send-integration-results',
61-
integrations.map((integration) => ({
62-
payload: {
63-
integration: {
64-
id: integration.id,
65-
name: integration.name,
66-
integration_id: integration.integrationId,
67-
settings: integration.settings,
68-
user_settings: integration.userSettings,
69-
organization: integration.organization,
70-
},
71-
},
72-
})),
73-
);
74-
75-
revalidatePath(`/${orgId}/tests/dashboard`);
76-
return {
77-
success: true,
78-
errors: null,
79-
};
8054
};
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { db } from '@db';
2+
import { logger, task } from '@trigger.dev/sdk';
3+
import { sendIntegrationResults } from './integration-results';
4+
5+
export const runIntegrationTests = task({
6+
id: 'run-integration-tests',
7+
run: async (payload: { organizationId: string }) => {
8+
const { organizationId } = payload;
9+
10+
logger.info(`Running integration tests for organization: ${organizationId}`);
11+
12+
const integrations = await db.integration.findMany({
13+
where: {
14+
organizationId: organizationId,
15+
integrationId: {
16+
in: ['aws', 'gcp', 'azure'],
17+
},
18+
},
19+
select: {
20+
id: true,
21+
name: true,
22+
integrationId: true,
23+
settings: true,
24+
userSettings: true,
25+
organization: {
26+
select: {
27+
id: true,
28+
name: true,
29+
},
30+
},
31+
},
32+
});
33+
34+
if (!integrations || integrations.length === 0) {
35+
logger.warn(`No integrations found for organization: ${organizationId}`);
36+
return {
37+
success: false,
38+
error: 'No integrations found',
39+
organizationId,
40+
};
41+
}
42+
43+
logger.info(`Found ${integrations.length} integrations to test for organization: ${organizationId}`);
44+
45+
const batchItems = integrations.map((integration) => ({
46+
payload: {
47+
integration: {
48+
id: integration.id,
49+
name: integration.name,
50+
integration_id: integration.integrationId,
51+
settings: integration.settings,
52+
user_settings: integration.userSettings,
53+
organization: integration.organization,
54+
},
55+
},
56+
}));
57+
58+
try {
59+
const batchHandle = await sendIntegrationResults.batchTriggerAndWait(batchItems);
60+
61+
logger.info(`Successfully completed batch integration tests for organization: ${organizationId}`);
62+
63+
return {
64+
success: true,
65+
organizationId,
66+
integrationsCount: integrations.length,
67+
batchHandleId: batchHandle.id,
68+
};
69+
} catch (error) {
70+
logger.error(`Failed to run integration tests for organization ${organizationId}: ${error}`);
71+
72+
return {
73+
success: false,
74+
error: error instanceof Error ? error.message : String(error),
75+
organizationId,
76+
integrationsCount: integrations.length,
77+
};
78+
}
79+
},
80+
});

0 commit comments

Comments
 (0)