Skip to content

Instantly share code, notes, and snippets.

class LongRunningTasks
include Queueable
queue 'myqueue'
def download(url)
require 'open-uri'
open("#{RAILS_ROOT}/tmp/#{Time.now.to_i}", 'w+') { |f| f.write(open(url).read) }
end
@mikewadhera
mikewadhera / application_tasks.rb
Created January 7, 2009 03:36
an example leveraging jruby-rack jms for background queue + cron in rails
require 'queueable'
class ApplicationTasks
include Queueable
end
puts "Hello World"
class Greeter
attr_accessor :greeting
def initialize(greeting)
self.greeting = greeting
end
def greet
puts self
end
pool :sandbox do
instances 1..1
cloud :hello_world do
# Update with the path to your EC2 keypair
# If you don't have one, create with:
# $ ec2-create-keypair NAME > /path/to/your/keypairs/<NAME>
keypair "/path/to/your/keypairs/<NAME>"
pool :involver_rails do
cloud :nginx do
instances 2..2 # binds against 2 elastic IPs
has_package "nginx"
end
cloud :app do
instances 2..12
# Following adds a svn co of my_app to /mnt/svn-repos/my_app on cloud-start
# svn up is run on the working copy every cloud-configure
has_svn_repos :name => "my_app",
:at => "/mnt/svn-repos",
:source => "http://svn.myhost.com/my_app",
:user => "<optional>",
:password => "<optional>"
require "jruby"
module JettyRails
class Runner
attr_reader :servers
def initialize(config = {})
@servers = {}
config.symbolize_keys!
#!/bin/sh
echo "Starting memcached in background..."
memcached &
echo "Starting OpenMQ broker in background..."
imqbrokerd -silent &
echo "Starting background_tasks queue processor in background..."
jruby script/queue_processor >/dev/null 2>&1 &
echo "Starting Jetty Rails..."
jruby --headless -S jetty_rails
@mikewadhera
mikewadhera / gist:169966
Created August 18, 2009 21:02
deploy:rolling_restart
namespace :deploy do
desc "Restarts each app role one at a time, removing from load balancing during restart"
serial_task self, :rolling_restart, :roles => :app do
lb = fetch(:load_balancer)
lb_removal = lambda { `elb-deregister-instances-from-lb #{lb} --instances #{@instance_id}` }
lb_addition = lambda { `elb-register-instances-with-lb #{lb} --instances #{@instance_id}` }
watch = "rails"
port = 8080