How to reconnect automatically to restarted mongo db from a rails app? - ruby-on-rails

I created an index for a collection in mongo db using scalegrid. After successfully creating the index, I get "not authorised for query on db" error when logging into the rails app running on kubernetes. When I restart the corresponding pod manually, I am able to login again.
Does anyone know how is it possible to reconnect to the restarted mongo db automatically from the app?
Would updating mongoid or any other gem help here?

Related

PG::ConnectionBad Sidekiq could not translate host name

We are getting a lot of sentries issue with PG:ConnectionBad on Postgres in RDS AWS and Ruby on Rails
PG::ConnectionBad Sidekiq/BookingExtensionCheckWorker
could not translate host name “ls-XXXXXXXXXXXXfee44.XXXXXXXXX.eu-west-1.rds.amazonaws.com” to address: Name or service not known
In two weeks ago, we have migrate a new database and we change endpoint in the RoR files api
new database endpoint,
ls-XXXXXXXXXXXXXXXf3d4a.XXXXXXXX.eu-west-1.rds.amazonaws.com
It working fine with no issue between the new database and Ruby on Rails api. however, I get a lot of sentries issue said that sidekiq having an issue with connection database as they use old database address which it’s no longer used. I have to check sidekiq database; the code shows it’s connected to the new database. They keep go back to the old database when I run Ruby on rails.
Is there some way to find why sidekiq keep connection old database
Sidekiq is background service. So when someone deployed he has used some sort of like. Right now you are getting issue you think is fine but actually most jobs are not running. Which you will noticed in few days.
How can you check jobs If you sidekiq setup. Probably following url will lead to all jobs.
your_url/sidekiq
It will show you all jobs, I think you have option here to restart services. Just click to restart sidekiq. And everything would be fine.
How to start
As your sidekiq running with old configuration. So following steps could be dangrous, I think you must check how you have started your process. Otherwise following are some way people configure it and runt it.
systemctl restart sidekiq
If this does not work, check your command your deployment guy has setup some sort of scripts inside /etc/init.d folder
Some time developer use following simple line to run sidekiq
bundle exec sidekiq -d -P tmp/sidekiq.pid -L log/sidekiq.log
or
bundle exec sidekiqctl stop

Connecting Rails to AWS MySQL database

I've recently created a rails app. I pushed the initial files onto github.
My problem is that I want to connect my rails app to AWS in order to use a MySQL database. I keep seeing tutorials on EC2 and Beanstalk, but I am not sure which one I should use. I have all the drivers needed for ruby through the gem installations.
I'm looking to figure out the main differences between Beanstalk and created a MySQL instance as well as what to put in my database.yml file in my rails app to connect to a database. Thank you in advance!
Just to give an idea, after you provision/create your instance on AWS (EC2 or wherever), you will then push your app's code to that remote server somewhere. You can do it manually via scripts, or you can use Capistrano for this. Once your app is deployed to the server, you need to connect to the server via SSH and manually edit the config/database.yml file to point to the staging/production MySQL database. (I'm generalizing, but I think you just need a step in the right direction.)

Pulling down from github, unable to work locally with postgreSQL

I cloned a repository in a RoR app using postgres but I'm unable to work locally. When I run the server I get this error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I've tried many things: the password reset doesn't work because it's not recognizing as a user...I've tried adding the underscore before postgres user...sudo su doesn't work...help!
Ok, so after shuffling through the google return links for the original error message, I came across this: http://www.brentmc79.com/posts/psql-could-not-connect-oh-fuck-you
Very straightforward list of commands that shut down the database, force a reset, and then a manual restart...it will also return prompts that you'll get. Very helpful. I'm getting a CSS error now, but it looks like the database setup is ok. Thanks!

Sybase SqlAnywhere 12 connection hangs after first connection attempt is successful

I'm experiencing what I believe is an environment issue, but I'm at my end as far as debugging it. I'm attempting to connect to a Sybase SqlAnywhere from a Rails 3.2.13 app on the same network. This is working from a rails 2.8 app, but I desperately need to upgrade.
It seems that I can connect through the rails console to the database the very first time that I create my new ruby gem and gemset using RVM, but subsequent attempts simply hang with no response after an attempt to query the database. I believe the database connection is being established as I get an error when incorrect credentials are supplied. After a successful connection on the first attempt, I am unable to replicate the success by opening a new terminal tab, setting the same gem and gemset, sourcing the database, and issuing the same query in the rails console.
I'm using a rails32 branch of a fork of the sqlanywhere adapter since the database adapter hasn't been supported by Sybase for a little while, but it has reported success using the same setup and I don't think this is the root of my issue since I've successfully returned valid data in the trials with limited success.
I've compared the working and non-working environments with no apparent difference, but is there anything significantly different about the RVM environment after the initialization of the gem/gemset that could be getting in the way?

Rails app won't connect to PostgreSQL

I'm coming from the PHP/MySQL world, trying to set up a Rails/PostgreSQL app. It doesn't seem to want to connect and I'm having a hard time pinning down the cause of the problem. Are there certain troubleshooting steps I can take to figure out what's going wrong?
Update: the problem is not with PostgreSQL. I can connect to PostgreSQL via the command line, remotely via an IDE, and via a PHP script. I just can't seem to connect to it through this Rails app.
First I'd start with the actual database.yml file to make sure i have all the right user and password information.
I'd also make sure i ran whatever it is you do to make postgres start it's server, so that connections can be established. (Whether you use a psql start or it starts when you start your dev env. So only you can answer that one).
Is the database created?
Can i connect through console? rails console shouldn't give an error.
Do you have the correct postgres gem installed and is that in your bundle file (or environment.rb file)?

Resources