R
Railway15mo ago
Jed

Code works locally, build and deploy succeeds, but ends with server error

Can you please help me?
104 Replies
Percy
Percy15mo ago
Project ID: N/A
Jed
Jed15mo ago
N/A
Jed
Jed15mo ago
Jed
Jed15mo ago
this is the main script that I am running, i am trying to make a crypto screener dashboard this is the github:
Jed
Jed15mo ago
GitHub
GitHub - Vasallius/momo-flask
Contribute to Vasallius/momo-flask development by creating an account on GitHub.
Jed
Jed15mo ago
i have tried consulting gpt-4 and have found no success
Brody
Brody15mo ago
you wont find any success here either if you cant provide us with any errors lol
Jed
Jed15mo ago
ah yes hang on let me provide some more context i will just redeploy since it already crahed so here is a proof that it does succeed
Jed
Jed15mo ago
Jed
Jed15mo ago
Jed
Jed15mo ago
Jed
Jed15mo ago
that is why im a bit confused do you kind of understand the problem
Brody
Brody15mo ago
please don't tag me like that
Jed
Jed15mo ago
oh i am sorry
Brody
Brody15mo ago
please delete the gunicorn_config.py file
Jed
Jed15mo ago
okay okay will do and will push gimme a sec
Brody
Brody15mo ago
wait hold your horses
Jed
Jed15mo ago
alright alright just wanna say that gunicorn_config.py was a chatgpt suggestion thinking i was getting timeout but i think my script runs fast enough to not get timeout'd oh wait deploy logs now have something:
Jed
Jed15mo ago
Jed
Jed15mo ago
that's interesting, im assuming there is a key error because the "data_df" is not filled
Brody
Brody15mo ago
delete the port variable in your service variables and instantly cancel the redeploy popup change line 40 of your main.py back to the original code from line 13 of https://github.com/railwayapp-templates/flask/blob/main/main.py after this is done we move onto the next error
Jed
Jed15mo ago
alright hang on
Brody
Brody15mo ago
no rush, just make sure you follow the instructions carefully
Jed
Jed15mo ago
did you mean line 147 of test.py
Jed
Jed15mo ago
that is what i am running
Jed
Jed15mo ago
alright, pushed the changes! redeploying now
Brody
Brody15mo ago
remove the start command, start command is defined in the Procfile, so if you want gunicorn to run your test.py file, delete the main.py and rename test.py to main.py and then yes in that case it would be like 147 that you'd need to change
Jed
Jed15mo ago
oh okay okay will do web: gunicorn test:server is this still the right Procfile ah nvm u told me to delete ok ok hang on
Brody
Brody15mo ago
no, please slow down and listen to what I'm saying
Jed
Jed15mo ago
sorry sorry okay i have followed the instructions and have deleted and rename test.py to main.py anything else before i push?
Brody
Brody15mo ago
and the port variable is removed from the service?
Jed
Jed15mo ago
yup!
Brody
Brody15mo ago
and the start command is empty?
Jed
Jed15mo ago
yup!
Brody
Brody15mo ago
okay, push
Jed
Jed15mo ago
gotcha
Brody
Brody15mo ago
now you'll probably still run into some errors with panda, but we needed to take care of that stuff before we can get to panda errors
Jed
Jed15mo ago
build and deploy succeeded trying the website now
Brody
Brody15mo ago
any panda errors?
Jed
Jed15mo ago
metrics are spiking
Jed
Jed15mo ago
Jed
Jed15mo ago
none but i have this
Jed
Jed15mo ago
Jed
Jed15mo ago
normally in local my script takes 40 seconds to run (10 threads)
Brody
Brody15mo ago
40 seconds is a long time, are you sure it should be taking 40 seconds?
Jed
Jed15mo ago
before without multithreading it takes 3-4 minutes
Brody
Brody15mo ago
what are you doing that took 3-4 minutes???
Jed
Jed15mo ago
well so to wlak u through the script there are a lot of cryptocurrency pairs each pair i api call to get data around 100 rows of data then process that data (add columns) derived from other columns then get the last 2 rows then add to a master df then do calculations on that master df
Brody
Brody15mo ago
even so 40 seconds is a long time, I know python isn't known to be the fastest but it's not that slow
Jed
Jed15mo ago
but it's a lot of data like a lot
Brody
Brody15mo ago
100 rows?
Jed
Jed15mo ago
440 symbols 100 rows each 44000 rows total then u do calculation on those rows
Brody
Brody15mo ago
okay that's a lot and you are perfectly okay with your app takeing 40 seconds to load?
Jed
Jed15mo ago
well normally i shud bind it to a button like press button -> wait 40 seconds -> spit out data
Brody
Brody15mo ago
well yes, but you'd still have to wait 40 seconds for data to be returned, and as long as your okay with that I can offer a possible solution
Jed
Jed15mo ago
yup 40 seconds is good enough
Brody
Brody15mo ago
change your Procfile to
web: gunicorn --timeout 600 main:server
web: gunicorn --timeout 600 main:server
gunicorn's default timeout is 30 seconds
Jed
Jed15mo ago
ok ok btw when i run the script locally this is what it looks like
Jed
Jed15mo ago
Brody
Brody15mo ago
40 seconds of processing for that lol
Jed
Jed15mo ago
yupp it tells me what assets to buy carefully filtering over 400 symbols
Brody
Brody15mo ago
you're on trail plan?
Jed
Jed15mo ago
yess considering to upgrade ngl if that will fix my issues
Brody
Brody15mo ago
well it wasn't even running before, but now that it's running your app might get killed if it tries to use more than 512mb of ram
Jed
Jed15mo ago
i get this sad
Jed
Jed15mo ago
Brody
Brody15mo ago
any errors in the logs?
Jed
Jed15mo ago
Jed
Jed15mo ago
key error just means that data_df wasn't populated meaning worker stopped before it had the chance to populate the df maybe? idk i just dont get why it's so hard to host it remotely when it works perfectly fine on local
Brody
Brody15mo ago
dev plan!!!! though I make no promises
Jed
Jed15mo ago
hm is that 5 usd?
Brody
Brody15mo ago
no railway gives you 5$ a month
Jed
Jed15mo ago
ah how much is that dev plan then
Brody
Brody15mo ago
and you only pay if your usage costs exceed the initial 5$
Jed
Jed15mo ago
ohhh
Brody
Brody15mo ago
it's based on usage, so if your usage stays under 5$ you can run your services for free but you are doing heavy compute so again, I make no promises
Jed
Jed15mo ago
i will try and check that out ty for the help one more thing is it possible i just run the thing locally and just use cron or smth
Brody
Brody15mo ago
run your python app on your own computer?
Jed
Jed15mo ago
Yupp But people can access the website
Brody
Brody15mo ago
you'd need to setup your own web server with the appropriate securities, setup port forwarding on your router, etc though I can't recommend you open any ports on your own network
Jed
Jed15mo ago
Rip ok ok Nvm ty
Brody
Brody15mo ago
no problem
Jed
Jed15mo ago
just upgraded
Jed
Jed15mo ago
let's see what will happen
Brody
Brody15mo ago
yay congrats
Jed
Jed15mo ago
hope this fixes my problem T_T
Brody
Brody15mo ago
hopefully
Jed
Jed15mo ago
hmm get the key error faster it is possible when railway runs the app, the api doesn't respond because the api block the specific location of railway server?
Brody
Brody15mo ago
i dont understand the question, sorry
Jed
Jed15mo ago
cause like binance api sometimes blocks requests depending on location i was wondering maybe that's the case since my dataframes aren't being populated
Brody
Brody15mo ago
oh, then yes
Jed
Jed15mo ago
so where is railway server located
Jed
Jed15mo ago
sorry how do i use this
Brody
Brody15mo ago
read it
Jed
Jed15mo ago
Jed
Jed15mo ago
i mean i dont know what those are
Brody
Brody15mo ago
you dont know your railway domain???
Jed
Jed15mo ago
oh i put my app url there ok ok
Brody
Brody15mo ago
put it in the input box and press the button
Jed
Jed15mo ago
Jed
Jed15mo ago
yep yep gotcha so us-west1 is there a way to change that? and make it asia or smth
Brody
Brody15mo ago
there is not multi region is coming soon
Jed
Jed15mo ago
ok ok thank you