How to clear all devise sessions? - heroku

Someone else asked this question while back here is the question
How can I reset all devise sessions so every user has to login again?
and the answer is this:
rake db:sessions:clear
However When I do it I get this error:
Don't know how to build task 'db:session:clear'
I tried doing this as well
~ $ heroku run bash
and then
~ $ rake db:sessions:clear
Still same error.
Any suggestions ?
tried these as well, still not working:
~ $ heroku run rake db:sessions:clear

If you are using session using client side cookies, you can simply restart your server as session ids are stored in memory in that case.

def index
reset_session
end

Related

Permanently switching user in Capistrano 3 (separate authorization & deploy)

We have following pattern in server management - all users do have their own user, but deploy is fully performed by special deploy user, without direct login possibility.
We used this method in Capistrano 2.x:
default_run_options[:shell] = "sudo -u deploy bash"
$ cap stage deploy -s user=thisisme
I'm aware that Capistrano 3.x has method to switch user directly:
task :install do
on roles(:all) do
as :deploy do
execute :whoami
end
end
end
But this code will fill all tasks, and default tasks will not inherit deploy user anyway. Is it ever possible to set up login user directly without dragging this code to each task?
Since I had received no proper answer and didn't got the idea myself, I decided to ask authors. Capistrano 3.x uses SSHKit to manage remote execution commands, and here's their answer:
You could try overriding the command map such that every command gets prefixed with the desired sudo string. https://github.com/capistrano/sshkit/blob/master/README.md#the-command-map
SSHKit.config.command_map = Hash.new do |hash, command|
hash[command] = "<<sudo stuff goes here>> #{command}"
end
The documentation says "this may not be wise, but it would be possible". YMMV

Stuck on heroku setup page for ruby

https://devcenter.heroku.com/articles/getting-started-with-ruby#web-rb
I'm stuck at the "write your app" part. It gives a hello world example, so I tried doing that with vim:
The web.rb file reads as follows.
require 'sinatra'
get '/' do
"hello, world"
end
But, when I try and do: heroku addons:add newrelic:stark --app web.rb,
it says failed. app not found.
I'm probably missing something "obvious" because I've actually never worked with Heroku and hardly any Ruby before. Any help would be really appreciated.
If you're at "Write Your App", you haven't created a Heroku application yet, you've only just started writing the code for it.
Adding the newrelic add-on to a non-existent heroku app would likely give you that error.
Don't get ahead of yourself, finish the tutorial on creating the Heroku application before trying to add things to it.

How can I get Heroku's database information in a ruby script?

I created a rails app that is hosted on Heroku. Now I want to upload a ruby script that will populate my database.
This script already exists and is using
PGconn.connect( :hostaddr=>"127.0.0.1", :port=>5432, :dbname=>"myDB", :user=>"MyUser", :password=>'MyPass');
This will obviously not work on Heroku.
I tried to get it using:
Rails.configuration.database_configuration
But I get
uninitialized constant Rails
How can I get the information so I can connect to my Heroku DB? Is there any way to make the same code wotk both on my localhost and on Heroku?
(ps: I am using foreman and the .ENV file, if it helps)
Edit:
The solution I took:
require 'yaml'
require 'erb'
config = YAML.load(ERB.new(File.read(File.join("config","database.yml"))).result)
In config I have all the information I need to perform the DB access.
Why would you not just access ENV['DATABASE_URL'] and break it up into the constituent parts? To see how this is done, if you do heroku run bash and do cat config\database.yml you will see how Heroku does this itself.
To ensure that locally it works as well if you execute via foreman run <Scriptname> then it will be executed and the contents of your .env will be loaded.

How to use Heroku-Scheduler

I've recently installed https://addons.heroku.com/scheduler in my heroku app, but I just cannot make any instruction get to work.
I think I don't know the correct syntax, for now I've tried with heroku pgbackups:capture --expire --app running-app command and selected frequency 10 mins.
It's been more than an hour and still hasn't done anything.
How can I get this to work?
Thanks
EDIT: This command is an example command, nor that I want to use that one specifically
You should be using the pgbackups addon, https://addons.heroku.com/pgbackups which is scheduled for you based on the level you pick.
Heroku Scheduler is more for if you need to run a rack task within your application codebase.
UPDATE BASED ON REVISED QUESTION:
You would write a rake task (assuming your using Rails?) which you could run locally using rake taskname and to schedule it on Heroku you would enter rake taskname as the command in the scheduler page for them to execute it.

How to print debug messages with Sinatra/Foreman?

I'm just starting out with Ruby and with the sinatra framework. I've got a setup going now with heroku and I'm totally amazed how well it works. There is just one thing that I can't figure out. How do I debug stuff? Might sound weird but I have this variable that I'd like to print out and see, preferably in the terminal or something like that. How do I do this in ruby with forman running? When I write print or puts nothing shows upp in the foreman logging...
Thanks!
If you're using Foreman, try adding a log: process to your Procfile. For Rails apps, my Procfile looks like so:
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
log: tail -f -n 0 log/development.log
You'll want to configure Sinatra to log to a file, in my example log/development.log.
Locally, Foreman will automatically spin up a log process and spit the logs out to the terminal, similar to how what you see on Heroku. On Heroku, no log process will be ran unless you manually scale it (which you don't want anyway).

Resources