Heroku: Long running Rake task eventually crashes - heroku

I have a rake task I'm going to use only once, to import a massive CSV file.
heroku run:detached bundle exec rake owners:import
The rake task works ok locally. It runs for > 8 hours on Heroku, but eventually crashes. The task is not completed. Checking processes:
heroku ps
=== web (Standard-1X): bin/rails server -p $PORT -e $RAILS_ENV (1)
web.1: up 2018/01/09 22:52:22 +0000 (~ 10h ago)
=== worker (Standard-1X): bundle exec rake jobs:work (1)
worker.1: crashed 2018/01/10 09:19:05 +0000 (~ 28m ago)
The log does not give any information at all
> heroku logs --app mydemoapp --dyno run.8945
>
I have a 1x standard worker process, which I thought this would use automatically. Is that wrong? Do I set it to use the worker process myself somewhere?

Related

How to restart Sidekiq when running on Heroku?

I am running sidekiq in a worker on Heroku as follows:
bundle exec sidekiq -t 25 -e $RAILS_ENV -c 3
One of the operations uses more memory (>500mb) than the worker allows. After the job has completed, the memory still hasn't been released and I get these errors in the heroku rails log files:
2018-11-13T00:56:05.642142+00:00 heroku[sidekiq_worker.1]: Process running mem=646M(126.4%)
2018-11-13T00:56:05.642650+00:00 heroku[sidekiq_worker.1]: Error R14 (Memory quota exceeded)
Is there a way to automatically restart Sidekiq when the memory usage exceeds a certain amount?
Thanks!
have you tried to reduce memory fragmentations? here how you can do it in Heroku.
if that wasn't good enough you can use Heroku platform gem and periodically restart the sidekiq

Ruby daemons on Heroku

I'm trying to execute a ruby daemon framework-less app on Heroku, but it crash after trying to execute the worker:
heroku[worker.1]: State changed from crashed to starting
heroku[worker.1]: Starting process with command `bundle exec rake twitter:start`
heroku[worker.1]: State changed from starting to up
heroku[worker.1]: Process exited with status 0
heroku[worker.1]: State changed from up to crashed
The app basically collects data, through a bunch of APIs, and saves it on a remote MongoHQ instance.
The rake tasks are:
dir_path = File.expand_path('../', __FILE__)
namespace :twitter do
desc 'Start Twitter daemon'
task :start do
exec "#{dir_path}/bin/autana start"
end
...
end
The Procfile is very simple: worker: bundle exec rake twitter:start
The code that executes the daemon is the following:
#!/usr/bin/env ruby
require 'daemons'
require File.expand_path('../../lib/autana', __FILE__)
Daemons.run_proc('autana', multiple: true, no_pidfiles: true) do
client = Autana::Client::Twitter.new
client.collect
end
Any ideas?
Can you run it dynamically?
heroku run rake twitter:start
So, it was a MongoDB error. Data was not properly associated. After entering the console, and changed the document, everything worked as expected.

Node app in heroku runs locally but I cannot scale dynos

I'm trying to run a node app in heroku. Foreman works to run it locally, and it pushes to git without any errors. However, when I run heroku ps:scale web=1, it says there is no such type as web. My Procfile is just this line: web: node server.js, which I think should work to set the web type.
Does anyone know why this could be going wrong? Your help would be appreciated!
Here's a copy of the terminal...
jmm-2:supportEmail jamesmatheson$ foreman start
14:35:07 web.1 | started with pid 36298
14:35:08 web.1 | app is running on /removed port/
14:35:08 web.1 | database open
^CSIGINT received
14:35:09 system | sending SIGTERM to all processes
SIGTERM received
14:35:09 web.1 | exited with code 1
jmm-2:supportEmail jamesmatheson$ heroku ps:scale web=1
Scaling web dynos... failed
! No such type as web.
Specity --app APP_NAME (As given in My Apps in Heroku). Just answered same questions here:
Heroku Web Dyno failing

How Do I Run a Tweetstream Loop on Heroku?

I have a fairly simple Tweetstream listener built in a Sinatra app that I am trying to get running on Heroku. It gets up and running fine, but after about a minute I get the following error:
2012-12-04T06:23:31+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-12-04T06:23:31+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Here is, basically, what I'm running:
require 'sinatra'
client = TwitterListener.new
puts "starting Twitter listener..."
client.restart
require 'tweetstream'
class TwitterListener
def initialize
#client = TweetStream::Client.new
...
#events = Events.new
end
def restart
...
#client.follow(users) do |status|
#events.mention_artist?(status, artists)
#events.retweet_artist?(status, artists)
end
end
end
It's starting the streaming listener and if I tweet fast enough, it picks it up, but Heroku seems to time out during the tweetstream loop. How can I fix this?
So I manged to work this out myself.
When running something a long running process like Tweetstream (which uses Eventmachine, I believe) on Heroku, you must use a worker dyno. The web dyno with time out if a process doesn't complete in 60 seconds. That's why I was getting the R10 timeout error.
To change to a worker dyno I needed to adjust my Procfile from
web: bundle exec rackup config.ru -p $PORT
to
worker: bundle exec rackup config.ru -p $PORT
And then turn off the web process and turn on a worker process named 'worker'
> heroku ps:scale web=0 worker=1
Because I only need one dyno working at this point in the project.

How can I tell how many worker dynos I'm using on Heroku?

I'm using HireFireApp to autoscale my web and worker dynos on Heroku. However, when I navigate to the Resque app on my application it says
"0 of 46 Workers Working"
Does this mean that I'm using 46 worker dynos???
Update:
Running heroku ps shows:
web.1 up for 21m bundle exec thin start -p $PORT
worker.1 starting for 1s bundle exec rake resque:work QUEUE..
From the command line in your heroku app have a look at the output of
heroku ps
that will show you how many workers you are running.

Resources