-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Poke Plugin to set connector error and pause. (#10025)
* Add Poke Plugin to set connector error and pause. * 👕
- Loading branch information
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./garbage_collect_google_drive_document"; | ||
export * from "./mark_connector_as_error"; | ||
export * from "./operations"; |
78 changes: 78 additions & 0 deletions
78
front/lib/api/poke/plugins/data_sources/mark_connector_as_error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { AdminCommandType } from "@dust-tt/types"; | ||
import { CONNECTORS_ERROR_TYPES, ConnectorsAPI, Err, Ok } from "@dust-tt/types"; | ||
|
||
import config from "@app/lib/api/config"; | ||
import { createPlugin } from "@app/lib/api/poke/types"; | ||
import { isManaged, isWebsite } from "@app/lib/data_sources"; | ||
import { DataSourceResource } from "@app/lib/resources/data_source_resource"; | ||
import logger from "@app/logger/logger"; | ||
|
||
export const markConnectorAsErrorPlugin = createPlugin( | ||
{ | ||
id: "mark-connector-as-error", | ||
name: "Mark connector as error", | ||
description: "Mark a connector as errored with a specific error type", | ||
resourceTypes: ["data_sources"], | ||
args: { | ||
errorType: { | ||
type: "enum", | ||
label: "Error Type", | ||
description: "Select error type to set", | ||
values: CONNECTORS_ERROR_TYPES, | ||
}, | ||
}, | ||
}, | ||
async (auth, dataSourceId, args) => { | ||
if (!dataSourceId) { | ||
return new Err(new Error("Data source not found.")); | ||
} | ||
|
||
const dataSource = await DataSourceResource.fetchById(auth, dataSourceId); | ||
if (!dataSource) { | ||
return new Err(new Error("Data source not found.")); | ||
} | ||
|
||
if (!isManaged(dataSource) && !isWebsite(dataSource)) { | ||
return new Err(new Error("Data source is not managed or website.")); | ||
} | ||
|
||
const { connectorId } = dataSource; | ||
if (!connectorId) { | ||
return new Err(new Error("No connector on datasource.")); | ||
} | ||
|
||
const { errorType } = args; | ||
const connectorsAPI = new ConnectorsAPI( | ||
config.getConnectorsAPIConfig(), | ||
logger | ||
); | ||
|
||
// First set the error. | ||
const setErrorCommand: AdminCommandType = { | ||
majorCommand: "connectors", | ||
command: "set-error", | ||
args: { | ||
connectorId: connectorId.toString(), | ||
error: errorType, | ||
wId: auth.getNonNullableWorkspace().sId, | ||
dsId: dataSource.sId, | ||
}, | ||
}; | ||
|
||
const setErrorRes = await connectorsAPI.admin(setErrorCommand); | ||
if (setErrorRes.isErr()) { | ||
return new Err(new Error(setErrorRes.error.message)); | ||
} | ||
|
||
// Then pause it. | ||
const pauseRes = await connectorsAPI.pauseConnector(connectorId.toString()); | ||
if (pauseRes.isErr()) { | ||
return new Err(new Error(pauseRes.error.message)); | ||
} | ||
|
||
return new Ok({ | ||
display: "text", | ||
value: `Connector ${connectorId} marked as ${errorType} and paused.`, | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters