Tarek
06/03/2022, 11:25 AMAnna Geller
06/03/2022, 11:29 AMTarek
06/03/2022, 11:30 AMversion: "3.7"
services:
agent:
build: .
command: bash -c "prefect agent local start --name $$(uuid) --no-hostname-label --label development"
volumes:
- /srv/docker/prefect/flows:/root/.prefect/flows
- type: bind
source: ./config.toml
target: /root/.prefect/config.toml
read_only: true
and my client
import json
import requests
import prefect
from prefect import Flow, task, Client
from prefect.storage import Local
logger = prefect.context.get("logger")
from prefect.run_configs import LocalRun
from prefect import task, Flow
from prefect.schedules import Schedule
from prefect.schedules.clocks import CronClock
from lib.afunction import get_other_text
import datetime
import pytz
every_10min = "*/1 * * * *"
REF_TZ_BERLIN = 'Europe/Berlin'
schedule = Schedule(clocks=[CronClock(every_10min,start_date=datetime.datetime.now(pytz.timezone(REF_TZ_BERLIN)))])
@task
def get_text():
return "text"
@task
def put_text(text):
<http://logger.info|logger.info>("Getting text of {}".format(text))
print(text + "text")
return text + "text" + get_other_text()
with Flow("local_test_flow", storage=Local(add_default_labels=False)) as flow:
text = get_text()
put_text(text)
try:
client = Client()
client.create_project(project_name="weather")
except prefect.utilities.exceptions.ClientError as e:
<http://logger.info|logger.info>("Project already exists")
#flow.register(project_name="weather", labels=["development"], add_default_labels=False)
FLOW_NAME = "scheduled_local_flow"
with Flow(
FLOW_NAME,
storage=Local(add_default_labels=False
),
schedule=schedule,
run_config=LocalRun(),
) as flow_schedule:
text = get_text()
put_text(text)
flow_schedule.register(project_name="weather", labels=["development"], add_default_labels=False)
docker-compose of the client weather.py:
version: "3.7"
services:
weather:
build: .
command: python3 /usr/app/weather.py
volumes:
- /srv/docker/prefect/flows:/root/.prefect/flows
- type: bind
source: ./weather.py
target: /usr/app/weather.py
read_only: true
- type: bind
source: ./lib/afunction.py
target: /usr/app/lib/afunction.py
read_only: true
- type: bind
source: ./config.toml
target: /root/.prefect/config.toml
read_only: true
and what's the purpose of this mount??
/srv/docker/prefect/flows:/root/.prefect/flows
the import problem only occur if i import a function from other file, but if i used the task/function locally. the flow will execute the task successfully..Anna Geller
06/03/2022, 11:31 AMprefect agent local start -p /path/to/your/lib
Tarek
06/03/2022, 11:34 AM/srv/docker/prefect/flows:/root/.prefect/flows
i saw it from sample file, what is this actually doing??
but after the import lib its again the same problem, but thanks i will look to your artikel..Anna Geller
06/03/2022, 11:36 AM