rufus + puma + heroku warning - ruby-on-rails

I'm running a rails app on heroku, I have two web dynos.
How can I remove the ! WARNING: Detected 1 Thread(s) started in app boot: warning?
My puma.rb file:
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do |worker_number|
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
The logs:
2016-09-03T14:21:24.742960+00:00 app[web.1]: [3] * Listening on tcp://0.0.0.0:53786
2016-09-03T14:21:24.743135+00:00 app[web.1]: [3] ! WARNING: Detected 1 Thread(s) started in app boot:
2016-09-03T14:21:24.743181+00:00 app[web.1]: [3] ! #<Thread:0x007f382b59fca8#/app/vendor/bundle/ruby/2.2.0/gems/rufus-scheduler-3.2.2/lib/rufus/scheduler.rb:563 sleep> - /app/vendor/bundle/ruby/2.2.0/gems/rufus-scheduler-3.2.2/lib/rufus/scheduler.rb:571:in `sleep'
2016-09-03T14:21:24.743257+00:00 app[web.1]: [3] Use Ctrl-C to stop
2016-09-03T14:21:24.754941+00:00 app[web.1]: [3] - Worker 0 (pid: 7) booted, phase: 0
2016-09-03T14:21:24.756269+00:00 app[web.1]: [3] - Worker 1 (pid: 20) booted, phase: 0
2016-09-03T14:21:25.525174+00:00 app[web.2]: ** [NewRelic][2016-09-03 14:21:25 +0000 web.2 (18)] INFO : Doing deferred dependency-detection before Rack startup

It's very easy. Stop using rufus-scheduler. It's using threads, that's what is causing your warning.
Look at:
2016-09-03T14:21:24.743181+00:00 app[web.1]: [3] !
<Thread:0x007f382b59fca8#
/app/vendor/bundle/ruby/2.2.0/gems/rufus-scheduler-3.2.2/lib/rufus/scheduler.rb:563
sleep> -
/app/vendor/bundle/ruby/2.2.0/gems/rufus-scheduler-3.2.2/lib/rufus/scheduler.rb:571
:in `sleep'
Rufus-scheduler clearly is the cause of the warning.
Cf https://github.com/jmettraux/rufus-scheduler/issues/213
Now there is another way to look at the thing: the warning is not emitted by rufus-scheduler, it's emitted by Puma. There's probably a way to disable the warning, but that's a question for people with knowledge of Puma.

Related

Heroku - Rails app gives 'No such app' when everything seems right

I have a new, Rails 6 app that I'm trying to deploy to Heroku.
Judging from the deploy log and the logs I'm getting with heroku logs --tail everything seems to work, but when I go to the deployed, herokuapp.com domain, I get the 'No such app' screen.
Here is the latest logs:
2021-11-19T13:45:11.000000+00:00 app[api]: Build succeeded
2021-11-19T13:45:11.060793+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2021-11-19T13:45:12.126085+00:00 app[web.1]: [4] Puma starting in cluster mode...
2021-11-19T13:45:12.126103+00:00 app[web.1]: [4] * Puma version: 5.5.2 (ruby 3.0.2-p107) ("Zawgyi")
2021-11-19T13:45:12.126103+00:00 app[web.1]: [4] * Min threads: 5
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Max threads: 5
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Environment: production
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Master PID: 4
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Workers: 2
2021-11-19T13:45:12.126127+00:00 app[web.1]: [4] * Restarts: (✔) hot (✖) phased
2021-11-19T13:45:12.126133+00:00 app[web.1]: [4] * Preloading application
2021-11-19T13:45:13.203269+00:00 app[web.1]: [4] * Listening on http://0.0.0.0:54150
2021-11-19T13:45:13.203334+00:00 app[web.1]: [4] Use Ctrl-C to stop
2021-11-19T13:45:13.207647+00:00 app[web.1]: [4] - Worker 0 (PID: 7) booted in 0.0s, phase: 0
2021-11-19T13:45:13.209455+00:00 app[web.1]: [4] - Worker 1 (PID: 9) booted in 0.0s, phase: 0
2021-11-19T13:45:13.336382+00:00 heroku[web.1]: State changed from starting to up
And here's the puma config:
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
Which is the one recommended by Heroku in their documentation.
The Procfile is a simple one-liner:
web: bundle exec puma -C config/puma.rb
I also tried the heroku configuration by running PORT=3000 heroku local on my machine and it works wonderfully, but not on Heroku's platform :(
I'm using Rails 6.1.4.1 and ruby 3.0.2
Can you point me at where I could try to find the root of the problem?
Thank you,
Balint
This seems to have been a transient issue. When I came back to the problem a few hours later, it just worked without me having to change anything.

Sidekiq job enqueued but not processing on Heroku

Rails 5.2
redis 4.0.1
sidekiq 5.1.3
RedisToGo on Heroku
Proc File:
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
sidekiq.yml
development:
:concurrency: 5
production:
:concurrency: 6
:queues:
- default
config/initialize/sidekiq.rb
if Rails.env.production?
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDISTOGO_URL'] || ENV['REDIS_URL'], size: 1 }
end
Sidekiq.configure_server do |config|
pool_size = ENV['SIDEKIQ_DB_POOL'] || (Sidekiq.options[:concurrency] + 2)
config.redis = { url: ENV['REDISTOGO_URL'] || ENV['REDIS_URL'], size: pool_size }
Rails.application.config.after_initialize do
Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('#size')}")
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
db_config = Rails.application.config.database_configuration[Rails.env]
db_config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
db_config['pool'] = pool_size
ActiveRecord::Base.establish_connection(db_config)
Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('#size')}")
end
end
end
end
I have no idea why the job is stuck in the queue. The job works on my local in development.
Any assistance appreciated.
Update!
As per the comment here is the output of heroku ps:
=== web (Free): bundle exec puma -C config/puma.rb (1)
web.1: up 2018/06/15 18:49:56 +0700 (~ 5s ago)
=== worker (Free): bundle exec sidekiq -q default (1)
worker.1: crashed 2018/06/15 18:49:51 +0700 (~ 10s ago)
Seems a worker crashed for some reason.
Heroku logs:
2018-06-15T11:56:00.301716+00:00 app[web.1]: [4] Puma starting in cluster mode...
2018-06-15T11:56:00.301740+00:00 app[web.1]: [4] * Version 3.11.2 (ruby 2.4.1-p111), codename: Love Song
2018-06-15T11:56:00.301760+00:00 app[web.1]: [4] * Min threads: 5, max threads: 5
2018-06-15T11:56:00.301794+00:00 app[web.1]: [4] * Environment: production
2018-06-15T11:56:00.301801+00:00 app[web.1]: [4] * Process workers: 2
2018-06-15T11:56:00.301838+00:00 app[web.1]: [4] * Preloading application
2018-06-15T11:56:01.249511+00:00 app[worker.1]: DB Connection Pool size for Sidekiq Server before disconnect is: 5
2018-06-15T11:56:01.252654+00:00 app[worker.1]: could not connect to server: No such file or directory
2018-06-15T11:56:01.252657+00:00 app[worker.1]: Is the server running locally and accepting
2018-06-15T11:56:01.252659+00:00 app[worker.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
After talking with tech support at Heroku it turns out that I needed to change the way I had my db yaml file coded.
I changed it to the following:
production:
url: <%= ENV['DATABASE_URL'] %>
That seem to solve the issue.
Install Heroku Postgres as an addon and then add the environment variables to your project and everything should work fine. - https://elements.heroku.com/addons/heroku-postgresql

Can't figure out why worker doesn't function Heroku

I have been looking at my Heroku logs and I just can't figure out why my woker is not functioning. It works locally and when I do heroku run rake perform_later I get a response that my job is enqueued
Heroku logs
2016-02-09T20:02:04.364227+00:00 heroku[scheduler.2066]: State changed from up to complete
2016-02-09T20:02:04.350705+00:00 heroku[scheduler.2066]: Process exited with status 0
2016-02-09T21:00:57.182878+00:00 heroku[api]: Starting process with command `bundle exec rake perform_later` by scheduler#addons.heroku.com
2016-02-09T21:01:04.063903+00:00 heroku[scheduler.9121]: Starting process with command `bundle exec rake perform_later`
2016-02-09T21:01:04.681867+00:00 heroku[scheduler.9121]: State changed from starting to up
2016-02-09T21:01:07.923640+00:00 app[scheduler.9121]: [Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
2016-02-09T21:01:07.965160+00:00 app[scheduler.9121]: [ActiveJob] Enqueued GettweetsJob (Job ID: d3363b17-a2f9-4ffd-85b7-a5188b89605d) to Sidekiq(default)
2016-02-09T21:01:08.614883+00:00 heroku[scheduler.9121]: Process exited with status 0
2016-02-09T21:01:08.611923+00:00 heroku[scheduler.9121]: State changed from up to complete
2016-02-09T21:24:48.087768+00:00 heroku[web.1]: State changed from down to starting
2016-02-09T21:24:48.087325+00:00 heroku[web.1]: Unidling
2016-02-09T21:24:51.847314+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2016-02-09T21:24:53.513605+00:00 app[web.1]: [3] Puma starting in cluster mode...
2016-02-09T21:24:53.513625+00:00 app[web.1]: [3] * Version 2.15.3 (ruby 2.2.3-p173), codename: Autumn Arbor Airbrush
2016-02-09T21:24:53.513627+00:00 app[web.1]: [3] * Environment: production
2016-02-09T21:24:53.513663+00:00 app[web.1]: [3] * Preloading application
2016-02-09T21:24:53.513626+00:00 app[web.1]: [3] * Min threads: 3, max threads: 3
2016-02-09T21:24:53.513628+00:00 app[web.1]: [3] * Process workers: 2
2016-02-09T21:24:55.539022+00:00 app[web.1]: [3] * Listening on tcp://0.0.0.0:23385
2016-02-09T21:24:55.539160+00:00 app[web.1]: [3] Use Ctrl-C to stop
2016-02-09T21:24:55.544071+00:00 app[web.1]: [3] - Worker 0 (pid: 6) booted, phase: 0
2016-02-09T21:24:55.520328+00:00 app[web.1]: [Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
2016-02-09T21:24:55.545450+00:00 app[web.1]: [3] - Worker 1 (pid: 10) booted, phase: 0
2016-02-09T21:24:56.075839+00:00 heroku[web.1]: State changed from starting to up
Job
class GettweetsJob < ActiveJob::Base
queue_as :default
def perform(*args)
client = Twitter::REST::Client.new do |config|
config.consumer_key = "aaaa"
config.consumer_secret = "bbbb"
config.access_token = "cccc"
config.access_token_secret = "dddd"
end
client.mentions_timeline.each do |tweet|
Tweet.create({text: tweet.text, username: tweet.user.screen_name})
end
end
end
rake task
desc "This task is called by the Heroku scheduler add-on"
task :perform_later => :environment do
GettweetsJob.perform_later
end
response heroku run rake perform_later
[Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
[ActiveJob] Enqueued GettweetsJob (Job ID: 5f71c5e3-f2f3-4c5d-8396-1eb5cb25068b) to Sidekiq(default)
procfile
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -C config/sidekiq.yml
sidekiq.yml
:concurrency: 3
:timeout: 60
:verbose: true
:queues:
- default
- mailers

Unable to run rails application on puma using ssl

I'm trying to run my rails app on puma in development environment on windows box. Without ssl the application works fine..
But when I try to configure ssl for puma, nothing happens. No error is generated in the log and the web page (https://localhost:3000/) says Secure Connection Failed. Below is the output from command line that shows the server started but nothing happened after that..
E:\ap01\dev\rmmi>foreman start -p 3000
17:19:31 web.1 | started with pid 3016
17:19:34 web.1 | *** SIGUSR2 not implemented, signal based restart unavailable!
17:19:34 web.1 | *** SIGUSR1 not implemented, signal based restart unavailable!
17:19:34 web.1 | *** SIGHUP not implemented, signal based logs reopening unavailable!
17:19:34 web.1 | Puma starting in single mode...
17:19:34 web.1 | * Version 2.11.2 (ruby 2.0.0-p353), codename: Intrepid Squirrel
17:19:34 web.1 | * Min threads: 5, max threads: 5
17:19:34 web.1 | * Environment: development
17:19:36 web.1 | * Listening on tcp://0.0.0.0:3000
17:19:36 web.1 | * Listening on ssl://127.0.0.1:3000?cert=E:/ap01/OpenSSL-Win32/bin/server.crt&key=E:/ap01/OpenSSL-Win32/bin/server.key
17:19:36 web.1 | Use Ctrl-C to stop
My config/puma.rb file is given below -
path_to_key="E:/ap01/OpenSSL-Win32/bin/server.key"
path_to_cert="E:/ap01/OpenSSL-Win32/bin/server.crt"
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
ssl_bind '127.0.0.1', '3000', { key: path_to_key, cert: path_to_cert }
on_worker_boot do
ActiveSupport.on_load(:active_record) do
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['MAX_THREADS'] || 5
ActiveRecord::Base.establish_connection(config)
end
end
The profile for foreman is given below -
web: bundle exec puma -p $PORT -C config/puma.rb
I've also set config.force_ssl = true in my apps config/application.rb file.
Could you please advise what I'm missing here or doing incorrectly ?. Any pointers will be appreciated
Thanks in Advance!
You aren't doing anything wrong. The browser doesn't trust your local certificate with your localhost, so it will give you a warning.
But you can bypass it using the "Advanced" option on the page (left side bottom) and click proceed to view the ssl version of your application.

Puma deployment issue with Heroku

I'm trying to deploy my application to Heroku using Puma. This is my first time using Puma, as this is my first attempt at a "production quality" application. I've added puma as described in the dev center but I'm running into a no method error once deployed. Here's my error from the logs: config/puma.rb:5:in _load_from': undefined method preload_app!' for #<Puma::Configuration::DSL:0x007f89e2686140> (NoMethodError)
I used the suggested configuration in my config\puma.rb:
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
as shown in the error above, it seems Heroku has a problem with the preload_app! command. I'm stuck and don't know where to go from here - I have a feeling I somehow miscreated the file - i.e. I just made a new file in my editor rather than from the command line.
This is how we set config/puma.rb up on Heroku using Rails 4.1.0
workers Integer(ENV['PUMA_WORKERS'] || 3)
threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 16)
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# worker specific setup
ActiveSupport.on_load(:active_record) do
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['MAX_THREADS'] || 16
ActiveRecord::Base.establish_connection(config)
end
end
We keep the workers and threads to a minimum (we are on the free plan).
When I restart our dyno, I get this output in the logs:
2015-03-.. app[web.1]: [3] Puma starting in cluster mode...
2015-03-... app[web.1]: [3] * Version 2.9.1 (ruby 2.1.5-p273), codename: Team High Five
2015-03-... app[web.1]: [3] * Min threads: 1, max threads: 3
2015-03-... app[web.1]: [3] * Environment: production
2015-03-... app[web.1]: [3] * Process workers: 2
2015-03-... app[web.1]: [3] * Preloading application

Resources