Using Dokku with Resque - resque

Does anyone have experience using resque with dokku?
I've been searching all over and cannot figure out how to setup:
- my Procfile
- the connection between my app and the redis server (I've found the dokku-redis plugin for dokku)
Any pointers would be much appreciated!

First, link the redis service to your app:
dokku redis:link SERVICE_NAME APP_NAME
Next, add an entry to your procfile like so:
resque: env TERM_CHILD=1 bundle exec rake resque:work
Finally, scale up your resque workers:
dokku ps:scale APP_NAME resque=1

Related

Where's Procfile?

I'm trying to install New Relic, but it says I'll need to make changes to Procfile. I can't seem to find it at the root of the local copy of my app though. I'm using Django.
Thanks
This page on Heroku gives a lot more information on what the procfile is:
https://devcenter.heroku.com/articles/procfile
You don't have to have one to deploy to Heroku, but you can manually create one to take more control over how Heroku runs your apps. As per this excerpt from the link above:
A Procfile is not necessary to deploy apps written in most languages supported by Heroku. The platform automatically detects the language, and creates a default web process type to boot the application server.
Creating an explicit Procfile is recommended for greater control and flexibility over your app.
For Heroku to use your Procfile, add the Procfile to the root of your application push to Heroku:
$ git add .
$ git commit -m "Procfile"
$ git push heroku
...
-----> Procfile declares process types: web, worker
Compiled slug size is 10.4MB
-----> Launching... done
http://strong-stone-297.herokuapp.com deployed to Heroku
To git#heroku.com:strong-stone-297.git
* [new branch] master -> master
For New Relic support, you have to explicitly tell Heroku to run a gunicorn instance within New Relic. So your Procfile would look something like this:
newrelic-admin run-program gunicorn --workers 4 --worker-class gevent --timeout 60 mysite.wsgi
You can turn this on or off without changing your Procfile by conditionally looking for your New Relic licence in the Heroku environment variables:
Procfile:
web: bash scripts/heroku_run
scripts/heroku_run:
#!/bin/bash
run_command="gunicorn --workers 4 --worker-class gevent --timeout 60 mysite.wsgi"
# Run through New Relic monitoring if add-on installed
if [[ $NEW_RELIC_LICENSE_KEY != '' ]]; then
newrelic-admin run-program $run_command
else
$run_command
fi

Heroku - how to start job worker (delayed job)?

I have some miniapp that use delayed_job. On my localhost everything works fine, but when I deploy my app to Heroku and click on the link that should be executed by delayed_job, so nothing happen, the "task" is just saved into the table delayed_job.
In this article on heroku blog is written, that the task from delayed_job table is executed, when is run this command rake jobs:work.
But how can I run this command? Where should be the command placed? In the code, or from terminal console?
If you are running the Cedar stack, run the following from the terminal console:
heroku run rake jobs:work
If you are running the older stacks (Bamboo, Aspen, etc.):
heroku rake jobs:work
see: https://devcenter.heroku.com/articles/rake
According to the delayed_job documentation, you can also start a worker programmatically:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
Delayed::Worker.new.start
You should use a Procfile to scpecify the commands for your dynos.
For example you would have something like this in your Procfile:
appDir/Procfile
web: bundle exec rails server -p $PORT
worker: bundle exec rake jobs:work
To use this on your development machine, you should use Foreman, it's all explained at the docs.
https://devcenter.heroku.com/articles/procfile
In our case we're only running a delayed job once a month, so didn't want to have a worker dyno running constantly.
To solve this we queue up the job (with .delayed) and then use the Heroku platform API to spawn rake jobs:workoff in a one-off worker. The API call returns relatively quickly.
PlatformAPI.connect_oauth(ENV["YOUR_HEROKU_KEY"]).dyno.create(ENV["YOUR_HEROKU_APP_NAME"],{command: 'rake jobs:workoff'})

How to run Play! background jobs on Heroku

I'm hardly using heroku for my Play! applications nowadays and I am new. I can deploy my web application but background jobs don't run. I tried to add worker but I got this error :
$ heroku scale worker=1
Scaling worker processes... ! No such type as worker
I created a Procfile includes just
web: play run --http.port=$PORT $PLAY_OPTS
It's just for web, I couldn't find expressions to run workers.
How can I run my background jobs on Heroku?
You have to define the worker instead of web:
worker: play run --http.port=$PORT $PLAY_OPTS

Resque Scheduler on Heroku... Do it remotely?

I'm adding Resque-Scheduler in my app on Heroku
So... I need ONE alone and distinct worker acting as the scheduler and
many doing the jobs.
This is how I've done it :
I've a distinct Heroku App which does nothing but has 1 resque-scheduler worker, running 24/7, adding Resque tasks to the Redis DB of the "distant" main App.
(I do that mapping jobs:work task to resque:scheduler or resque:work)
Is this the best way to do it on the Heroku's platform ; or am I doing it totally wrong ?
Thanks !
EDIT:
minimal app for scheduling on Heroku :
http://github.com/clmntlxndr/heroku-scheduler
UPDATE: With the new CEDAR stack on Heroku and Procfiles, it's possible to start a distinct task for each worker.
web: bundle exec rails server -p $PORT
scheduler: bundle exec rake resque:scheduler
worker: bundle exec rake jobs:work
http://devcenter.heroku.com/articles/procfile
I think I misread your question the first time. I missed the part where scheduler requires a separate rake task.
Yes, I think the only way to do it is to have two separate heroku apps, because heroku workers will only run rake jobs:work and presumably you can only map this onto one of the resque rake tasks.
You could try this:
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => ["resque:work", "resque:scheduler"]
But I have sincere doubts about that actually working properly with how Heroku monitors worker processes and stuff. Also, double check the rake syntax there; it's just from memory. I know it's possible to specify multiple dependencies though.

rake aborted! Don't know how to build task 'jobs:work'

Hi all: I'm on Heroku, installed delayed_job and am getting the above error when I attempt to run a background job. I've tried filing a ticket and scouring the net to no avail.
Thanks...Chris
You only use rake jobs:work to start a DJ worker locally. When on Heroku, you have to add workers: heroku workers +1 --app myapp. Those cost money though, so you might want to set workers back to 0 when you're done with it.
Edit:
Looks like this is clearly explained in the docs: http://docs.heroku.com/delayed-job#running-dj-workers-on-heroku.

Resources