-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flav/monitor active notion temporal workflows (#3152)
* Check Notion connectors active temporal workflows * ✂️ * Stop using environment variables everywhere * 📚 * Make it run every hour.
- Loading branch information
Showing
7 changed files
with
129 additions
and
35 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
84 changes: 84 additions & 0 deletions
84
front/production_checks/checks/check_notion_active_workflows.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,84 @@ | ||
import { Client, WorkflowHandle } from "@temporalio/client"; | ||
import { QueryTypes } from "sequelize"; | ||
|
||
import { getTemporalClient } from "@app/lib/temporal"; | ||
import { getConnectorReplicaDbConnection } from "@app/production_checks/lib/utils"; | ||
import { CheckFunction } from "@app/production_checks/types/check"; | ||
|
||
interface NotionConnector { | ||
id: number; | ||
dataSourceName: string; | ||
workspaceId: string; | ||
} | ||
|
||
export function getWorkflowId(dataSourceInfo: { | ||
workspaceId: string; | ||
dataSourceName: string; | ||
}) { | ||
return `workflow-notion-${dataSourceInfo.workspaceId}-${dataSourceInfo.dataSourceName}`; | ||
} | ||
|
||
async function listAllNotionConnectors() { | ||
const connectorsReplica = getConnectorReplicaDbConnection(); | ||
|
||
const notionConnectors: NotionConnector[] = await connectorsReplica.query( | ||
`SELECT id, "dataSourceName", "workspaceId" FROM connectors WHERE "type" = 'notion'`, | ||
{ | ||
type: QueryTypes.SELECT, | ||
} | ||
); | ||
|
||
return notionConnectors; | ||
} | ||
|
||
async function isTemporalWorkflowRunning( | ||
client: Client, | ||
notionConnector: NotionConnector | ||
) { | ||
try { | ||
const handle: WorkflowHandle = client.workflow.getHandle( | ||
getWorkflowId(notionConnector) | ||
); | ||
|
||
const description = await handle.describe(); | ||
const { status } = description; | ||
|
||
return status.name === "RUNNING"; | ||
} catch (err) { | ||
return false; | ||
} | ||
} | ||
|
||
export const checkNotionActiveWorkflows: CheckFunction = async ( | ||
checkName, | ||
logger, | ||
reportSuccess, | ||
reportFailure, | ||
heartbeat | ||
) => { | ||
const notionConnectors = await listAllNotionConnectors(); | ||
|
||
const client = await getTemporalClient(); | ||
|
||
const missingActiveWorkflows: any[] = []; | ||
for (const notionConnector of notionConnectors) { | ||
heartbeat(); | ||
|
||
const isActive = isTemporalWorkflowRunning(client, notionConnector); | ||
if (!isActive) { | ||
missingActiveWorkflows.push({ | ||
connectorId: notionConnector.id, | ||
workspaceId: notionConnector.workspaceId, | ||
}); | ||
} | ||
} | ||
|
||
if (missingActiveWorkflows.length > 0) { | ||
reportFailure( | ||
{ missingActiveWorkflows }, | ||
"Missing Notion temporal workflows" | ||
); | ||
} else { | ||
reportSuccess({}); | ||
} | ||
}; |
25 changes: 7 additions & 18 deletions
25
front/production_checks/checks/managed_data_source_gdrive_gc.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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { | ||
CONNECTORS_DATABASE_READ_REPLICA_URI, | ||
FRONT_DATABASE_READ_REPLICA_URI, | ||
} = process.env; | ||
|
||
const config = { | ||
getConnectorsDatabaseReadReplicaUri: () => | ||
CONNECTORS_DATABASE_READ_REPLICA_URI, | ||
getFrontDatabaseReadReplicaUri: () => FRONT_DATABASE_READ_REPLICA_URI, | ||
}; | ||
|
||
export default config; |
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,15 @@ | ||
import { Sequelize } from "sequelize"; | ||
|
||
import config from "@app/production_checks/lib/config"; | ||
|
||
export function getConnectorReplicaDbConnection() { | ||
return new Sequelize(config.getConnectorsDatabaseReadReplicaUri() as string, { | ||
logging: false, | ||
}); | ||
} | ||
|
||
export function getFrontReplicaDbConnection() { | ||
return new Sequelize(config.getConnectorsDatabaseReadReplicaUri() as string, { | ||
logging: false, | ||
}); | ||
} |
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