Skip to content

Commit

Permalink
Revert "No grid auto-refresh for backfill dag runs (#25042)" (#26463)
Browse files Browse the repository at this point in the history
* Revert "No grid auto-refresh for backfill dag runs (#25042)"

This reverts commit de6938e.

* Fix Grid unit test

(cherry picked from commit d0b3d59)
  • Loading branch information
Gollum999 authored and ephraimbuddy committed Oct 18, 2022
1 parent c652493 commit 8e836db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 59 deletions.
64 changes: 6 additions & 58 deletions airflow/www/static/js/api/useGridData.test.ts
Expand Up @@ -27,6 +27,7 @@ const commonDagRunParams = {
executionDate: '2022-01-01T10:00+00:00',
dataIntervalStart: '2022-01-01T05:00+00:00',
dataIntervalEnd: '2022-01-01T10:00+00:00',
runType: 'scheduled' as DagRun['runType'],
startDate: null,
endDate: null,
lastSchedulingDecision: null,
Expand All @@ -35,75 +36,22 @@ const commonDagRunParams = {
describe('Test areActiveRuns()', () => {
test('Correctly detects active runs', () => {
const runs: DagRun[] = [
{ runType: 'scheduled', state: 'success', ...commonDagRunParams },
{ runType: 'manual', state: 'queued', ...commonDagRunParams },
{ state: 'success', ...commonDagRunParams },
{ state: 'queued', ...commonDagRunParams },
];
expect(areActiveRuns(runs)).toBe(true);
});

test('Returns false when all runs are resolved', () => {
const runs: DagRun[] = [
{ runType: 'scheduled', state: 'success', ...commonDagRunParams },
{ runType: 'manual', state: 'failed', ...commonDagRunParams },
{ runType: 'manual', state: 'failed', ...commonDagRunParams },
{ state: 'success', ...commonDagRunParams },
{ state: 'failed', ...commonDagRunParams },
{ state: 'failed', ...commonDagRunParams },
];
const result = areActiveRuns(runs);
expect(result).toBe(false);
});

test('Returns false when filtering runs runtype ["backfill"]', () => {
const runs: DagRun[] = [
{ runType: 'scheduled', state: 'success', ...commonDagRunParams },
{ runType: 'manual', state: 'failed', ...commonDagRunParams },
{ runType: 'backfill', state: 'failed', ...commonDagRunParams },
];
const result = areActiveRuns(runs);
expect(result).toBe(false);
});

test('Returns false when filtering runs runtype ["backfill"] and state ["queued"]', () => {
const runs: DagRun[] = [
{ runType: 'scheduled', state: 'success', ...commonDagRunParams },
{ runType: 'manual', state: 'failed', ...commonDagRunParams },
{ runType: 'backfill', state: 'queued', ...commonDagRunParams },
];
const result = areActiveRuns(runs);
expect(result).toBe(false);
});

[
{
runType: 'manual', state: 'queued', expectedResult: true,
},
{
runType: 'manual', state: 'running', expectedResult: true,
},
{
runType: 'scheduled', state: 'queued', expectedResult: true,
},
{
runType: 'scheduled', state: 'running', expectedResult: true,
},
{
runType: 'dataset_triggered', state: 'queued', expectedResult: true,
},
{
runType: 'dataset_triggered', state: 'running', expectedResult: true,
},
{
runType: 'backfill', state: 'queued', expectedResult: false,
},
{
runType: 'backfill', state: 'running', expectedResult: false,
},
].forEach(({ state, runType, expectedResult }) => {
test(`Returns ${expectedResult} when filtering runs with runtype ["${runType}"] and state ["${state}"]`, () => {
const runs: DagRun[] = [{ runType, state, ...commonDagRunParams } as DagRun];
const result = areActiveRuns(runs);
expect(result).toBe(expectedResult);
});
});

test('Returns false when there are no runs', () => {
const result = areActiveRuns();
expect(result).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/static/js/api/useGridData.ts
Expand Up @@ -57,7 +57,7 @@ const formatOrdering = (data: GridData) => ({
ordering: data.ordering.map((o: string) => camelCase(o)) as RunOrdering,
});

export const areActiveRuns = (runs: DagRun[] = []) => runs.filter((run) => ['manual', 'scheduled', 'dataset_triggered'].includes(run.runType)).filter((run) => ['queued', 'running'].includes(run.state)).length > 0;
export const areActiveRuns = (runs: DagRun[] = []) => runs.filter((run) => ['queued', 'running'].includes(run.state)).length > 0;

const useGridData = () => {
const { isRefreshOn, stopRefresh } = useAutoRefresh();
Expand Down

0 comments on commit 8e836db

Please sign in to comment.