Skip to content
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

[connectors] Add a worker for Zendesk workflows #8343

Merged
merged 7 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions connectors/src/connectors/zendesk/temporal/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const WORKFLOW_VERSION = 3;
export const WORKFLOW_VERSION = 0;
export const QUEUE_NAME = `zendesk-queue-v${WORKFLOW_VERSION}`;
export const INTERVAL_BETWEEN_SYNCS_MS = 60_000; // 1 minute
39 changes: 39 additions & 0 deletions connectors/src/connectors/zendesk/temporal/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { Context } from "@temporalio/activity";
import { Worker } from "@temporalio/worker";
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";

import { getTemporalWorkerConnection } from "@connectors/lib/temporal";
import { ActivityInboundLogInterceptor } from "@connectors/lib/temporal_monitoring";
import logger from "@connectors/logger/logger";

import * as activities from "./activities";
import { QUEUE_NAME } from "./config";

export async function runZendeskWorker() {
const { connection, namespace } = await getTemporalWorkerConnection();
const worker = await Worker.create({
workflowsPath: require.resolve("./workflows"),
activities,
taskQueue: QUEUE_NAME,
connection,
reuseV8Context: true,
namespace,
maxConcurrentActivityTaskExecutions: 16,
interceptors: {
activityInbound: [
(ctx: Context) => {
return new ActivityInboundLogInterceptor(ctx, logger);
},
],
},
bundlerOptions: {
webpackConfigHook: (config) => {
const plugins = config.resolve?.plugins ?? [];
config.resolve!.plugins = [...plugins, new TsconfigPathsPlugin({})];
return config;
},
},
});

await worker.run();
}
16 changes: 7 additions & 9 deletions connectors/src/connectors/zendesk/temporal/workflows.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import type { ModelId } from "@dust-tt/types";
import { assertNever } from "@dust-tt/types";
import { assertNever } from "@temporalio/common/lib/type-helpers";
import {
executeChild,
proxyActivities,
setHandler,
sleep,
workflowInfo,
} from "@temporalio/workflow";

import type * as activities from "@connectors/connectors/zendesk/temporal/activities";
import { syncZendeskTicketsActivity } from "@connectors/connectors/zendesk/temporal/activities";
import { INTERVAL_BETWEEN_SYNCS_MS } from "@connectors/connectors/zendesk/temporal/config";
import type { ZendeskUpdateSignal } from "@connectors/connectors/zendesk/temporal/signals";

import { zendeskUpdatesSignal } from "./signals";
import { zendeskUpdatesSignal } from "@connectors/connectors/zendesk/temporal/signals";

const {
getZendeskCategoriesActivity,
syncZendeskBrandActivity,
syncZendeskCategoryActivity,
syncZendeskArticlesActivity,
syncZendeskTicketsActivity,
} = proxyActivities<typeof activities>({
startToCloseTimeout: "5 minutes",
});
Expand Down Expand Up @@ -81,7 +78,10 @@ export async function zendeskSyncWorkflow({
break;
}
default:
assertNever(signal.type);
assertNever(
`Unexpected signal type ${signal.type} received within Zendesk sync workflow.`,
signal.type
);
}
});
});
Expand Down Expand Up @@ -182,8 +182,6 @@ export async function zendeskSyncWorkflow({
// run cleanup here if needed

await saveZendeskConnectorSuccessSync({ connectorId });

await sleep(INTERVAL_BETWEEN_SYNCS_MS);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions connectors/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { runIntercomWorker } from "./connectors/intercom/temporal/worker";
import { runNotionWorker } from "./connectors/notion/temporal/worker";
import { runSlackWorker } from "./connectors/slack/temporal/worker";
import { runWebCrawlerWorker } from "./connectors/webcrawler/temporal/worker";
import { runZendeskWorker } from "./connectors/zendesk/temporal/worker";
import { errorFromAny } from "./lib/error";
import logger from "./logger/logger";

Expand Down Expand Up @@ -44,6 +45,9 @@ runGoogleWorkers().catch((err) =>
runIntercomWorker().catch((err) =>
logger.error(errorFromAny(err), "Error running intercom worker")
);
runZendeskWorker().catch((err) =>
logger.error(errorFromAny(err), "Error running zendesk worker")
);
runWebCrawlerWorker().catch((err) =>
logger.error(errorFromAny(err), "Error running webcrawler worker")
);
Expand Down
5 changes: 2 additions & 3 deletions connectors/src/start_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
runNotionWorker,
} from "./connectors/notion/temporal/worker";
import { runSlackWorker } from "./connectors/slack/temporal/worker";
import { runZendeskWorker } from "./connectors/zendesk/temporal/worker";
import { errorFromAny } from "./lib/error";
import logger from "./logger/logger";

Expand All @@ -34,9 +35,7 @@ const workerFunctions: Record<WorkerType, () => Promise<void>> = {
slack: runSlackWorker,
webcrawler: runWebCrawlerWorker,
snowflake: runSnowflakeWorker,
zendesk: async () => {
logger.info("Zendesk worker not implemented yet.");
},
zendesk: runZendeskWorker,
};

const ALL_WORKERS = Object.keys(workerFunctions) as WorkerType[];
Expand Down
6 changes: 5 additions & 1 deletion front/components/ConnectorPermissionsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const PERMISSIONS_EDITABLE_CONNECTOR_TYPES: Set<ConnectorProvider> = new Set([
"microsoft",
"intercom",
"snowflake",
"zendesk",
]);

const CONNECTOR_TYPE_TO_PERMISSIONS: Record<
Expand All @@ -75,7 +76,10 @@ const CONNECTOR_TYPE_TO_PERMISSIONS: Record<
},
notion: undefined,
github: undefined,
zendesk: undefined,
zendesk: {
selected: "read",
unselected: "none",
},
intercom: {
selected: "read",
unselected: "none",
Expand Down
Loading