예제 #1
0
def create_some_links():
    artifact_id_1 = artifacts.create_link("https://prefect.io111")
    print(artifact_id_1)
    artifacts.update_link(artifact_id_1, "https://new.co111")

    artifact_id_2 = artifacts.create_link("https://prefect.io222")
    print(artifact_id_2)
    artifacts.update_link(artifact_id_1, "https://new.co222")

    artifact_id_3 = artifacts.create_link("https://prefect.io333")
    print(artifact_id_3)

    print("Deleting artifact 3")
    artifacts.delete_artifact(artifact_id_2)
예제 #2
0
def test_create_link(client, running_with_backend):
    with context(task_run_id="trid"):
        artifact_id = artifacts.create_link(link="link_here")
        assert artifact_id == "id"
        assert client.create_task_run_artifact.called
        assert client.create_task_run_artifact.call_args[1] == {
            "data": {"link": "link_here"},
            "kind": "link",
            "task_run_id": "trid",
        }
예제 #3
0
def test_old_create_link(client, running_with_backend):
    with context(task_run_id="trid"):
        with pytest.warns(
            UserWarning,
            match="has been moved to `prefect.backend.create_link_artifact`",
        ):
            artifact_id = artifacts.create_link(link="link_here")
        assert artifact_id == "id"
        assert client.create_task_run_artifact.called
        assert client.create_task_run_artifact.call_args[1] == {
            "data": {"link": "link_here"},
            "kind": "link",
            "task_run_id": "trid",
        }
예제 #4
0
파일: flow_run.py 프로젝트: sp1thas/prefect
    def run(
        self,
        flow_name: str = None,
        project_name: str = None,
        parameters: dict = None,
        run_config: RunConfig = None,
        new_flow_context: dict = None,
        run_name: str = None,
        idempotency_key: str = None,
        scheduled_start_time: datetime.datetime = None,
    ) -> str:
        """
        Run method for the task; responsible for scheduling the specified flow run.

        Args:
            - flow_name (str, optional): the name of the flow to schedule; if not provided,
                this method will use the flow name provided at initialization
            - project_name (str, optional): the Cloud project in which the flow is located; if
                not provided, this method will use the project provided at initialization. If
                running with Prefect Core's server as the backend, this should not be provided.
            - parameters (dict, optional): the parameters to pass to the flow run being
                scheduled; if not provided, this method will use the parameters provided at
                initialization
            - run_config (RunConfig, optional): a run-config to use for this flow
                run, overriding any existing flow settings.
            - new_flow_context (dict, optional): the optional run context for the new flow run
            - run_name (str, optional): name to be set for the flow run
            - idempotency_key (str, optional): a unique idempotency key for scheduling the
                flow run. Duplicate flow runs with the same idempotency key will only create
                a single flow run. This is useful for ensuring that only one run is created
                if this task is retried. If not provided, defaults to the active `task_run_id`.
            - scheduled_start_time (datetime, optional): the time to schedule the execution
                for; if not provided, defaults to now

        Returns:
            - str: the ID of the newly-scheduled flow run

        Raises:
            - ValueError: if flow was not provided, cannot be found, or if a project name was
                not provided while using Cloud as a backend

        Example:
            ```python
            from prefect.tasks.prefect.flow_run import StartFlowRun

            kickoff_task = StartFlowRun(project_name="Hello, World!", flow_name="My Cloud Flow")
            ```

        """

        # verify that flow and project names were passed where necessary
        if flow_name is None:
            raise ValueError("Must provide a flow name.")
        if project_name is None:
            raise ValueError("Must provide a project name.")

        where_clause = {
            "name": {
                "_eq": flow_name
            },
            "archived": {
                "_eq": False
            },
            "project": {
                "name": {
                    "_eq": project_name
                }
            },
        }

        # find the flow ID to schedule
        query = {
            "query": {
                with_args(
                    "flow",
                    {
                        "where": where_clause,
                        "order_by": {
                            "version": EnumValue("desc")
                        },
                        "limit": 1,
                    },
                ): {"id"}
            }
        }

        client = Client()
        flow = client.graphql(query).data.flow

        # verify that a flow has been returned
        if not flow:
            raise ValueError("Flow '{}' not found.".format(flow_name))

        # grab the ID for the most recent version
        flow_id = flow[0].id

        if idempotency_key is None:
            idempotency_key = prefect.context.get("task_run_id", None)

        # providing an idempotency key ensures that retries for this task
        # will not create additional flow runs
        flow_run_id = client.create_flow_run(
            flow_id=flow_id,
            parameters=parameters,
            run_config=run_config,
            idempotency_key=idempotency_key,
            context=new_flow_context,
            run_name=run_name,
            scheduled_start_time=scheduled_start_time,
        )

        self.logger.debug(f"Flow Run {flow_run_id} created.")

        self.logger.debug(
            f"Creating link artifact for Flow Run {flow_run_id}.")
        run_link = client.get_cloud_url("flow-run", flow_run_id, as_user=False)
        create_link(urlparse(run_link).path)
        self.logger.info(f"Flow Run: {run_link}")

        if not self.wait:
            return flow_run_id

        while True:
            time.sleep(self.poll_interval.total_seconds())
            flow_run_state = client.get_flow_run_info(flow_run_id).state
            if flow_run_state.is_finished():
                exc = signal_from_state(flow_run_state)(
                    f"{flow_run_id} finished in state {flow_run_state}")
                raise exc
예제 #5
0
def create_bucket_link(bucket, file_path):
    create_link(f"https://{bucket}.s3.us-west-2.amazonaws.com/{file_path}")
                        states: [{ flow_run_id: $flowRunId, state: $state }]
                        }
                    ) {
                        states {
                        id
                        status
                        message
                        }
                    }
                }
            """,
                                            variables={
                                                "flowRunId": prev_flow_run_id,
                                                "state": {
                                                    "type": "Skipped"
                                                }
                                            })


with Flow("Previous Flow Run State Changer") as flow2:
    t1 = log_prev_flow_run_id()
    t2 = log_prev_num()
    secret = PrefectSecret("PERSONAL_ACCESS_TOKEN")
    t3 = change_prev_flow_state(t2, secret)
    create_link(prefect.context.get("prev_flow_run_id"))

flow2.add_edge(t1, t2)
flow2.storage = GitHub(repo="kmoonwright/utility_flows",
                       path="state_generators/2_prev_run_state_changer.py",
                       access_token_secret="GITHUB_ACCESS_TOKEN")
flow2.register(project_name="State Generators")
예제 #7
0
def test_create_link_not_using_backend(client):
    with context(task_run_id="trid"):
        artifact_id = artifacts.create_link(link="link_here")
        assert artifact_id == None
        assert not client.create_task_run_artifact.called
@task
def generate_flow_run_id():
    flow_run_id = prefect.context.get("flow_run_id")
    return flow_run_id


initiate_flow_run_changer = StartFlowRun(
    project_name="State Generators",
    flow_name="Previous Flow Run State Changer",
)

with Flow("Random State Generator") as flow1:
    t1 = generate_randomness()
    t2 = log_random_number(t1)
    t3 = wait()
    t4 = generate_flow_run_id()
    t5 = initiate_flow_run_changer(new_flow_context={
        "prev_flow_run_id": t4,
        "prev_random_number": t2
    })
    create_link(f"You activated a subsequent flow: {t5}")

flow1.add_edge(t1, t2)
flow1.add_edge(t2, t3)
flow1.add_edge(t3, t4)
flow1.add_edge(t4, t5)

flow1.storage = GitHub(repo="kmoonwright/utility_flows",
                       path="state_generators/1_random_state_generator.py",
                       access_token_secret="GITHUB_ACCESS_TOKEN")
flow1.register(project_name="State Generators")
예제 #9
0
            run_config=run_config,
            idempotency_key=idempotency_key,
=======
            idempotency_key=idem_key or idempotency_key,
>>>>>>> prefect clone
            context=new_flow_context,
            run_name=run_name,
            scheduled_start_time=scheduled_start_time,
        )

        self.logger.debug(f"Flow Run {flow_run_id} created.")

<<<<<<< HEAD
        self.logger.debug(f"Creating link artifact for Flow Run {flow_run_id}.")
        run_link = client.get_cloud_url("flow-run", flow_run_id, as_user=False)
        create_link(urlparse(run_link).path)

=======
>>>>>>> prefect clone
        if not self.wait:
            return flow_run_id

        while True:
            time.sleep(10)
            flow_run_state = client.get_flow_run_info(flow_run_id).state
            if flow_run_state.is_finished():
                exc = signal_from_state(flow_run_state)(
                    f"{flow_run_id} finished in state {flow_run_state}"
                )
                raise exc
예제 #10
0
 def run(self, data):
     artifact_id = artifacts.create_link(data)
     return artifact_id