R
Railway9mo ago
drdrigg

Access rails console and run rake tasks?

Is it possible to run rake tasks on the server here at Railway? And even perhaps possible to access the rails console on the server? Project ID: 988851b6-78d5-44de-a73d-3e5b6468c8bf
51 Replies
Percy
Percy9mo ago
Project ID: 988851b6-78d5-44de-a73d-3e5b6468c8bf
Brody
Brody9mo ago
it's not, but if you're just using it to interact with your database, you can run it within the railway shell (local shell with railway environment variables)
drdrigg
drdrigg9mo ago
ok interesting! But how can I run rake tasks?
Brody
Brody9mo ago
what do these tasks do? if they just interact with the database then you can run them locally
drdrigg
drdrigg9mo ago
Basically different maintainance tasks. Like checking all accounts that are too old and then remove them. Or changing a lot of records at once. Things like that.
Brody
Brody9mo ago
yeah that sounds like just interacting with the database
drdrigg
drdrigg9mo ago
Yes basically, but using a rake task
Brody
Brody9mo ago
you should have no problem using the rails console from within railway shell
drdrigg
drdrigg9mo ago
So how do I access the railway shell?
Brody
Brody9mo ago
oh mb, here's the docs for the cli https://docs.railway.app/develop/cli
drdrigg
drdrigg9mo ago
railway shell No service linked, not entering shell. I first ran railway link
Brody
Brody9mo ago
run railway service
drdrigg
drdrigg9mo ago
And selected a team and a project Entering subshell with Railway variables available. Type 'exit' to exit. N/A: version "N/A -> N/A" is not yet installed. You need to run "nvm install N/A" to install it before using it.
Brody
Brody9mo ago
what's N/A supposed to mean
drdrigg
drdrigg9mo ago
No idea 🙂 I tried both the Rails service and the Postgres service Both have the same error
Brody
Brody9mo ago
screenshot please
drdrigg
drdrigg9mo ago
No description
Brody
Brody9mo ago
what OS and terminal is this?
drdrigg
drdrigg9mo ago
MacOs Default terminal MacOS 13.3.1 (22E261) Ventura
Brody
Brody9mo ago
going to tag in @alex for this, could you try to repro this when you have the time?
drdrigg
drdrigg9mo ago
oki Thanks
alex
alex9mo ago
No pgsql installed on his computer Weird bug being thrown by the cli tho
Brody
Brody9mo ago
they only ran railway shellthough, what does pgsql have to do with that?
alex
alex9mo ago
Maybe I’ll peep the cli code later Rn I’m sick Like hella sick
Brody
Brody9mo ago
get well soon <$
alex
alex9mo ago
Like two boxes of tissues nod
macwilko
macwilko9mo ago
idk if this is helpful @drdrigg but I use the Rails console like this:
railway run env SSL_CA_PATH="/etc/ssl/cert.pem" rails c
railway run env SSL_CA_PATH="/etc/ssl/cert.pem" rails c
note, all this does is run yor rails app with env variables pulled from your Railway instance
drdrigg
drdrigg9mo ago
Thank you! BTW, have you experienced any performance issues with you rails app on Railway? I get 480 ms response time on average on Railway but for the same request/endpoint on a regular VPS only 70 ms. Both Railway and VPS is in Amsterdam.
macwilko
macwilko9mo ago
@drdrigg hmm, I do have slow response times, but I haven't determined if that's Railway or my bad coding.
drdrigg
drdrigg9mo ago
Do you also use Postgres?
macwilko
macwilko9mo ago
MySQL Where is your database located? I believe by default Railway is us-west if you can do any tests confirming slow speed on Railway, I'de like to know it I just have some performance issues but mostly I figured it was due to N+1 queiries
drdrigg
drdrigg9mo ago
My main rails server, postgres and redis is located in Amsterdam, Europe.
macwilko
macwilko9mo ago
wow so literally just running the rails app on Railway vs VPS, you're getting that much additional latancy is it a Dockerfile you're running?
drdrigg
drdrigg9mo ago
Yes, I am using a Dockerfile and yes, same code and same user and same data. Which is frustrating because I really want to use Railway for my rails app.
macwilko
macwilko9mo ago
yeah... man I should probably do some tests to compare myself which VPS are you using have you tried Fly.io ?
drdrigg
drdrigg9mo ago
I am using Vultr.com. I tried fly.io but Railway is vastly superior
macwilko
macwilko9mo ago
Right why do you want to move from Vultr to Railway? curious
drdrigg
drdrigg9mo ago
I love Railways interface, innovations and the overall flow of everything How all is kept together. I am using Cloud66.com to handle the servers (I know very little about servers)
macwilko
macwilko9mo ago
gotcha... i mean, railway for me is super easy to run and administer as an individual. So perhaps it's not the fastest solution, but as a 1 man startup, I run everything here and it works fine.
drdrigg
drdrigg9mo ago
Also I could get $250 down to like $25 which is quite nice to 🙂
macwilko
macwilko9mo ago
but if you're scaling up, and need performance, it might not be the fastest
drdrigg
drdrigg9mo ago
Its fast for my ExpressJS / NextJS project. Rails is a bit legacy now (at least in the hosting world, very hard to find good hosting).
macwilko
macwilko9mo ago
hmm, have you spoken to anyway at Railway about this? I have a call booked with Angelo tomorrow, I can bring it up I am not an expert enough to know where the issue could be you're on the Pro plan so I expect you can talk to the Railway engineers here's my app it's a Rails backend / graphql API you can see loading a chat conversation is pretty slow bare in mind, it's hosted in us-west, database is also in us-west. I am located in UK.
macwilko
macwilko9mo ago
macwilko
macwilko9mo ago
the data behind this app is as complex as any SaaS you'll find I imagine i really would like it to be faster but I don't have much resources to spend on optimising it just yet 😦 I have features needing to be built presently.
drdrigg
drdrigg9mo ago
This is exactly what I am experincing. Very slow, even in Postman. Great app BTW, looks very nice! Have you tried moving the app to the EU cloud? Its very simple now with the new location setting
macwilko
macwilko9mo ago
I would, but all my customers are in the US I’m hoping multi regional services are a thing soon, which sounds like it might be If you can send anything to me at matt@zenshop.app I’ll bring it up on my call tomorrow with Angelo I’m keen to have faster performance also Thanks!! Rails isn’t dead yet 👌⭐️
macwilko
macwilko9mo ago
No description
macwilko
macwilko9mo ago
My response time processing webhooks is pretty fast But those don’t touch the database layer much I wonder if it’s due to some slow connection between the database and the service Have you tried testing using Railway Postgres?
drdrigg
drdrigg9mo ago
I am only using Railway services, Rails app, Redis service template and Postgres service template. I also tried both connecting to database using "public" url and using "private" direct url. Same result.
macwilko
macwilko9mo ago
ok good to know have you got any tests / numbers to share at all? since we're both running Rails apps, and both on Pro plan maybe worth talking together to Railway team also, can you try test hitting a route on the rails app that doesn't call out to your Database?