Skip to content

Commit

Permalink
Add latestRun resolver to AssetsLatestInfo (#8072)
Browse files Browse the repository at this point in the history
  • Loading branch information
clairelin135 committed May 31, 2022
1 parent f921f04 commit 8551940
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 321 deletions.
45 changes: 6 additions & 39 deletions js_modules/dagit/packages/core/src/asset-graph/Utils.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import {gql} from '@apollo/client';
import {pathVerticalDiagonal} from '@vx/shape';
import uniq from 'lodash/uniq';

import {AssetNodeDefinitionFragment} from '../assets/types/AssetNodeDefinitionFragment';

import {
AssetGraphLiveQuery_assetsLatestInfo,
AssetGraphLiveQuery_assetsLatestInfo_latestRun,
AssetGraphLiveQuery_assetNodes_assetMaterializations,
} from './types/AssetGraphLiveQuery';
import {
AssetGraphQuery_assetNodes,
AssetGraphQuery_assetNodes_assetKey,
} from './types/AssetGraphQuery';
import {AssetNodeLiveFragment} from './types/AssetNodeLiveFragment';
import {
RepositoryLiveFragment,
RepositoryLiveFragment_latestRunByStep_run,
} from './types/RepositoryLiveFragment';
type AssetNode = AssetGraphQuery_assetNodes;
type AssetKey = AssetGraphQuery_assetNodes_assetKey;

Expand Down Expand Up @@ -219,7 +215,7 @@ export interface LiveDataForNode {
computeStatus: Status;
unstartedRunIds: string[]; // run in progress and step not started
inProgressRunIds: string[]; // run in progress and step in progress
runWhichFailedToMaterialize: RepositoryLiveFragment_latestRunByStep_run | null;
runWhichFailedToMaterialize: AssetGraphLiveQuery_assetsLatestInfo_latestRun | null;
lastMaterialization: AssetGraphLiveQuery_assetNodes_assetMaterializations | null;
lastChanged: number;
}
Expand All @@ -230,7 +226,6 @@ export interface LiveData {
export const buildLiveData = (
graph: GraphData,
nodes: AssetNodeLiveFragment[],
repos: RepositoryLiveFragment[],
assetsLatestInfo: AssetGraphLiveQuery_assetsLatestInfo[],
) => {
const data: LiveData = {};
Expand All @@ -245,19 +240,17 @@ export const buildLiveData = (
const lastMaterialization = liveNode.assetMaterializations[0] || null;
const lastChanged = Number(lastMaterialization?.timestamp || 0) / 1000;
const isPartitioned = graphNode.definition.partitionDefinition;
const repo = repos.find((r) => r.id === liveNode.repository.id);

const assetLiveRuns = assetsLatestInfo.find(
(r) => JSON.stringify(r.assetKey) === JSON.stringify(liveNode.assetKey),
);
const info = repo?.latestRunByStep.find((r) => liveNode.opNames.includes(r.stepKey));

const latestRunForStepKey = info?.__typename === 'LatestRun' ? info.run : null;
const latestRunForAsset = assetLiveRuns?.latestRun ? assetLiveRuns.latestRun : null;

const runWhichFailedToMaterialize =
(latestRunForStepKey?.status === 'FAILURE' &&
(!lastMaterialization || lastMaterialization.runId !== latestRunForStepKey?.id) &&
latestRunForStepKey) ||
(latestRunForAsset?.status === 'FAILURE' &&
(!lastMaterialization || lastMaterialization.runId !== latestRunForAsset?.id) &&
latestRunForAsset) ||
null;

data[graphId] = {
Expand Down Expand Up @@ -315,29 +308,3 @@ export function tokenForAssetKey(key: {path: string[]}) {
export function displayNameForAssetKey(key: {path: string[]}) {
return key.path.join(' / ');
}

export const LAST_RUNS_WARNINGS_FRAGMENT = gql`
fragment LastRunsWarningsFragment on LatestRun {
stepKey
run {
id
status
}
}
`;

export const REPOSITORY_LIVE_FRAGMENT = gql`
fragment RepositoryLiveFragment on Repository {
id
name
location {
id
name
}
latestRunByStep {
__typename
...LastRunsWarningsFragment
}
}
${LAST_RUNS_WARNINGS_FRAGMENT}
`;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import {AssetKeyInput, PipelineSelector} from '../types/globalTypes';

import {ASSET_NODE_LIVE_FRAGMENT} from './AssetNode';
import {buildLiveData, GraphData, REPOSITORY_LIVE_FRAGMENT} from './Utils';
import {buildLiveData, GraphData} from './Utils';
import {AssetGraphLiveQuery, AssetGraphLiveQueryVariables} from './types/AssetGraphLiveQuery';

/** Fetches the last materialization, "upstream changed", and other live state
Expand All @@ -24,12 +24,6 @@ export function useLiveDataForAssetKeys(
skip: graphAssetKeys.length === 0,
variables: {
assetKeys: graphAssetKeys,
repositorySelector: pipelineSelector
? {
repositoryLocationName: pipelineSelector.repositoryLocationName,
repositoryName: pipelineSelector.repositoryName,
}
: undefined,
},
notifyOnNetworkStatusChange: true,
},
Expand All @@ -40,11 +34,9 @@ export function useLiveDataForAssetKeys(
return {};
}

const {repositoriesOrError, assetNodes: liveAssetNodes, assetsLatestInfo} = liveResult.data;
const repos =
repositoriesOrError.__typename === 'RepositoryConnection' ? repositoriesOrError.nodes : [];
const {assetNodes: liveAssetNodes, assetsLatestInfo} = liveResult.data;

return buildLiveData(graphData, liveAssetNodes, repos, assetsLatestInfo);
return buildLiveData(graphData, liveAssetNodes, assetsLatestInfo);
}, [graphData, liveResult]);

return {
Expand All @@ -55,17 +47,7 @@ export function useLiveDataForAssetKeys(
}

const ASSETS_GRAPH_LIVE_QUERY = gql`
query AssetGraphLiveQuery($repositorySelector: RepositorySelector, $assetKeys: [AssetKeyInput!]) {
repositoriesOrError(repositorySelector: $repositorySelector) {
__typename
... on RepositoryConnection {
nodes {
__typename
id
...RepositoryLiveFragment
}
}
}
query AssetGraphLiveQuery($assetKeys: [AssetKeyInput!]) {
assetNodes(assetKeys: $assetKeys, loadMaterializations: true) {
id
...AssetNodeLiveFragment
Expand All @@ -76,8 +58,11 @@ const ASSETS_GRAPH_LIVE_QUERY = gql`
}
unstartedRunIds
inProgressRunIds
latestRun {
status
id
}
}
}
${REPOSITORY_LIVE_FRAGMENT}
${ASSET_NODE_LIVE_FRAGMENT}
`;
31 changes: 6 additions & 25 deletions js_modules/dagit/packages/core/src/assets/AssetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {Timestamp} from '../app/time/Timestamp';
import {
buildGraphDataFromSingleNode,
buildLiveData,
REPOSITORY_LIVE_FRAGMENT,
LiveData,
displayNameForAssetKey,
toGraphId,
Expand Down Expand Up @@ -83,10 +82,6 @@ export const AssetView: React.FC<Props> = ({assetKey}) => {
>(ASSET_NODE_DEFINITION_LIVE_QUERY, {
skip: !repoAddress,
variables: {
repositorySelector: {
repositoryLocationName: repoAddress ? repoAddress.location : '',
repositoryName: repoAddress ? repoAddress.name : '',
},
assetKeys: [assetKey],
},
notifyOnNetworkStatusChange: true,
Expand All @@ -103,14 +98,9 @@ export const AssetView: React.FC<Props> = ({assetKey}) => {

let liveDataByNode: LiveData = {};

const repo =
liveQueryResult.data?.repositoryOrError.__typename === 'Repository'
? liveQueryResult.data.repositoryOrError
: null;

const assetsLatestInfo = liveQueryResult.data ? liveQueryResult.data.assetsLatestInfo : null;

if (definition && repo && assetsLatestInfo) {
if (definition && assetsLatestInfo) {
const nodesWithLatestMaterialization = [
definition,
...definition.dependencies.map((d) => d.asset),
Expand All @@ -119,7 +109,6 @@ export const AssetView: React.FC<Props> = ({assetKey}) => {
liveDataByNode = buildLiveData(
buildGraphDataFromSingleNode(definition),
nodesWithLatestMaterialization,
[repo],
assetsLatestInfo,
);
}
Expand Down Expand Up @@ -263,27 +252,19 @@ const ASSET_QUERY = gql`
`;

const ASSET_NODE_DEFINITION_LIVE_QUERY = gql`
query AssetNodeDefinitionLiveQuery(
$repositorySelector: RepositorySelector!
$assetKeys: [AssetKeyInput!]
) {
repositoryOrError(repositorySelector: $repositorySelector) {
__typename
... on Repository {
id
name
...RepositoryLiveFragment
}
}
query AssetNodeDefinitionLiveQuery($assetKeys: [AssetKeyInput!]) {
assetsLatestInfo(assetKeys: $assetKeys) {
assetKey {
path
}
unstartedRunIds
inProgressRunIds
latestRun {
status
id
}
}
}
${REPOSITORY_LIVE_FRAGMENT}
`;

const HistoricalViewAlert: React.FC<{
Expand Down

0 comments on commit 8551940

Please sign in to comment.