예제 #1
0
)
container = CreateContainer(
    docker_server_url="tcp://localhost:2375",
    image_name="prefecthq/prefect:latest",
    command=
    '''python -c "from prefect import Flow; f = Flow('empty'); f.run()"''',
)
start = StartContainer(docker_server_url="tcp://localhost:2375", )
logs = GetContainerLogs(docker_server_url="tcp://localhost:2375",
                        trigger=always_run)
status_code = WaitOnContainer(docker_server_url="tcp://localhost:2375", )

flow = Flow(
    "Run a Prefect Flow in Docker",
    environment=KubernetesJobEnvironment(job_spec_file="job_spec.yaml"),
    storage=Docker(
        registry_url="joshmeek18",
        image_name="flows",
    ),
)

# set task dependencies using imperative API
container.set_upstream(image, flow=flow)
start.set_upstream(container, flow=flow, key="container_id")
logs.set_upstream(container, flow=flow, key="container_id")
status_code.set_upstream(container, flow=flow, key="container_id")

status_code.set_upstream(start, flow=flow)
logs.set_upstream(status_code, flow=flow)

flow.register("Demo")
    print('Hello, world!')

schedule = IntervalSchedule(interval=timedelta(minutes=1))

with Flow('Hello', schedule) as flow:
    say_hello()

flow.run()"''',
)

start = StartContainer()
logs = GetContainerLogs(trigger=always_run)
status_code = WaitOnContainer()

flow = Flow('Run in Docker')

## set individual task dependencies using imperative API
start.set_upstream(container, flow=flow, key='container_id')
logs.set_upstream(container, flow=flow, key='container_id')
status_code.set_upstream(container, flow=flow, key='container_id')

status_code.set_upstream(start, flow=flow)
logs.set_upstream(status_code, flow=flow)

## run flow and print logs
flow_state = flow.run()

print('=' * 30)
print('Container Logs')
print('=' * 30)
print(flow_state.result[logs].result)