From 8e836db4855db681f7539733f6b08fb190d899ed Mon Sep 17 00:00:00 2001 From: Tim Sanders Date: Wed, 21 Sep 2022 12:35:01 -0500 Subject: [PATCH] Revert "No grid auto-refresh for backfill dag runs (#25042)" (#26463) * Revert "No grid auto-refresh for backfill dag runs (#25042)" This reverts commit de6938e173773d88bd741e43c7b0aa16d8a1a167. * Fix Grid unit test (cherry picked from commit d0b3d59c958f98d3b9856d661c8479284e70bb39) --- airflow/www/static/js/api/useGridData.test.ts | 64 ++----------------- airflow/www/static/js/api/useGridData.ts | 2 +- 2 files changed, 7 insertions(+), 59 deletions(-) diff --git a/airflow/www/static/js/api/useGridData.test.ts b/airflow/www/static/js/api/useGridData.test.ts index c5a0e6c9de515..43d581f0006d0 100644 --- a/airflow/www/static/js/api/useGridData.test.ts +++ b/airflow/www/static/js/api/useGridData.test.ts @@ -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, @@ -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); diff --git a/airflow/www/static/js/api/useGridData.ts b/airflow/www/static/js/api/useGridData.ts index f9a5737c5dac6..737167552cc77 100644 --- a/airflow/www/static/js/api/useGridData.ts +++ b/airflow/www/static/js/api/useGridData.ts @@ -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();