Skip to content

Commit

Permalink
fix broken auto-refresh (apache#25950)
Browse files Browse the repository at this point in the history
In PR apache#25042 the merged change included a bug that prevents the page
from auto-refreshing if there are anything other than manual runs on the
page. We also want to auto-refresh for scheduled runs.

I've also added more complete unit tests for the expected behaviour.

(cherry picked from commit 37ec752)
  • Loading branch information
cloventt authored and ephraimbuddy committed Aug 25, 2022
1 parent 7283823 commit b947e86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions airflow/www/static/js/grid/api/useGridData.test.js
Expand Up @@ -60,6 +60,24 @@ describe('Test areActiveRuns()', () => {
expect(result).toBe(false);
});

[
{ runType: 'manual', state: 'queued', result: true },
{ runType: 'manual', state: 'running', result: true },
{ runType: 'scheduled', state: 'queued', result: true },
{ runType: 'scheduled', state: 'running', result: true },
{ runType: 'backfill', state: 'queued', result: false },
{ runType: 'backfill', state: 'running', result: false },
].forEach((conf) => {
test(`Returns ${conf.result} when filtering runs with runtype ["${conf.runType}"] and state ["${conf.state}"]`, () => {
const runConf = { ...conf };
delete runConf.result;
const runs = [runConf];

const result = areActiveRuns(runs);
expect(result).toBe(conf.result);
});
});

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/grid/api/useGridData.ts
Expand Up @@ -49,7 +49,7 @@ const emptyGridData: GridData = {
},
};

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

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

0 comments on commit b947e86

Please sign in to comment.