Jonny
10/12/2024, 3:18 PMif __name__== "__main__":
run.serve(name="api_pull_deployment", cron="0 * * * *")
This works the way I want it to, and I can see that the job is scheduled every hour and seems to run. However, when I close the terminal, the status of the deployment changes to not ready in the prefect server UI and the future scheduled runs don't happen. How can I schedule runs and then close my terminal?Marvin
10/12/2024, 3:19 PMnohup
or screen
or `tmux`:
- nohup: This command allows a process to continue running in the background after you log out. Run your script with:
nohup python your_script.py &
- screen/tmux: These terminal multiplexers allow you to create a terminal session that can be detached and reattached later. Start a screen
or tmux
session, run your command, and then detach from the session.
2. Systemd Service:
- Create a systemd service file in /etc/systemd/system/
. This will allow your script to run as a service managed by the init system.
Example of a basic service file:
[Unit]
Description=My Prefect Flow Service
[Service]
ExecStart=/usr/bin/python /path/to/your_script.py
Restart=always
[Install]
WantedBy=multi-user.target
- Enable and start the service with:
sudo systemctl enable my-prefect-flow.service
sudo systemctl start my-prefect-flow.service
3. Docker:
- If you are already using Docker, consider running your Prefect script inside a Docker container. The container can be run in detached mode.
Make sure to check the Prefect version you are using. In Prefect 2.x and 3.x, the orchestration and scheduling might differ, but the above general techniques to persist execution should help in both versions.
If you need more detailed instructions, let me know the version of Prefect you're using, and I can assist further. For now, these methods should help you ensure your scheduled jobs continue to run even after the terminal is closed.Jonny
10/12/2024, 3:25 PMMarvin
10/12/2024, 3:26 PM