@@ -666,34 +666,61 @@ def execute_in_process(
666
666
:py:class:`~dagster.ExecuteInProcessResult`
667
667
668
668
"""
669
- from dagster ._core .definitions .executor_definition import execute_in_process_executor
670
- from dagster ._core .definitions .run_config import convert_config_input
671
- from dagster ._core .execution .build_resources import wrap_resources_for_execution
672
- from dagster ._core .execution .execute_in_process import core_execute_in_process
673
-
674
- run_config = check .opt_mapping_param (convert_config_input (run_config ), "run_config" )
675
- op_selection = check .opt_sequence_param (op_selection , "op_selection" , str )
676
- asset_selection = check .opt_sequence_param (asset_selection , "asset_selection" , AssetKey )
677
- resources = check .opt_mapping_param (resources , "resources" , key_type = str )
669
+ from dagster ._core .definitions .job_base import InMemoryJob
670
+ from dagster ._core .execution .execute_in_process import (
671
+ core_execute_in_process ,
672
+ merge_run_tags ,
673
+ type_check_and_normalize_args ,
674
+ )
678
675
679
- resource_defs = wrap_resources_for_execution (resources )
676
+ run_config , op_selection , asset_selection , resource_defs , partition_key , input_values = (
677
+ type_check_and_normalize_args (
678
+ run_config = run_config ,
679
+ partition_key = partition_key ,
680
+ op_selection = op_selection ,
681
+ asset_selection = asset_selection ,
682
+ input_values = input_values ,
683
+ resources = resources ,
684
+ )
685
+ )
680
686
681
- check .invariant (
682
- not (op_selection and asset_selection ),
683
- "op_selection and asset_selection cannot both be provided as args to"
684
- " execute_in_process" ,
687
+ ephemeral_job = self .as_ephemeral_job (
688
+ resource_defs = resource_defs ,
689
+ input_values = input_values ,
690
+ op_selection = op_selection ,
691
+ asset_selection = asset_selection ,
685
692
)
686
693
687
- partition_key = check .opt_str_param (partition_key , "partition_key" )
688
- input_values = check .opt_mapping_param (input_values , "input_values" )
694
+ wrapped_job = InMemoryJob (job_def = ephemeral_job )
695
+ return core_execute_in_process (
696
+ job = wrapped_job ,
697
+ run_config = run_config ,
698
+ instance = instance ,
699
+ output_capturing_enabled = True ,
700
+ raise_on_error = raise_on_error ,
701
+ run_tags = merge_run_tags (
702
+ job_def = self ,
703
+ partition_key = partition_key ,
704
+ tags = tags ,
705
+ asset_selection = asset_selection ,
706
+ instance = instance ,
707
+ run_config = run_config ,
708
+ ),
709
+ run_id = run_id ,
710
+ asset_selection = frozenset (asset_selection ),
711
+ )
689
712
690
- # Combine provided input values at execute_in_process with input values
691
- # provided to the definition. Input values provided at
692
- # execute_in_process will override those provided on the definition.
693
- input_values = merge_dicts (self .input_values , input_values )
713
+ def as_ephemeral_job (
714
+ self ,
715
+ resource_defs : Mapping [str , ResourceDefinition ],
716
+ input_values : Mapping [str , object ],
717
+ op_selection : Optional [Sequence [str ]] = None ,
718
+ asset_selection : Optional [Sequence [AssetKey ]] = None ,
719
+ ) -> "JobDefinition" :
720
+ from dagster ._core .definitions .executor_definition import execute_in_process_executor
694
721
695
722
bound_resource_defs = dict (self .resource_defs )
696
- ephemeral_job = JobDefinition .dagster_internal_init (
723
+ return JobDefinition .dagster_internal_init (
697
724
name = self ._name ,
698
725
graph_def = self ._graph_def ,
699
726
resource_defs = {** _swap_default_io_man (bound_resource_defs , self ), ** resource_defs },
@@ -705,54 +732,17 @@ def execute_in_process(
705
732
run_tags = self ._run_tags ,
706
733
op_retry_policy = self ._op_retry_policy ,
707
734
asset_layer = self .asset_layer ,
708
- input_values = input_values ,
735
+ input_values = merge_dicts ( self . input_values , input_values ) ,
709
736
description = self .description ,
710
737
partitions_def = self .partitions_def ,
711
738
metadata = self .metadata ,
712
739
_subset_selection_data = None , # this is added below
713
740
_was_explicitly_provided_resources = True ,
714
- )
715
-
716
- ephemeral_job = ephemeral_job .get_subset (
741
+ ).get_subset (
717
742
op_selection = op_selection ,
718
743
asset_selection = frozenset (asset_selection ) if asset_selection else None ,
719
744
)
720
745
721
- merged_run_tags = merge_dicts (self .run_tags , tags or {})
722
- if partition_key :
723
- ephemeral_job .validate_partition_key (
724
- partition_key ,
725
- selected_asset_keys = asset_selection ,
726
- dynamic_partitions_store = instance ,
727
- )
728
- tags_for_partition_key = ephemeral_job .get_tags_for_partition_key (
729
- partition_key ,
730
- selected_asset_keys = asset_selection ,
731
- )
732
-
733
- if not run_config and self .partitioned_config :
734
- run_config = self .partitioned_config .get_run_config_for_partition_key (partition_key )
735
-
736
- if self .partitioned_config :
737
- merged_run_tags .update (
738
- self .partitioned_config .get_tags_for_partition_key (
739
- partition_key , job_name = self .name
740
- )
741
- )
742
- else :
743
- merged_run_tags .update (tags_for_partition_key )
744
-
745
- return core_execute_in_process (
746
- ephemeral_job = ephemeral_job ,
747
- run_config = run_config ,
748
- instance = instance ,
749
- output_capturing_enabled = True ,
750
- raise_on_error = raise_on_error ,
751
- run_tags = merged_run_tags ,
752
- run_id = run_id ,
753
- asset_selection = frozenset (asset_selection ),
754
- )
755
-
756
746
def _get_partitions_def (
757
747
self , selected_asset_keys : Optional [Iterable [AssetKey ]]
758
748
) -> PartitionsDefinition :
0 commit comments