Skip to content

Instantly share code, notes, and snippets.

View devdatta's full-sized avatar

Devdatta Kane devdatta

View GitHub Profile
class GetEventResult
@queue = :events
def self.perform(event_id, attempt=0)
event = Event.find(event_id)
Rails.logger.info "Fetching results for event ##{event.id} (#{event.name})..."
begin
results = EventImporter.new(event.datetime.to_date).get_results(event)
rescue OpenURI::HTTPError
module Resque
##
# Resque StateMachine
#
# Is a Mash to be used in a resque queue. The create method will
# initiate the object and enqueue it.
#
# Can pass in a run_at attribute to delay the run.
# Can pass in a test_mode attribute to force test mode.
#
#Tasks have been added to fully maintain nginx, unicorn, redis, memcached, start resque workers and run any command on any server in the farm.
#<pre>
#cap nginx:restart # Restart Nginx.
#cap nginx:start # Start Nginx.
#cap nginx:status # Status of Nginx.
#cap nginx:stop # Stop Nginx.
#cap nginx:tail_error # Tail the Nginx error logs.
#cap unicorn:reload # reload your unicorn servers.
#cap unicorn:restart # restart your unicorn servers.
#cap unicorn:start # start your unicorn servers.

(This is the text of the keynote I gave at Startup Riot 2009. Will update when video becomes available.)

Hi everyone, I’m Chris Wanstrath, and I’m one of the co-founders of GitHub.

GitHub, if you haven’t heard of it, has been described as “Facebook for developers.” Which is great when talking about GitHub as a website, but not so great when describing GitHub as a business. In fact, I think we’re the polar opposite of Facebook as a business: we’re small, never took investment, and actually make money. Some have even called us successful.

Which I’ve always wondered about. Success is very vague, right? Probably even relative. How do you define it?

After thinking for a while I came up with two criteria. The first is profitability. We employ four people full time, one person part time, have thousands of paying customers, and are still growing. In fact, our rate of growth is increasing – which means January was our best month so far, and February is looking pretty damn good.

# Removing libraries, and specifying plugins
config.frameworks -= [:action_controller, :action_view, :action_mailer, :active_resource]
config.plugins = [:acts_as_state_machine, :masochism, :resque]
Resque.after_fork do |job|
# How many jobs should we process in each fork?
jobs_per_fork = [ ENV['JOBS_PER_FORK'].to_i, 1 ].max
# Set hook to nil to prevent running this hook over
# and over while processing more jobs in this fork.
Resque.after_fork = nil
# Make sure we process jobs in the right order.
job.worker.process(job)
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
set :application, "example.com"
set :deploy_to, "/var/www/#{application}"
role :app, "example.com"
role :web, "example.com"
role :db, "example.com", :primary => true
set :scm, :git
set :repository, "ssh://shay@example.com/git/example.com"
set :branch, "origin/master"
# you'd obviously have more settings somewhere
set :scm, :git
set :repository, "git@github.com:defunkt/github.git"
set :branch, "origin/master"
set :migrate_target, :current
set(:latest_release) { fetch(:current_path) }
set(:release_path) { fetch(:current_path) }
set(:current_release) { fetch(:current_path) }
~/projects/jruby ➔ cat blah.rb
# hello_world.rb
require 'rubygems'
require 'sinatra'
get '/' do
sleep 2
"Hello world, it's #{Time.now} at the server!"
end