What I thought was a simple python upgrade broke my deployed flask service. Need some help.
Project ID: b06af9f3-d9c9-4d4c-a74f-c5521f149984/service/872870dd-f98a-486c-9f14-09fcd5bc43e5
87 Replies
Project ID:
b06af9f3-d9c9-4d4c-a74f-c5521f149984,872870dd-f98a-486c-9f14-09fcd5bc43e5
well what broke? show us some logs please?
I'm using a lightweight task library called Huey, which uses Redis as the storage layer. That's failing to bootstrap in my init.
File "/app/myapp/init.py", line 42, in create_app
from . import tasks
File "/app/myapp/tasks/init.py", line 2, in <module>
from .cli import register_cli_blueprint
File "/app/myapp/tasks/cli.py", line 6, in <module>
from .tasker import TASKER
File "/app/myapp/tasks/tasker.py", line 30, in <module>
TASKER: Tasker = Tasker(current_app)
^^^^^^^^^^^^^^^^^^^
File "/app/myapp/tasks/tasker.py", line 10, in init
self.init_app(app)
File "/app/myapp/tasks/tasker.py", line 14, in init_app
huey_instance = RedisHuey(
^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/huey/api.py", line 116, in init
self.storage = self.create_storage()
^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/huey/api.py", line 135, in create_storage
return self.get_storage(self.storage_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/huey/api.py", line 147, in get_storage
return Storage(self.name, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/huey/storage.py", line 369, in init
raise ConfigurationError('"redis" python module not found, cannot '
huey.exceptions.ConfigurationError: "redis" python module not found, cannot use Redis storage backend. Run "pip install redis" to
please provide logs as .txt or .log files
or at minimum wrap that text in triple backticks
but regardless, do you have redis in your requirements.txt file?
sorry, is there an easy way to do that from Railway's UI?
I'm using a Pipfile
do you have a requirements.txt file though?
and yes, Redis is specified there
no I do not
https://bookmarklets.up.railway.app/log-downloader/
use that to send both your build and deploy logs please
why do you have redis in the setup phase? what have you done there?
ah, I added that in a fit of debugging and trying random things last night
it was not there when this was all working on Python 3.8
I assume you are using a nixpacks.toml file? if so, send that over please
I overwrote the start command for this service (my repo is a mono repo)
I have it set as inside of Railway's UI to override
who wrote that file?
it looks like something chatgpt would write after scanning the nixpacks docs site
initially generated but I made a few modifications. Had to debug the dockerfile locally to get to this point
if there are ways to simplify it, I'm all ears
was it chatgpt generated, I'm curious
I don't think so, I might have copied it from another repo
but like I said, I made some modifications after lots of local debugging with Docker
can you share your repo?
sure, send me your GH username
brody192
done, repo is called kdp-analyzer
so i can assume that you do have the root directory in the service settings set to /backend right?
yes
either way, delete your Procfile and nixpacks.toml file from the repo and locally, we will then go from there
okay, let me do that and push a commit
pushed
what version of python do you use locally
3.11
3.11.5 to be exact
add a
.python-version
with 3.11
in itokay, and I assume make sure that's not ignored and goes into git?
it tells nixpacks to use python 3.11
otherwise the default is 3.8
oh got it
ok pushed that
youll now want to remove any build or start commands you may have set in the service settings, and add this railway.json file to your backend folder
you where using the flask command to run your app, as far as im aware, that starts a development server
right
that's the web server
we do not want to run the server in development mode on railway
the flask command was used for only the task manager huey
the web server was run with
did you have two services for the backend or something?
yeah
originally I had one
the command was set to "gunicorn wsgi:gunicorn_app --log-level=debug & flask run-huey"
not ideal
I think I have to go back to that, unfortunately both use a shared file system
files get uploaded via web, and processed via Huey
I was going to move to an S3 bucket that could be shared at some point
is it better to have two separate services or one?
its not ideal because that will run gunicorn in the background, railway wont be able to detect a crash
right
you said you need a shared fs, so you need to do one service until railway supports attaching a volume to multiple services
exactly
to run two things in one service we need to use a tool called parallel
but we will come back to that later, lets get the web server part of this working first
so remove one of the backend services
I'm trying, the railway UI appears broken
might have to use the CLI
broken?
Delete button won't become enabled
haha yes i know, add a space to the begging of that input box
omg
ok got it
your service name has a space at the begging too, this isnt a bug
see the extra underscore
okay re-pushing now
interesting, wonder how that got there
ah, now we're back to where we were
okay lets try something, make a requirements.txt file
ok trying that
ok we got past that error, something different now likely related to missing ENV vars
for the SqlAlchemy DB connection
one interesting thing flashed in deploy logs that might be the culprit, one second
is your database hosted on railway in the same project?
yes
dont worry about that right now
show me a screenshot of your service variables please
use variable references that arent shared please
okay, trying to unshare
nice, looks like its all back up
for a sanity check, mind sharing another service variables screenshot?
do you suspect the shared variables weren't working right?
you can remove the port variable btw
okay so now everything works, right?
yes
I'm still confused about the requirements.txt
and why that's needed
no clue
seems like I might need to switch to poetry or read up on that issue
looks like Pip had a breaking change
but we still have one more thing to do
run gunicorn and huey with parallel
ah
I didn't realize that was an option
anything is possible if you know your way around nixpacks
any docs I can look at?
no need, i am docs, one sec
nixpacks.toml
railway.json
you know what to do
okay awesome
thank you!
really appreciate the help. Do you work for Railway?
for a tiny explnation on parallel: run gunicorn and huey in parallel, this will fail fast if either service crashes allowing railway to restart the deployment
i do not
wow, well thank you so much either way
anything I can do for you? venmo you a coffee or something?
if you absolutely insist, i have a buymeacoffee in my bio, please dont feel obligated, i dont do this expecting anything in return
oh I insist, you have some coffee coming your way. Thank you again!
i set it to trains 🤣
all running with parallel now?
yes!
it worked on the first try
I'm gonna try to debug this pip issue later
sounds good!
might be good to have a read of this page as well
https://nixpacks.com/docs/providers/python