Skip to content

Instantly share code, notes, and snippets.

@seigel
Created November 4, 2011 05:32
Show Gist options
  • Save seigel/1338725 to your computer and use it in GitHub Desktop.
Save seigel/1338725 to your computer and use it in GitHub Desktop.
Resque on Cloudfoundry
# shell for the real worker in the other project
class EmailSentCount
@queue = :high
end
require 'mining'
if ENV['VCAP_SERVICES'].nil?
if Rails.env == 'development'
Mining.set_redis(Redis.new)
Resque.redis = Redis.new
Mining.redis.select(4)
end
else
vcap_services = JSON.parse(ENV['VCAP_SERVICES'])
redis = vcap_services.detect { |k,v| k =~ /redis/ }.last.first
redis_host = redis["credentials"]["hostname"]
redis_port = redis["credentials"]["port"]
redis_password = redis["credentials"]["password"]
Mining.set_redis(Redis.new( :host => redis_host, :port => redis_port, :password => redis_password ))
Resque.redis = Redis.new( :host => redis_host, :port => redis_port, :password => redis_password)
Mining.redis.select(4)
end
...
require File.join(File.dirname(__FILE__), '../../lib/email_sent_count') # shell job for update profile
...
...
Resque.enqueue(EmailSentCount, {})
...
@millisami
Copy link

Is this in separate apps or a single app?
Can you plz explain how the setup is done?

@seigel
Copy link
Author

seigel commented Nov 11, 2011

This is all the Rails side of the application. I have a resque application running which attaches to the same redis server and then runs jobs when it sees them. This gives some nice decoupling between the rails application and the workers.

@millisami
Copy link

Is there any repo/gist on running the resque app separately on the CloudFoundry?
Last time I tried running in the same rails app as threaded process in config/initializer, but couldn't get any success with it.

So, it would be great to see on how to run the resque app separately since CF doesn't provide any rake tasks to run on its platform. I really like to see your approach on how you're running resque app separately!

@seigel
Copy link
Author

seigel commented Nov 14, 2011

I'll post a skeleton here shortly :)

@millisami
Copy link

Do please! Thanks

@seigel
Copy link
Author

seigel commented Nov 14, 2011

Take a look here and play around with it...I left some example jobs in etc..you'll have to change or remove some settings for your example. This one uses redis and mongodb :)

https://github.com/seigel/rescue_worker_cloudfoundry_example

Good luck

@millisami
Copy link

Thanks, I'll check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment