-
Notifications
You must be signed in to change notification settings - Fork 108
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] Launch workflows from ZendeskConnectorManager #8346
Changes from 7 commits
bd639b1
b3294f4
a0d7c88
893373b
99f86bd
16c74ac
3cadb70
406bf63
61107d6
e24778a
94d042f
69fa4e0
ac9f73d
aee585c
a897686
ca0e439
12c7af6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,7 @@ import type { | |
ContentNodesViewType, | ||
Result, | ||
} from "@dust-tt/types"; | ||
import { assertNever } from "@dust-tt/types"; | ||
import { Err } from "@dust-tt/types"; | ||
import { Ok } from "@dust-tt/types"; | ||
import { assertNever, Err, Ok } from "@dust-tt/types"; | ||
|
||
import type { ConnectorManagerError } from "@connectors/connectors/interface"; | ||
import { BaseConnectorManager } from "@connectors/connectors/interface"; | ||
|
@@ -37,13 +35,18 @@ import { | |
revokeSyncZendeskTickets, | ||
} from "@connectors/connectors/zendesk/lib/ticket_permissions"; | ||
import { getZendeskAccessToken } from "@connectors/connectors/zendesk/lib/zendesk_access_token"; | ||
import { | ||
launchZendeskSyncWorkflow, | ||
stopZendeskSyncWorkflow, | ||
} from "@connectors/connectors/zendesk/temporal/client"; | ||
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config"; | ||
import logger from "@connectors/logger/logger"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
import { ZendeskConfigurationResource } from "@connectors/resources/zendesk_resources"; | ||
import { | ||
ZendeskArticleResource, | ||
ZendeskBrandResource, | ||
ZendeskCategoryResource, | ||
ZendeskConfigurationResource, | ||
ZendeskTicketResource, | ||
} from "@connectors/resources/zendesk_resources"; | ||
import type { DataSourceConfig } from "@connectors/types/data_source_config"; | ||
|
@@ -69,6 +72,22 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> { | |
{ subdomain: "d3v-dust", conversationsSlidingWindow: 90 } | ||
); | ||
|
||
const workflowStartResult = await launchZendeskSyncWorkflow({ | ||
connectorId: connector.id, | ||
}); | ||
|
||
if (workflowStartResult.isErr()) { | ||
await connector.delete(); | ||
logger.error( | ||
{ | ||
workspaceId: dataSourceConfig.workspaceId, | ||
error: workflowStartResult.error, | ||
}, | ||
"[Zendesk] Error launching the sync workflow." | ||
); | ||
throw workflowStartResult.error; | ||
} | ||
|
||
return new Ok(connector.id.toString()); | ||
} | ||
|
||
|
@@ -86,15 +105,52 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> { | |
} | ||
|
||
async stop(): Promise<Result<undefined, Error>> { | ||
throw new Error("Method not implemented."); | ||
const result = await stopZendeskSyncWorkflow(this.connectorId); | ||
return result.isErr() ? result : new Ok(undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not directly returning result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. types do not match here, but this is an error in stopZendeskSyncWorkflow, will fix it and return result here, thanks for spotting |
||
} | ||
|
||
async resume(): Promise<Result<undefined, Error>> { | ||
throw new Error("Method not implemented."); | ||
const connectorId = this.connectorId; | ||
aubin-tchoi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const connector = await ConnectorResource.fetchById(connectorId); | ||
if (!connector) { | ||
logger.error({ connectorId }, "[Zendesk] Connector not found."); | ||
return new Err(new Error("Connector not found")); | ||
} | ||
|
||
const dataSourceConfig = dataSourceConfigFromConnector(connector); | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the try/catch if we have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my bad, changed that in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. goal here is indeed to always use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
await launchZendeskSyncWorkflow({ connectorId }); | ||
} catch (e) { | ||
logger.error( | ||
{ | ||
workspaceId: dataSourceConfig.workspaceId, | ||
dataSourceId: dataSourceConfig.dataSourceId, | ||
error: e, | ||
}, | ||
"[Zendesk] Error resuming the sync workflow." | ||
); | ||
} | ||
return new Ok(undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems weird to not return the error in this case 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, i'll change that |
||
} | ||
|
||
async sync(): Promise<Result<string, Error>> { | ||
throw new Error("Method not implemented."); | ||
const connectorId = this.connectorId; | ||
const connector = await ConnectorResource.fetchById(connectorId); | ||
if (!connector) { | ||
logger.error({ connectorId }, "[Zendesk] Connector not found."); | ||
return new Err(new Error("Connector not found")); | ||
} | ||
|
||
const brandIds = await ZendeskBrandResource.fetchAllBrandIds({ | ||
connectorId, | ||
}); | ||
const result = await launchZendeskSyncWorkflow({ | ||
connectorId, | ||
brandIds, | ||
forceResync: true, | ||
}); | ||
|
||
return result.isErr() ? result : new Ok(connector.id.toString()); | ||
} | ||
|
||
async retrievePermissions({ | ||
|
@@ -146,9 +202,8 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> { | |
} | ||
|
||
const connectionId = connector.connectionId; | ||
const zendeskConfiguration = await ZendeskConfigurationResource.fetchById( | ||
this.connectorId | ||
); | ||
const zendeskConfiguration = | ||
await ZendeskConfigurationResource.fetchByConnectorId(connectorId); | ||
if (!zendeskConfiguration) { | ||
logger.error( | ||
{ connectorId }, | ||
|
@@ -276,7 +331,23 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> { | |
} | ||
} | ||
|
||
/// Launch a sync workflow here | ||
if ( | ||
toBeSignaledBrandIds.size > 0 || | ||
toBeSignaledTicketsIds.size > 0 || | ||
toBeSignaledHelpCenterIds.size > 0 || | ||
toBeSignaledCategoryIds.size > 0 | ||
) { | ||
const sendSignalToWorkflowResult = await launchZendeskSyncWorkflow({ | ||
connectorId, | ||
brandIds: [...toBeSignaledBrandIds], | ||
ticketsBrandIds: [...toBeSignaledTicketsIds], | ||
helpCenterBrandIds: [...toBeSignaledHelpCenterIds], | ||
categoryIds: [...toBeSignaledCategoryIds], | ||
}); | ||
if (sendSignalToWorkflowResult.isErr()) { | ||
return new Err(sendSignalToWorkflowResult.error); | ||
} | ||
} | ||
|
||
return new Ok(undefined); | ||
} | ||
|
@@ -469,11 +540,33 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> { | |
} | ||
|
||
async pause(): Promise<Result<undefined, Error>> { | ||
throw new Error("Method not implemented."); | ||
const connectorId = this.connectorId; | ||
const connector = await ConnectorResource.fetchById(connectorId); | ||
if (!connector) { | ||
logger.error({ connectorId }, "[Zendesk] Connector not found."); | ||
return new Err(new Error("Connector not found")); | ||
} | ||
await connector.markAsPaused(); | ||
const result = await this.stop(); | ||
|
||
return result.isErr() ? result : new Ok(undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here? Can we simply return result? |
||
} | ||
|
||
async unpause(): Promise<Result<undefined, Error>> { | ||
throw new Error("Method not implemented."); | ||
const connectorId = this.connectorId; | ||
const connector = await ConnectorResource.fetchById(connectorId); | ||
if (!connector) { | ||
logger.error({ connectorId }, "[Zendesk] Connector not found."); | ||
return new Err(new Error("Connector not found")); | ||
} | ||
await connector.markAsUnpaused(); | ||
|
||
const brandIds = await ZendeskBrandResource.fetchAllBrandIds({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we only resume with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the brands are the top level collections, syncing them syncs everything |
||
connectorId, | ||
}); | ||
const result = await launchZendeskSyncWorkflow({ connectorId, brandIds }); | ||
|
||
return result.isErr() ? result : new Ok(undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here types don't match since we pass the workflow ID in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flvndvd done |
||
} | ||
|
||
async garbageCollect(): Promise<Result<string, Error>> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
but we usually prefer to pass proper type, here you can passConnector
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do!