mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 17:08:27 +00:00
* Feat: added integration connect and mcp oAuth * Feat: add mcp support to chat * Fix: UI for integrations and logs * Fix: ui * Fix: proxy server * Feat: enhance MCP tool integration and loading functionality * Fix: added header * Fix: Linear integration sync --------- Co-authored-by: Manoj K <saimanoj58@gmail.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { PrismaClient } from "@prisma/client";
|
|
import { IntegrationEventType } from "@core/types";
|
|
import { logger, schedules, tasks } from "@trigger.dev/sdk/v3";
|
|
|
|
import { type integrationRun } from "./integration-run";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
export const integrationRunSchedule = schedules.task({
|
|
id: "integration-run-schedule",
|
|
run: async (payload) => {
|
|
const { externalId } = payload;
|
|
if (!externalId) {
|
|
logger.info("No externalId provided");
|
|
return null;
|
|
}
|
|
|
|
const integrationAccount = await prisma.integrationAccount.findUnique({
|
|
where: { id: externalId },
|
|
include: {
|
|
integrationDefinition: true,
|
|
workspace: true,
|
|
},
|
|
});
|
|
|
|
if (!integrationAccount) {
|
|
const deletedSchedule = await schedules.del(externalId);
|
|
logger.info("No integration account found, deleting schedule");
|
|
return deletedSchedule;
|
|
}
|
|
|
|
if (!integrationAccount.workspace.userId) {
|
|
logger.info("No workspace user id found");
|
|
return null;
|
|
}
|
|
|
|
logger.info("Triggering scheduled integration run", {
|
|
integrationId: integrationAccount.integrationDefinition.id,
|
|
integrationSlug: integrationAccount.integrationDefinition.slug,
|
|
accountId: integrationAccount.id,
|
|
});
|
|
|
|
return await tasks.trigger<typeof integrationRun>("integration-run", {
|
|
event: IntegrationEventType.SYNC,
|
|
integrationAccount,
|
|
integrationDefinition: integrationAccount.integrationDefinition,
|
|
eventBody: {
|
|
scheduled: true,
|
|
scheduledAt: new Date().toISOString(),
|
|
},
|
|
});
|
|
},
|
|
});
|