def test_enum_backcompat(): test_env = WhitelistMap.create() class MyEnumSerializer(EnumSerializer): @classmethod def value_from_storage_str(cls, storage_str, klass): return getattr(klass, storage_str) @classmethod def value_to_storage_str(cls, value, whitelist_map, descent_path): val_as_str = str(value) actual_enum_val = val_as_str.split(".")[1:] backcompat_name = ( "OldEnum" # Simulate changing the storage name to some legacy backcompat name ) return ".".join([backcompat_name, *actual_enum_val]) @_whitelist_for_serdes(test_env, serializer=MyEnumSerializer) class MyEnum(Enum): RED = "color.red" BLUE = "color.red" # Ensure that serdes roundtrip preserves value register_serdes_enum_fallbacks({"OldEnum": MyEnum}, whitelist_map=test_env) my_enum = MyEnum("color.red") enum_json = serialize_value(my_enum, whitelist_map=test_env) result = _deserialize_json(enum_json, test_env) assert result == my_enum # ensure that "legacy" environment can correctly interpret enum stored under legacy name. legacy_env = WhitelistMap.create() @_whitelist_for_serdes(legacy_env) class OldEnum(Enum): RED = "color.red" BLUE = "color.blue" result = _deserialize_json(enum_json, legacy_env) old_enum = OldEnum("color.red") assert old_enum == result
from collections import namedtuple from enum import Enum from dagster import check from dagster.core.storage.pipeline_run import PipelineRun from dagster.serdes.serdes import register_serdes_enum_fallbacks, whitelist_for_serdes from dagster.utils.error import SerializableErrorInfo @whitelist_for_serdes class InstigatorType(Enum): SCHEDULE = "SCHEDULE" SENSOR = "SENSOR" register_serdes_enum_fallbacks({"JobType": InstigatorType}) # for internal backcompat JobType = InstigatorType @whitelist_for_serdes class SkipReason(namedtuple("_SkipReason", "skip_message")): """ Represents a skipped evaluation, where no runs are requested. May contain a message to indicate why no runs were requested. Attributes: skip_message (Optional[str]): A message displayed in dagit for why this evaluation resulted in no requested runs. """ def __new__(cls, skip_message=None):
class DagsterRunStatus(Enum): """The status of pipeline execution.""" QUEUED = "QUEUED" NOT_STARTED = "NOT_STARTED" MANAGED = "MANAGED" STARTING = "STARTING" STARTED = "STARTED" SUCCESS = "SUCCESS" FAILURE = "FAILURE" CANCELING = "CANCELING" CANCELED = "CANCELED" PipelineRunStatus = DagsterRunStatus register_serdes_enum_fallbacks({"PipelineRunStatus": DagsterRunStatus}) # These statuses that indicate a run may be using compute resources IN_PROGRESS_RUN_STATUSES = [ PipelineRunStatus.STARTING, PipelineRunStatus.STARTED, PipelineRunStatus.CANCELING, ] # This serves as an explicit list of run statuses that indicate that the run is not using compute # resources. This and the enum above should cover all run statuses. NON_IN_PROGRESS_RUN_STATUSES = [ PipelineRunStatus.QUEUED, PipelineRunStatus.NOT_STARTED, PipelineRunStatus.SUCCESS, PipelineRunStatus.FAILURE,
from dagster.utils import merge_dicts from dagster.utils.error import SerializableErrorInfo @whitelist_for_serdes class InstigatorStatus(Enum): # User has taken some action to start the run instigator RUNNING = "RUNNING" # The run instigator is running, but only because of its default setting AUTOMATICALLY_RUNNING = "AUTOMATICALLY_RUNNING" STOPPED = "STOPPED" register_serdes_enum_fallbacks({"JobStatus": InstigatorStatus}) # for internal backcompat JobStatus = InstigatorStatus @whitelist_for_serdes class SensorInstigatorData( NamedTuple( "_SensorInstigatorData", [ ("last_tick_timestamp", Optional[float]), ("last_run_key", Optional[str]), ("min_interval", Optional[int]), ("cursor", Optional[str]), ], )