mirror of
https://github.com/apache/superset.git
synced 2026-07-20 21:55:46 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dee44e7de6 | ||
|
|
a492f27cbc | ||
|
|
668f60ba7e | ||
|
|
489d341688 |
@@ -992,27 +992,23 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
|
||||
}, [resource]);
|
||||
|
||||
// Validation
|
||||
useEffect(
|
||||
() => {
|
||||
validate();
|
||||
},
|
||||
currentAlert
|
||||
? [
|
||||
currentAlert.name,
|
||||
currentAlert.owners,
|
||||
currentAlert.database,
|
||||
currentAlert.sql,
|
||||
currentAlert.validator_config_json,
|
||||
currentAlert.crontab,
|
||||
currentAlert.working_timeout,
|
||||
currentAlert.dashboard,
|
||||
currentAlert.chart,
|
||||
contentType,
|
||||
notificationSettings,
|
||||
conditionNotNull,
|
||||
]
|
||||
: [],
|
||||
);
|
||||
const currentAlertSafe = currentAlert || {};
|
||||
useEffect(() => {
|
||||
validate();
|
||||
}, [
|
||||
currentAlertSafe.name,
|
||||
currentAlertSafe.owners,
|
||||
currentAlertSafe.database,
|
||||
currentAlertSafe.sql,
|
||||
currentAlertSafe.validator_config_json,
|
||||
currentAlertSafe.crontab,
|
||||
currentAlertSafe.working_timeout,
|
||||
currentAlertSafe.dashboard,
|
||||
currentAlertSafe.chart,
|
||||
contentType,
|
||||
notificationSettings,
|
||||
conditionNotNull,
|
||||
]);
|
||||
|
||||
// Show/hide
|
||||
if (isHidden && show) {
|
||||
|
||||
@@ -191,9 +191,16 @@ def load_examples(
|
||||
@superset.command()
|
||||
@click.option("--database_name", "-d", help="Database name to change")
|
||||
@click.option("--uri", "-u", help="Database URI to change")
|
||||
def set_database_uri(database_name: str, uri: str) -> None:
|
||||
@click.option(
|
||||
"--skip_create",
|
||||
"-s",
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Create the DB if it doesn't exist",
|
||||
)
|
||||
def set_database_uri(database_name: str, uri: str, skip_create: bool) -> None:
|
||||
"""Updates a database connection URI """
|
||||
utils.get_or_create_db(database_name, uri)
|
||||
utils.get_or_create_db(database_name, uri, not skip_create)
|
||||
|
||||
|
||||
@superset.command()
|
||||
|
||||
@@ -24,6 +24,7 @@ from typing import Any, Dict
|
||||
from urllib import request
|
||||
|
||||
import pandas as pd
|
||||
from flask import current_app
|
||||
from sqlalchemy import BigInteger, Boolean, Date, DateTime, Float, String, Text
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql.visitors import VisitableType
|
||||
@@ -125,6 +126,7 @@ def import_dataset(
|
||||
def load_data(
|
||||
data_uri: str, dataset: SqlaTable, example_database: Database, session: Session
|
||||
) -> None:
|
||||
|
||||
data = request.urlopen(data_uri)
|
||||
if data_uri.endswith(".gz"):
|
||||
data = gzip.open(data)
|
||||
@@ -137,7 +139,9 @@ def load_data(
|
||||
df[column_name] = pd.to_datetime(df[column_name])
|
||||
|
||||
# reuse session when loading data if possible, to make import atomic
|
||||
if example_database.sqlalchemy_uri == get_example_database().sqlalchemy_uri:
|
||||
if example_database.sqlalchemy_uri == current_app.config.get(
|
||||
"SQLALCHEMY_DATABASE_URI"
|
||||
) or not current_app.config.get("SQLALCHEMY_EXAMPLES_URI"):
|
||||
logger.info("Loading data inside the import transaction")
|
||||
connection = session.connection()
|
||||
else:
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Utility functions used across Superset"""
|
||||
"""
|
||||
DEPRECATION NOTICE: this module is deprecated as of v1.0.0.
|
||||
It will be removed in future versions of Superset. Please
|
||||
migrate to the new scheduler: `superset.tasks.scheduler`.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import time
|
||||
@@ -535,11 +538,10 @@ def schedule_email_report(
|
||||
@celery_app.task(
|
||||
name="alerts.run_query",
|
||||
bind=True,
|
||||
soft_time_limit=config["EMAIL_ASYNC_TIME_LIMIT_SEC"],
|
||||
# TODO: find cause of https://github.com/apache/superset/issues/10530
|
||||
# and remove retry
|
||||
autoretry_for=(NoSuchColumnError, ResourceClosedError,),
|
||||
retry_kwargs={"max_retries": 5},
|
||||
retry_kwargs={"max_retries": 1},
|
||||
retry_backoff=True,
|
||||
)
|
||||
def schedule_alert_query(
|
||||
@@ -844,8 +846,8 @@ def schedule_alerts() -> None:
|
||||
resolution = 0
|
||||
now = datetime.utcnow()
|
||||
start_at = now - timedelta(
|
||||
seconds=3600
|
||||
) # process any missed tasks in the past hour
|
||||
seconds=300
|
||||
) # process any missed tasks in the past few minutes
|
||||
stop_at = now + timedelta(seconds=1)
|
||||
with session_scope(nullpool=True) as session:
|
||||
schedule_window(ScheduleType.alert, start_at, stop_at, resolution, session)
|
||||
|
||||
@@ -1095,7 +1095,7 @@ def user_label(user: User) -> Optional[str]:
|
||||
|
||||
|
||||
def get_or_create_db(
|
||||
database_name: str, sqlalchemy_uri: str, *args: Any, **kwargs: Any
|
||||
database_name: str, sqlalchemy_uri: str, always_create: Optional[bool] = True
|
||||
) -> "Database":
|
||||
from superset import db
|
||||
from superset.models import core as models
|
||||
@@ -1104,13 +1104,15 @@ def get_or_create_db(
|
||||
db.session.query(models.Database).filter_by(database_name=database_name).first()
|
||||
)
|
||||
|
||||
if not database:
|
||||
if not database and always_create:
|
||||
logger.info("Creating database reference for %s", database_name)
|
||||
database = models.Database(database_name=database_name, *args, **kwargs)
|
||||
database = models.Database(database_name=database_name)
|
||||
db.session.add(database)
|
||||
|
||||
database.set_sqlalchemy_uri(sqlalchemy_uri)
|
||||
db.session.commit()
|
||||
if database:
|
||||
database.set_sqlalchemy_uri(sqlalchemy_uri)
|
||||
db.session.commit()
|
||||
|
||||
return database
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user