Hey guys, I'd really appreciate some help. I've d...
# prefect-getting-started
n
Hey guys, I'd really appreciate some help. I've deployed prefect server with what I believe is the simplest possible method. I just have a single Windows Server, and currently a single flow. I start the server with: prefect server start --host 0.0.0.0 And I run my python script with: python main.py It contains: if name == "__main__": my_flow.serve(name="deploymentv1") The deployment is scheduled on the server at 4am every day. Firstly, is this the simplest and most robust method? I really have found the documentation on this stuff really really lacking. The docs and the AI's get clouded with obsolete Prefect V1 content. I suspect I could put the scheduling in the serve command, but the current setup should work. This has been running fine for 2 weeks, but today it just completely failed to schedule the flow run! This is a complete show stopper if I can't rely on it to schedule. Not sure how I can debug this. I tried looking through the server console output and noticed a lot of these messages: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked [SQL: DELETE FROM flow_run_notification_queue WHERE flow_run_notification_queue.id IN (SELECT 1 FROM (SELECT 1) WHERE 1!=1)] I looked that up and its a known thing? I'm about to wrap the server start in the following batch file to see if it improves and so I can have useful logs. server.bat @echo off set PREFECT_API_SERVICES_FLOW_RUN_NOTIFICATIONS_ENABLED=false prefect server start --host 0.0.0.0 >> server.txt 2>&1 rem email me that the server stopped However I can't proceed with prefect if I can't rely on it to run my flow each day. A bad PLan B is I just use windows task scheduler to run the python flow scripts, but I would lose a lot of the reason for using prefect in the first place if I do that.
j
Hi Nicholas. For production use cases you will want to use PostgreSQL as your backing database if you are self hosting.
See the docs here.
n
This is currently a trial with a single single flow, and it failed to schedule. So are you saying that sqlite just doesn't work?
j
Hi Nicholas. I’m not sure why your flow failed to run in this specific instance. It may or may not be related to SQLite. That message is explained in the response in this GitHub issue.
…When using SQLite the database is locked on occasion to ensure correct concurrent access. This log is sever and part of a loop service, it is not dangerous as the loop service will try again but we should probably more explicitly look for this error and suppress the exception so it doesn’t look as alarming
Using Postgres instead of SQLite should avoid the issue.
r
One other thought: have you set
PREFECT_API_URL
, either via running
prefect config set PREFECT_API_URL=<http://127.0.0.1:4200/api>
or setting it as an environment variable? If not, the flow will run standalone and access the database itself instead of going thorough the API server you started. You can verify this by shutting down your Prefect and and then running your flow serve script. It will still work and you can still run deployments via the Prefect CLI. But in your case you might have two processes using the Prefect database at the same time. This will work most of the time because IIRC, SQLite doesn't care if multiple processes are using the database file except if they're both trying to write to it. Once in a blue moon you'll get unlucky and have a conflict, and the flow run notification service is one of the most likely victims since it runs 15 times a minute. I'd try setting the API URL if you haven't yet. Also, if it works for your use case, consider adding the schedule to your flow.serve call. If you try to serve a flow with an interval or schedule and there's no API URL set, Prefect will give you a friendly warning that you need to set a server URL to serve a scheduled flow.
🙌 1
c
Hey @Nicholas Andonakis have you found a solution for this? Im also experiencin the same thing
179 Views