(
blocks: DeepnoteBlock[],
blocksToExecute: DeepnoteBlock[],
options: { pythonInterpreter?: string } = {}
)
| 114 | * @param options Options for DAG generation |
| 115 | */ |
| 116 | export async function getUpstreamBlocks( |
| 117 | blocks: DeepnoteBlock[], |
| 118 | blocksToExecute: DeepnoteBlock[], |
| 119 | options: { pythonInterpreter?: string } = {} |
| 120 | ): Promise<GetUpstreamBlocksResult> { |
| 121 | try { |
| 122 | const { dag, blocksWithErrorInContentDeps, newlyComputedBlocksContentDeps } = await getDagForBlocks(blocks, { |
| 123 | acceptPartialDAG: true, |
| 124 | pythonInterpreter: options.pythonInterpreter, |
| 125 | }) |
| 126 | const upstreamBlocks = getUpstreamBlocksForBlocksIds( |
| 127 | dag, |
| 128 | blocksToExecute.map(cell => cell.id) |
| 129 | ) |
| 130 | // Merge the blocks we want to execute with the blocks they depend on. |
| 131 | const blocksToExecuteWithDeps = blocks.filter( |
| 132 | block => blocksToExecute.find(b => b.id === block.id) || upstreamBlocks.includes(block.id) |
| 133 | ) |
| 134 | |
| 135 | const status = blocksWithErrorInContentDeps.length === 0 ? 'success' : 'missing-deps' |
| 136 | |
| 137 | return { status, blocksToExecuteWithDeps, newlyComputedBlocksContentDeps } |
| 138 | } catch (error) { |
| 139 | if (error instanceof DagError || error instanceof SyntaxError) { |
| 140 | return { status: 'fatal', error } |
| 141 | } |
| 142 | |
| 143 | return { status: 'fatal', error: new DagError(error instanceof Error ? error.message : String(error)) } |
| 144 | } |
| 145 | } |
no test coverage detected