This is an automated email from the ASF dual-hosted git repository.

bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 1950c18  Pause autorefresh if scheduler isn't running (#22151)
1950c18 is described below

commit 1950c1874515097fbcc4f5b5ef74120c8b731574
Author: Brent Bovenzi <[email protected]>
AuthorDate: Mon Mar 14 18:29:11 2022 -0400

    Pause autorefresh if scheduler isn't running (#22151)
    
    * pause autorefresh if scheduler isn't running
    
    * fix test
    
    * update jinja if statement
---
 airflow/www/static/js/graph.js                  |  3 ++-
 airflow/www/static/js/tree/useTreeData.js       | 10 +++++++++-
 airflow/www/static/js/tree/useTreeData.test.jsx | 15 ++++++++++-----
 airflow/www/templates/airflow/main.html         |  7 +++++++
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/airflow/www/static/js/graph.js b/airflow/www/static/js/graph.js
index 3cb0fbe..1ba99a8 100644
--- a/airflow/www/static/js/graph.js
+++ b/airflow/www/static/js/graph.js
@@ -35,6 +35,7 @@ const executionDate = getMetaValue('execution_date');
 const dagRunId = getMetaValue('dag_run_id');
 const arrange = getMetaValue('arrange');
 const taskInstancesUrl = getMetaValue('task_instances_url');
+const isSchedulerRunning = getMetaValue('is_scheduler_running');
 
 // This maps the actual taskId to the current graph node id that contains the 
task
 // (because tasks may be grouped into a group node)
@@ -450,7 +451,7 @@ $('#auto_refresh').change(() => {
 function initRefresh() {
   const isDisabled = localStorage.getItem('disableAutoRefresh');
   const isFinal = checkRunState();
-  $('#auto_refresh').prop('checked', !(isDisabled || isFinal));
+  $('#auto_refresh').prop('checked', !(isDisabled || isFinal) && 
isSchedulerRunning === 'True');
   startOrStopRefresh();
   d3.select('#refresh_button').on('click', () => handleRefresh());
 }
diff --git a/airflow/www/static/js/tree/useTreeData.js 
b/airflow/www/static/js/tree/useTreeData.js
index e26a9c9..da9b4c6 100644
--- a/airflow/www/static/js/tree/useTreeData.js
+++ b/airflow/www/static/js/tree/useTreeData.js
@@ -32,6 +32,7 @@ const numRuns = getMetaValue('num_runs');
 const urlRoot = getMetaValue('root');
 const isPaused = getMetaValue('is_paused');
 const baseDate = getMetaValue('base_date');
+const isSchedulerRunning = getMetaValue('is_scheduler_running');
 
 const autoRefreshKey = 'disabledAutoRefresh';
 
@@ -55,7 +56,14 @@ const formatData = (data) => {
 const useTreeData = () => {
   const initialData = formatData(treeData);
 
-  const defaultIsOpen = isPaused !== 'True' && 
!JSON.parse(localStorage.getItem(autoRefreshKey)) && 
areActiveRuns(initialData.dagRuns);
+  const isRefreshDisabled = JSON.parse(localStorage.getItem(autoRefreshKey));
+  const defaultIsOpen = (
+    isPaused !== 'True'
+    && !isRefreshDisabled
+    && areActiveRuns(initialData.dagRuns)
+    && isSchedulerRunning === 'True'
+  );
+
   const { isOpen: isRefreshOn, onToggle, onClose } = useDisclosure({ 
defaultIsOpen });
 
   const onToggleRefresh = () => {
diff --git a/airflow/www/static/js/tree/useTreeData.test.jsx 
b/airflow/www/static/js/tree/useTreeData.test.jsx
index 624a029..af04508 100644
--- a/airflow/www/static/js/tree/useTreeData.test.jsx
+++ b/airflow/www/static/js/tree/useTreeData.test.jsx
@@ -17,14 +17,12 @@
  * under the License.
  */
 import React from 'react';
-import { renderHook } from '@testing-library/react-hooks';
+import { renderHook, act } from '@testing-library/react-hooks';
 import { QueryClient, QueryClientProvider } from 'react-query';
 import useTreeData from './useTreeData';
 
 /* global describe, test, expect, jest, beforeAll */
 
-global.autoRefreshInterval = 5;
-
 const pendingTreeData = {
   groups: {},
   dag_runs: [
@@ -58,6 +56,7 @@ const QueryWrapper = ({ children }) => {
 
 describe('Test useTreeData hook', () => {
   beforeAll(() => {
+    global.autoRefreshInterval = 5;
     global.fetch = jest.fn();
   });
 
@@ -70,11 +69,11 @@ describe('Test useTreeData hook', () => {
     expect(typeof data === 'object').toBe(true);
     expect(data.dagRuns).toBeDefined();
     expect(data.dag_runs).toBeUndefined();
-    expect(isRefreshOn).toBe(true);
+    expect(isRefreshOn).toBe(false);
     expect(typeof onToggleRefresh).toBe('function');
   });
 
-  test('queued run should have refreshOn by default and then turn off when run 
failed', async () => {
+  test('turn on autorefresh for a queued run and then auto-turn off when run 
fails', async () => {
     // return a dag run of failed during refresh
     const mockFetch = jest
       .spyOn(global, 'fetch')
@@ -85,6 +84,12 @@ describe('Test useTreeData hook', () => {
 
     const { result, waitFor } = renderHook(() => useTreeData(), { wrapper: 
QueryWrapper });
 
+    expect(result.current.isRefreshOn).toBe(false);
+
+    act(() => {
+      result.current.onToggleRefresh();
+    });
+
     expect(result.current.isRefreshOn).toBe(true);
 
     await waitFor(() => expect(mockFetch).toBeCalled());
diff --git a/airflow/www/templates/airflow/main.html 
b/airflow/www/templates/airflow/main.html
index d57f5f0..94a5d4f 100644
--- a/airflow/www/templates/airflow/main.html
+++ b/airflow/www/templates/airflow/main.html
@@ -28,6 +28,13 @@
   {% endif%}
 {% endblock %}
 
+{% block head_meta %}
+  {{ super() }}
+  {% if scheduler_job is defined and (scheduler_job and 
scheduler_job.is_alive()) %}
+    <meta name="is_scheduler_running" content="True">
+  {% endif %}
+{% endblock %}
+
 {% block head_css %}
   {{ super() }}
 

Reply via email to