R
Railway2y ago
Jed

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

Can you please help me?
104 Replies
Percy
Percy2y ago
Project ID: N/A
Jed
JedOP2y ago
N/A
Jed
JedOP2y ago
Jed
JedOP2y ago
this is the main script that I am running, i am trying to make a crypto screener dashboard this is the github:
Jed
JedOP2y ago
GitHub
GitHub - Vasallius/momo-flask
Contribute to Vasallius/momo-flask development by creating an account on GitHub.
Jed
JedOP2y ago
i have tried consulting gpt-4 and have found no success
Brody
Brody2y ago
you wont find any success here either if you cant provide us with any errors lol
Jed
JedOP2y 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
JedOP2y ago
Jed
JedOP2y ago
Jed
JedOP2y ago
Jed
JedOP2y ago
that is why im a bit confused do you kind of understand the problem
Brody
Brody2y ago
please don't tag me like that
Jed
JedOP2y ago
oh i am sorry
Brody
Brody2y ago
please delete the gunicorn_config.py file
Jed
JedOP2y ago
okay okay will do and will push gimme a sec
Brody
Brody2y ago
wait hold your horses
Jed
JedOP2y 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
JedOP2y ago
Jed
JedOP2y ago
that's interesting, im assuming there is a key error because the "data_df" is not filled
Brody
Brody2y 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
JedOP2y ago
alright hang on
Brody
Brody2y ago
no rush, just make sure you follow the instructions carefully
Jed
JedOP2y ago
did you mean line 147 of test.py
Jed
JedOP2y ago
that is what i am running
Jed
JedOP2y ago
alright, pushed the changes! redeploying now
Brody
Brody2y 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
JedOP2y 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
Brody2y ago
no, please slow down and listen to what I'm saying
Jed
JedOP2y 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
Brody2y ago
and the port variable is removed from the service?
Jed
JedOP2y ago
yup!
Brody
Brody2y ago
and the start command is empty?
Jed
JedOP2y ago
yup!
Brody
Brody2y ago
okay, push
Jed
JedOP2y ago
gotcha
Brody
Brody2y 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
JedOP2y ago
build and deploy succeeded trying the website now
Brody
Brody2y ago
any panda errors?
Jed
JedOP2y ago
metrics are spiking
Jed
JedOP2y ago
Jed
JedOP2y ago
none but i have this
Jed
JedOP2y ago
Jed
JedOP2y ago
normally in local my script takes 40 seconds to run (10 threads)
Brody
Brody2y ago
40 seconds is a long time, are you sure it should be taking 40 seconds?
Jed
JedOP2y ago
before without multithreading it takes 3-4 minutes
Brody
Brody2y ago
what are you doing that took 3-4 minutes???
Jed
JedOP2y 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
Brody2y 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
JedOP2y ago
but it's a lot of data like a lot
Brody
Brody2y ago
100 rows?
Jed
JedOP2y ago
440 symbols 100 rows each 44000 rows total then u do calculation on those rows
Brody
Brody2y ago
okay that's a lot and you are perfectly okay with your app takeing 40 seconds to load?
Jed
JedOP2y ago
well normally i shud bind it to a button like press button -> wait 40 seconds -> spit out data
Brody
Brody2y 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
JedOP2y ago
yup 40 seconds is good enough
Brody
Brody2y 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
JedOP2y ago
ok ok btw when i run the script locally this is what it looks like
Jed
JedOP2y ago
Brody
Brody2y ago
40 seconds of processing for that lol
Jed
JedOP2y ago
yupp it tells me what assets to buy carefully filtering over 400 symbols
Brody
Brody2y ago
you're on trail plan?
Jed
JedOP2y ago
yess considering to upgrade ngl if that will fix my issues
Brody
Brody2y 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
JedOP2y ago
i get this sad
Jed
JedOP2y ago
Brody
Brody2y ago
any errors in the logs?
Jed
JedOP2y ago
Jed
JedOP2y 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
Brody2y ago
dev plan!!!! though I make no promises
Jed
JedOP2y ago
hm is that 5 usd?
Brody
Brody2y ago
no railway gives you 5$ a month
Jed
JedOP2y ago
ah how much is that dev plan then
Brody
Brody2y ago
and you only pay if your usage costs exceed the initial 5$
Jed
JedOP2y ago
ohhh
Brody
Brody2y 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
JedOP2y 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
Brody2y ago
run your python app on your own computer?
Jed
JedOP2y ago
Yupp But people can access the website
Brody
Brody2y 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
JedOP2y ago
Rip ok ok Nvm ty
Brody
Brody2y ago
no problem
Jed
JedOP2y ago
just upgraded
Jed
JedOP2y ago
let's see what will happen
Brody
Brody2y ago
yay congrats
Jed
JedOP2y ago
hope this fixes my problem T_T
Brody
Brody2y ago
hopefully
Jed
JedOP2y 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
Brody2y ago
i dont understand the question, sorry
Jed
JedOP2y 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
Brody2y ago
oh, then yes
Jed
JedOP2y ago
so where is railway server located
Jed
JedOP2y ago
sorry how do i use this
Brody
Brody2y ago
read it
Jed
JedOP2y ago
Jed
JedOP2y ago
i mean i dont know what those are
Brody
Brody2y ago
you dont know your railway domain???
Jed
JedOP2y ago
oh i put my app url there ok ok
Brody
Brody2y ago
put it in the input box and press the button
Jed
JedOP2y ago
Jed
JedOP2y ago
yep yep gotcha so us-west1 is there a way to change that? and make it asia or smth
Brody
Brody2y ago
there is not multi region is coming soon
Jed
JedOP2y ago
ok ok thank you
Want results from more Discord servers?
Add your server