(
blocks: DeepnoteBlock[],
options: {
// If true, the function will not throw an error and return partial DAG
// this may happen when there is an error in one of the processed blocks.
// Partial DAG should be used only in the DAG chart.
acceptPartialDAG: boolean
pythonInterpreter?: string
} = { acceptPartialDAG: false }
)
| 34 | } |
| 35 | |
| 36 | export async function getDagForBlocks( |
| 37 | blocks: DeepnoteBlock[], |
| 38 | options: { |
| 39 | // If true, the function will not throw an error and return partial DAG |
| 40 | // this may happen when there is an error in one of the processed blocks. |
| 41 | // Partial DAG should be used only in the DAG chart. |
| 42 | acceptPartialDAG: boolean |
| 43 | pythonInterpreter?: string |
| 44 | } = { acceptPartialDAG: false } |
| 45 | ) { |
| 46 | try { |
| 47 | const blocksWithContentDeps = await getBlockDependencies(blocks, { |
| 48 | pythonInterpreter: options.pythonInterpreter, |
| 49 | }) |
| 50 | |
| 51 | const blocksWithErrorInContentDeps = blocksWithContentDeps.filter(block => block.error) |
| 52 | const blocksWithoutErrorsInContentDeps = blocksWithContentDeps.filter(block => !block.error) |
| 53 | |
| 54 | if (blocksWithErrorInContentDeps.length > 0 && !options.acceptPartialDAG) { |
| 55 | const firstErrorBlock = blocksWithErrorInContentDeps[0] |
| 56 | if (firstErrorBlock?.error?.type === 'SyntaxError') { |
| 57 | throw new SyntaxError(firstErrorBlock.error.message) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | const allBlocksForDAG = options.acceptPartialDAG ? blocksWithContentDeps : blocksWithoutErrorsInContentDeps |
| 62 | const dag = buildDagFromBlocks(allBlocksForDAG) |
| 63 | return { dag, blocksWithErrorInContentDeps, newlyComputedBlocksContentDeps: blocksWithContentDeps } |
| 64 | } catch (error) { |
| 65 | if (error instanceof SyntaxError) { |
| 66 | throw error |
| 67 | } |
| 68 | |
| 69 | throw new DagError(error instanceof Error ? error.message : String(error)) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Takes blocks, creates DAG and returns blocks that should be executed based in blocksToExecute for downstream execution. |
no test coverage detected