mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix: Ensure alerts & reports aren't schduled when flag is off (#16639)
* Don't schedule alerts & reports when flag is off * Fix test function name * Fix test * Oops * Another tweak * Try to lint by hand * Fix mock
This commit is contained in:
@@ -19,7 +19,7 @@ import logging
|
||||
from celery.exceptions import SoftTimeLimitExceeded
|
||||
from dateutil import parser
|
||||
|
||||
from superset import app
|
||||
from superset import app, is_feature_enabled
|
||||
from superset.commands.exceptions import CommandException
|
||||
from superset.extensions import celery_app
|
||||
from superset.reports.commands.exceptions import ReportScheduleUnexpectedError
|
||||
@@ -37,6 +37,8 @@ def scheduler() -> None:
|
||||
"""
|
||||
Celery beat main scheduler for reports
|
||||
"""
|
||||
if not is_feature_enabled("ALERT_REPORTS"):
|
||||
return
|
||||
with session_scope(nullpool=True) as session:
|
||||
active_schedules = ReportScheduleDAO.find_active(session)
|
||||
for active_schedule in active_schedules:
|
||||
|
||||
@@ -115,3 +115,25 @@ def test_scheduler_celery_no_timeout_utc(execute_mock):
|
||||
db.session.delete(report_schedule)
|
||||
db.session.commit()
|
||||
app.config["ALERT_REPORTS_WORKING_TIME_OUT_KILL"] = True
|
||||
|
||||
|
||||
@patch("superset.tasks.scheduler.is_feature_enabled")
|
||||
@patch("superset.tasks.scheduler.execute.apply_async")
|
||||
def test_scheduler_feature_flag_off(execute_mock, is_feature_enabled):
|
||||
"""
|
||||
Reports scheduler: Test scheduler with feature flag off
|
||||
"""
|
||||
with app.app_context():
|
||||
is_feature_enabled.return_value = False
|
||||
report_schedule = insert_report_schedule(
|
||||
type=ReportScheduleType.ALERT,
|
||||
name="report",
|
||||
crontab="0 9 * * *",
|
||||
timezone="UTC",
|
||||
)
|
||||
|
||||
with freeze_time("2020-01-01T09:00:00Z"):
|
||||
scheduler()
|
||||
execute_mock.assert_not_called()
|
||||
db.session.delete(report_schedule)
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user