Vugar Yagubov
02/25/2025, 7:13 PMcron = CronSchedule(cron="8 9 * * *", timezone="Europe/Berlin")
into the following construction?
flow.from_source(
source=gitlab_repo,
entrypoint=entrypoint,
).deploy(
name=deployment_name,
work_pool_name=work_pool_name,
job_variables=job_variables,
)
The deploy()
method expects either cron: Optional[str]
or schedules: Optional[list[DeploymentScheduleCreate]]
.
I couldn't make it work with either of them. Prefect 3.1.
Any advice would be appreciated.Bianca Hoch
02/25/2025, 7:34 PMfrom prefect.schedules import CronSchedule
...
if __name__ == "__main__":
flow.from_source(
source=gitlab_repo,
entrypoint=entrypoint,
).deploy(
name="my-deployment",
work_pool_name="my-work-pool",
schedules=CronSchedule(cron="8 9 * * *", timezone="Europe/Berlin")
)
Vugar Yagubov
02/25/2025, 7:43 PMFile "..../orchestrator/lib/deploy.py", line 64, in deploy_all_deployments
).deploy(
^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 353, in coroutine_wrapper
return run_coro_as_sync(ctx_call())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 209, in run_coro_as_sync
return call.result()
^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 330, in result
return self.future.result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 193, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.12/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "...venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 403, in _run_async
result = await coro
^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 190, in coroutine_wrapper
return await task
^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 343, in ctx_call
result = await async_fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/flows.py", line 1479, in deploy
deployment = await to_deployment_coro
^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/flows.py", line 743, in ato_deployment
return await RunnerDeployment.afrom_storage(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/deployments/runner.py", line 806, in afrom_storage
deployment = cls(
^^^^
File "...venv/lib/python3.12/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/deployments/runner.py", line 256, in reconcile_schedules
return reconcile_schedules_runner(values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/_internal/schemas/validators.py", line 194, in reconcile_schedules_runner
if schedules is not None and len(schedules) > 0:
^^^^^^^^^^^^^^
TypeError: object of type 'CronSchedule' has no len()
schedules
needs listVugar Yagubov
02/25/2025, 7:47 PMfrom prefect.schedules import CronSchedule
...
if __name__ == "__main__":
flow.from_source(
source=gitlab_repo,
entrypoint=entrypoint,
).deploy(
name="my-deployment",
work_pool_name="my-work-pool",
schedules=[CronSchedule(cron="8 9 * * *", timezone="Europe/Berlin")]
)
then I get:Vugar Yagubov
02/25/2025, 7:48 PMFile ".../orchestrator/lib/deploy.py", line 65, in deploy_all_deployments
).deploy(
^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 353, in coroutine_wrapper
return run_coro_as_sync(ctx_call())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 209, in run_coro_as_sync
return call.result()
^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 330, in result
return self.future.result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 193, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.12/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "...venv/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 403, in _run_async
result = await coro
^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 190, in coroutine_wrapper
return await task
^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 343, in ctx_call
result = await async_fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/flows.py", line 1479, in deploy
deployment = await to_deployment_coro
^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/flows.py", line 743, in ato_deployment
return await RunnerDeployment.afrom_storage(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...venv/lib/python3.12/site-packages/prefect/deployments/runner.py", line 806, in afrom_storage
deployment = cls(
^^^^
File "...venv/lib/python3.12/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for RunnerDeployment
Value error, Server schema schedules are not supported. Please use the schedule objects from `prefect.client.schemas.schedules` [type=value_error, input_value={'name': 'SnowflakeExport...ne, 'job_variables': {}}, input_type=dict]
For further information visit <https://errors.pydantic.dev/2.10/v/value_error>
Vugar Yagubov
02/25/2025, 7:49 PMBianca Hoch
02/25/2025, 7:53 PMschedules
does require a list. The version you're using will influence how you pass in the schedule.
For prefect versions < 3.1.16:
schedules=[CronSchedule(cron="8 9 * * *", timezone="Europe/Berlin")]
And then for versions >= 3.1.16:
schedule=CronSchedule(
cron="8 9 * * *",
timezone="Europe/Berlin"
)
Vugar Yagubov
02/25/2025, 7:55 PMBianca Hoch
02/25/2025, 7:55 PMBianca Hoch
02/25/2025, 7:55 PMVugar Yagubov
02/25/2025, 8:47 PMfrom prefect.schedules import Cron
flow.from_source(
source=gitlab_repo,
entrypoint=entrypoint,
).deploy(
name=name,
....
schedule=Cron(cron="8 9 * * *", timezone="Europe/Berlin"),
....
)
And it was successful.
Thanks for your help!