This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'daemons' | |
module Daemons | |
class Monitor | |
def stop | |
pid = @pid.pid | |
begin; Process.kill('TERM', pid); rescue ::Exception; end | |
sleep(0.5) | |
begin; Process.kill('KILL', pid); rescue ::Exception; end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require File.dirname(__FILE__) + "/../../config/environment" | |
$running = true | |
$working = false | |
Signal.trap("TERM") do | |
$stderr.puts "#{Time.now.to_s(:db)}\tGot TERM, exiting..." | |
$running = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def destroy | |
if params[:ids] | |
@models = Model.find(:all, :conditions => { :id => params[:ids] }) | |
@models.each { |m| m.destroy } | |
else | |
@model = Tracker.find(params[:id]) | |
@model.destroy | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def em_start_websockets(options) | |
options.logger.info "Starting WebSockets daemon on #{options.websocket_host}:#{options.websocket_port} and '#{ENV['RAILS_ENV']}' environment" | |
@connections = 0 | |
EventMachine::WebSocket.start(:host => options.websocket_host, :port => options.websocket_port, :debug => false) do |ws| | |
@user = nil | |
ws.onopen do | |
@connections = @connections + 1 | |
puts "WebSocket connection open: #{@connections}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def em_start_websockets(options) | |
options.logger.info "Starting WebSockets daemon on #{options.websocket_host}:#{options.websocket_port} and '#{ENV['RAILS_ENV']}' environment" | |
connections = 0 | |
EventMachine::WebSocket.start(:host => options.websocket_host, :port => options.websocket_port, :debug => false) do |ws| | |
mq = MQ.new | |
user = nil | |
token = nil | |
queue = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'), | |
http = require('http'); | |
//var process = require('process'); | |
var amqp = require('./node-amqp/amqp'); | |
var connection = amqp.createConnection({ host: 'localhost' }); | |
var env = process.env.RAILS_ENV || 'development'; | |
sys.puts('Environment: ' + env); | |
connection.addListener('ready', function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
#require 'map_by_method' rescue nil | |
require 'pp' | |
# Enable tab-completion. | |
require 'irb/completion' rescue nil | |
# Enable prompt-less prompts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- ruby -*- | |
require 'rubygems' | |
require 'daemon-spawn' | |
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) | |
class DelayedJobWorker < DaemonSpawn::Base | |
def start(args) | |
ENV['RAILS_ENV'] ||= args.first || 'development' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The problem: In your Rails 3 project, you have a model Request that models a | |
# user's request for content related to a specific problem or topic. The user | |
# can tag her request with any number of words. These are modeled by a Tag class | |
# backed by a tags DB table. Since you want unique records per tag, you have a | |
# Tagging class backed by a taggings table. Taggings is a a many-to-many table | |
# with some additional information. Also, other models in the application | |
# besides requests can be tagged: The Tagging class defines a polymorphic | |
# relationship "taggable" with those models. | |
# | |
# So pretty soon you want to look up all the requests that are tagged with |
OlderNewer