Exemplo n.º 1
0
def test_jobs_attr():
    def eval_fn():
        pass

    @graph
    def my_graph():
        pass

    sensor = SensorDefinition(evaluation_fn=eval_fn, job=my_graph)
    assert sensor.job.name == my_graph.name

    sensor = SensorDefinition(evaluation_fn=eval_fn,
                              pipeline_name="my_pipeline")
    with pytest.raises(DagsterInvalidDefinitionError,
                       match="No job was provided to SensorDefinition."):
        sensor.job

    @graph
    def my_second_graph():
        pass

    sensor = SensorDefinition(evaluation_fn=eval_fn,
                              jobs=[my_graph, my_second_graph])
    with pytest.raises(
            DagsterInvalidDefinitionError,
            match=
            "Job property not available when SensorDefinition has multiple jobs.",
    ):
        sensor.job
Exemplo n.º 2
0
def build_post_import_sensor(env: str) -> SensorDefinition:
    """
    Builds a post-validation sensor, responsible for determining the source argo workflow and
    kicking off our post-import validation egress pipeline.
    :param env: Environment in which this sensor runs, corresponds to the "mode" as defined in the
    validate_egress module.
    """
    def _validate_on_import_complete(_: SensorExecutionContext) -> Union[Iterator[RunRequest], SkipReason]:
        sensor = ArgoHcaImportCompletionSensor(
            argo_url=os.environ["HCA_ARGO_URL"],
            access_token=default_google_access_token())

        workflows = sensor.successful_hca_import_workflows()

        if any(workflows):
            for workflow in workflows:
                yield sensor.generate_run_request(workflow)
        else:
            return SkipReason("No succeeded import-hca-total workflows returned by Argo.")

    return SensorDefinition(
        name="post_import_validate_egress",
        pipeline_name="validate_egress",
        mode=env,
        evaluation_fn=_validate_on_import_complete
    )
Exemplo n.º 3
0
def test_sensor_no_pipeline_name():
    foo_system_sensor = SensorDefinition(name="foo", evaluation_fn=lambda x: x)

    @repository
    def foo_repo():
        return [foo_system_sensor]

    assert foo_repo.has_sensor_def("foo")
Exemplo n.º 4
0
def test_direct_sensor_definition_instantiation():
    with pytest.raises(
            DagsterInvalidDefinitionError,
            match="Must provide evaluation_fn to SensorDefinition."):
        SensorDefinition()