Skip to content

Commit

Permalink
batch calls to fetch schedule/sensors on the overview page (dagster-i…
Browse files Browse the repository at this point in the history
  • Loading branch information
prha authored Jan 11, 2022
1 parent 7505aa1 commit 73b8c52
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Redirect} from 'react-router-dom';
import {useFeatureFlags} from '../app/Flags';
import {PYTHON_ERROR_FRAGMENT} from '../app/PythonErrorInfo';
import {QueryCountdown} from '../app/QueryCountdown';
import {JOB_METADATA_FRAGMENT, ScheduleOrSensorTag} from '../nav/JobMetadata';
import {ScheduleOrSensorTag} from '../nav/JobMetadata';
import {LegacyPipelineTag} from '../pipelines/LegacyPipelineTag';
import {PipelineReference} from '../pipelines/PipelineReference';
import {RunStatusIndicator} from '../runs/RunStatusDots';
Expand All @@ -38,6 +38,8 @@ import {
import {JobMap, RunTimeline} from '../runs/RunTimeline';
import {RunElapsed, RunTime, RUN_TIME_FRAGMENT} from '../runs/RunUtils';
import {RunTimeFragment} from '../runs/types/RunTimeFragment';
import {SCHEDULE_SWITCH_FRAGMENT} from '../schedules/ScheduleSwitch';
import {SENSOR_SWITCH_FRAGMENT} from '../sensors/SensorSwitch';
import {InstigationStatus, RunStatus} from '../types/globalTypes';
import {REPOSITORY_INFO_FRAGMENT} from '../workspace/RepositoryInformation';
import {useRepositoryOptions} from '../workspace/WorkspaceContext';
Expand All @@ -50,7 +52,11 @@ import {InstanceTabs} from './InstanceTabs';
import {JobMenu} from './JobMenu';
import {NextTick, SCHEDULE_FUTURE_TICKS_FRAGMENT} from './NextTick';
import {StepSummaryForRun} from './StepSummaryForRun';
import {InstanceOverviewInitialQuery} from './types/InstanceOverviewInitialQuery';
import {
InstanceOverviewInitialQuery,
InstanceOverviewInitialQuery_workspaceOrError_Workspace_locationEntries_locationOrLoadError_RepositoryLocation_repositories_schedules as Schedule,
InstanceOverviewInitialQuery_workspaceOrError_Workspace_locationEntries_locationOrLoadError_RepositoryLocation_repositories_sensors as Sensor,
} from './types/InstanceOverviewInitialQuery';
import {LastTenRunsPerJobQuery} from './types/LastTenRunsPerJobQuery';
import {OverviewJobFragment} from './types/OverviewJobFragment';

Expand Down Expand Up @@ -84,6 +90,8 @@ const makeJobKey = (repoAddress: RepoAddress, jobName: string) => {
type JobItem = {
job: OverviewJobFragment;
repoAddress: RepoAddress;
schedules: Schedule[];
sensors: Sensor[];
};

type JobItemWithRuns = JobItem & {
Expand Down Expand Up @@ -185,16 +193,24 @@ const OverviewContent = () => {
) {
for (const repository of locationEntry.locationOrLoadError.repositories) {
for (const pipeline of repository.pipelines) {
const {runs, schedules} = pipeline;
const {runs} = pipeline;
const schedules: Schedule[] = (repository.schedules || []).filter(
(schedule) => schedule.pipelineName === pipeline.name,
);
const sensors: Sensor[] = (repository.sensors || []).filter((sensor) =>
sensor.targets?.map((t) => t.pipelineName).includes(pipeline.name),
);
const repoAddress = buildRepoAddress(
repository.name,
locationEntry.locationOrLoadError.name,
);

if (runs.length) {
const {status} = runs[0];
const item = {
const item: JobItem = {
job: pipeline,
schedules,
sensors,
repoAddress,
};
if (failedStatuses.has(status)) {
Expand All @@ -220,6 +236,8 @@ const OverviewContent = () => {
scheduled.push({
job: pipeline,
repoAddress,
schedules,
sensors,
});
}
}
Expand Down Expand Up @@ -338,7 +356,7 @@ const OverviewContent = () => {
}, {} as JobMap);

for (const jobItem of scheduled) {
const {job, repoAddress} = jobItem;
const {job, repoAddress, schedules} = jobItem;
const jobKey = makeJobKey(repoAddress, job.name);

// If there are no runs tracked for this job yet because they're only scheduled,
Expand All @@ -357,7 +375,6 @@ const OverviewContent = () => {
}

const {runs} = jobMap[jobKey];
const {schedules} = job;
for (const schedule of schedules) {
if (schedule.scheduleState.status === InstigationStatus.RUNNING) {
schedule.futureTicks.results.forEach(({timestamp}) => {
Expand Down Expand Up @@ -574,7 +591,7 @@ const JobSection = (props: JobSectionProps) => {
</tr>
</thead>
<tbody>
{jobs.map(({job, repoAddress, runs}) => {
{jobs.map(({job, repoAddress, runs, schedules, sensors}) => {
const jobKey = makeJobKey(repoAddress, job.name);
return (
<tr key={jobKey}>
Expand Down Expand Up @@ -607,10 +624,14 @@ const JobSection = (props: JobSectionProps) => {
</Box>
</td>
<td>
{job.schedules.length || job.sensors.length ? (
{schedules.length || sensors.length ? (
<Box flex={{direction: 'column', alignItems: 'flex-start', gap: 8}}>
<ScheduleOrSensorTag job={job} repoAddress={repoAddress} />
{job.schedules.length ? <NextTick schedules={job.schedules} /> : null}
<ScheduleOrSensorTag
schedules={schedules}
sensors={sensors}
repoAddress={repoAddress}
/>
{schedules.length ? <NextTick schedules={schedules} /> : null}
</Box>
) : (
<div style={{color: ColorsWIP.Gray500}}>None</div>
Expand Down Expand Up @@ -666,32 +687,12 @@ const OVERVIEW_JOB_FRAGMENT = gql`
status
...RunTimeFragment
}
...JobMetadataFragment
modes {
id
name
}
schedules {
id
name
scheduleState {
id
status
}
...ScheduleFutureTicksFragment
}
sensors {
id
name
sensorState {
id
status
}
}
}
${SCHEDULE_FUTURE_TICKS_FRAGMENT}
${JOB_METADATA_FRAGMENT}
${RUN_TIME_FRAGMENT}
`;

Expand Down Expand Up @@ -719,6 +720,29 @@ const INSTANCE_OVERVIEW_INITIAL_QUERY = gql`
...OverviewJobFragment
}
...RepositoryInfoFragment
schedules {
id
name
pipelineName
scheduleState {
id
status
}
...ScheduleFutureTicksFragment
...ScheduleSwitchFragment
}
sensors {
id
name
targets {
pipelineName
}
sensorState {
id
status
}
...SensorSwitchFragment
}
}
}
... on PythonError {
Expand All @@ -733,6 +757,9 @@ const INSTANCE_OVERVIEW_INITIAL_QUERY = gql`
${OVERVIEW_JOB_FRAGMENT}
${REPOSITORY_INFO_FRAGMENT}
${SCHEDULE_FUTURE_TICKS_FRAGMENT}
${SCHEDULE_SWITCH_FRAGMENT}
${SENSOR_SWITCH_FRAGMENT}
${PYTHON_ERROR_FRAGMENT}
`;

Expand Down

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

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

Loading

0 comments on commit 73b8c52

Please sign in to comment.