Differential D6810 Diff 33326 python_modules/libraries/dagster-mysql/dagster_mysql/schedule_storage/schedule_storage.py
Changeset View
Changeset View
Standalone View
Standalone View
python_modules/libraries/dagster-mysql/dagster_mysql/schedule_storage/schedule_storage.py
import sqlalchemy as db | import sqlalchemy as db | ||||
from dagster import check | from dagster import check | ||||
from dagster.core.storage.schedules import ScheduleStorageSqlMetadata, SqlScheduleStorage | from dagster.core.storage.schedules import ScheduleStorageSqlMetadata, SqlScheduleStorage | ||||
from dagster.core.storage.sql import create_engine, run_alembic_upgrade, stamp_alembic_rev | from dagster.core.storage.sql import create_engine, run_alembic_upgrade, stamp_alembic_rev | ||||
from dagster.serdes import ConfigurableClass, ConfigurableClassData | from dagster.serdes import ConfigurableClass, ConfigurableClassData | ||||
from dagster.utils.backcompat import experimental_class_warning | from dagster.utils.backcompat import experimental | ||||
from ..utils import ( | from ..utils import ( | ||||
create_mysql_connection, | create_mysql_connection, | ||||
mysql_alembic_config, | mysql_alembic_config, | ||||
mysql_config, | mysql_config, | ||||
mysql_url_from_config, | mysql_url_from_config, | ||||
retry_mysql_connection_fn, | retry_mysql_connection_fn, | ||||
retry_mysql_creation_fn, | retry_mysql_creation_fn, | ||||
) | ) | ||||
@experimental | |||||
class MySQLScheduleStorage(SqlScheduleStorage, ConfigurableClass): | class MySQLScheduleStorage(SqlScheduleStorage, ConfigurableClass): | ||||
"""MySQL-backed run storage. | """MySQL-backed run storage. | ||||
Users should not directly instantiate this class; it is instantiated by internal machinery when | Users should not directly instantiate this class; it is instantiated by internal machinery when | ||||
``dagit`` and ``dagster-graphql`` load, based on the values in the ``dagster.yaml`` file in | ``dagit`` and ``dagster-graphql`` load, based on the values in the ``dagster.yaml`` file in | ||||
``$DAGSTER_HOME``. Configuration of this class should be done by setting values in that file. | ``$DAGSTER_HOME``. Configuration of this class should be done by setting values in that file. | ||||
To use MySQL for schedule storage, you can add a block such as the following to your | To use MySQL for schedule storage, you can add a block such as the following to your | ||||
``dagster.yaml``: | ``dagster.yaml``: | ||||
.. literalinclude:: ../../../../../examples/docs_snippets/docs_snippets/deploying/dagster-mysql.yaml | .. literalinclude:: ../../../../../examples/docs_snippets/docs_snippets/deploying/dagster-mysql.yaml | ||||
:caption: dagster.yaml | :caption: dagster.yaml | ||||
:lines: 23-32 | :lines: 23-32 | ||||
:language: YAML | :language: YAML | ||||
Note that the fields in this config are :py:class:`~dagster.StringSource` and | Note that the fields in this config are :py:class:`~dagster.StringSource` and | ||||
:py:class:`~dagster.IntSource` and can be configured from environment variables. | :py:class:`~dagster.IntSource` and can be configured from environment variables. | ||||
""" | """ | ||||
def __init__(self, mysql_url, inst_data=None): | def __init__(self, mysql_url, inst_data=None): | ||||
experimental_class_warning("MySQLScheduleStorage") | |||||
self._inst_data = check.opt_inst_param(inst_data, "inst_data", ConfigurableClassData) | self._inst_data = check.opt_inst_param(inst_data, "inst_data", ConfigurableClassData) | ||||
self.mysql_url = mysql_url | self.mysql_url = mysql_url | ||||
# Default to not holding any connections open to prevent accumulating connections per DagsterInstance | # Default to not holding any connections open to prevent accumulating connections per DagsterInstance | ||||
self._engine = create_engine( | self._engine = create_engine( | ||||
self.mysql_url, isolation_level="AUTOCOMMIT", poolclass=db.pool.NullPool | self.mysql_url, isolation_level="AUTOCOMMIT", poolclass=db.pool.NullPool | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |