Hi <@ULVA73B9P> I am getting the following warnin...
# ask-marvin
a
Hi @Marvin I am getting the following warning:
Copy code
PrefectDeprecationWarning: prefect.infrastructure.process.Process has been deprecated. It will not be available after Sep 2024. Use the process worker instead. Refer to the upgrade guide for more information: <https://docs.prefect.io/latest/guides/upgrade-guide-agents-to-workers/>
What should I change in my deployment below so that the warning goes away
Copy code
Deployment.build_from_flow(
                flow=bhavcopy_flow,
                name=f"{project_name}-{current_file}-{segment}",
                version="1",
                tags=[project_name],
                parameters={"segment": segment},
                work_pool_name="local-pool",
                work_queue_name="local-queue",
                schedules=[cron],
                infrastructure=Process(
                    working_dir=f"/home/{os.environ.get('USER')}/miniflows/"
                ),
            )
m
The deprecation warning indicates that Prefect will retire
prefect.infrastructure.process.Process
. You should leverage the process worker infrastructure instead. Below is your modified deployment code:
Copy code
python
from prefect.deployments import Deployment
from prefect.infrastructure import ProcessWorker  # Import the ProcessWorker class

Deployment.build_from_flow(
    flow=bhavcopy_flow,
    name=f"{project_name}-{current_file}-{segment}",
    version="1",
    tags=[project_name],
    parameters={"segment": segment},
    work_pool_name="local-pool",
    work_queue_name="local-queue",
    schedules=[cron],
    infrastructure=ProcessWorker(
        working_dir=f"/home/{os.environ.get('USER')}/miniflows/"
    ),
)
Make sure you have the
ProcessWorker
class correctly imported and utilized in the deployment configuration. For further details, you can refer to the Prefect Upgrade Guide.
a
@Marvin why isn't prefect able to read my environment variables when I deploy the flow
m
It appears that Prefect might not be picking up your environment variables due to the deployment configuration. Here are some steps to ensure your environment variables are properly read: 1. Set Environment Variables in Deployment Configuration: Use the
job_variables
section in your deployment YAML or add an
env
configuration directly in your deployment code. 2. Use
ProcessWorker
and Pass Environment Variables:
Below is an updated version of your deployment code that specifies environment variables within the deployment configuration:
Copy code
python
    from prefect.deployments import Deployment
    from prefect.infrastructure import ProcessWorker  # Import the ProcessWorker class

    Deployment.build_from_flow(
        flow=bhavcopy_flow,
        name=f"{project_name}-{current_file}-{segment}",
        version="1",
        tags=[project_name],
        parameters={"segment": segment},
        work_pool_name="local-pool",
        work_queue_name="local-queue",
        schedules=[cron],
        infrastructure=ProcessWorker(
            env={
                "USER": os.environ.get("USER")  # Add your required environment variables here
            },
            working_dir=f"/home/{os.environ.get('USER')}/miniflows/"
        ),
    )
3. Check Work Pool and Work Queue Configuration: Depending on how your work pool and queue are configured, you might need to set environment variables there as well. 4. Ensure Correct Override Mechanism: Refer to the deployment guide to ensure correct override mechanisms are used for job variables. See the Overriding Job Variables guide for more details. ### Relevant Issues from GitHub You might find useful insights or workarounds regarding this in relevant GitHub issues: - Job variables should use a deep merge rather than shallow merge of dictionaries - build_from_flow docstring is wrong for ENV and infra_overrides are not validated - There is no way to pass secrets to ECSTask Implementing these changes should help ensure that your environment variables are picked up during flow deployment.