Skip to content

Instantly share code, notes, and snippets.

@eric
eric / README.md
Last active December 17, 2015 00:39
Zookeeper-based storage adapter for rollout

Update

You can now find this packaged up nicely in a rubygem as rollout-zk.


Zookeeper storage adapter for rollout

I've implemented a zookeeper-based storage adapter for [rollout][] that does not require any network roundtrips to check if a feature is active for a user.

@eric
eric / _scheduler.rb
Last active December 15, 2015 07:49
class Scheduler < Rufus::Scheduler::PlainScheduler
def initialize(zk, *args)
super(*args)
@zk_locker = zk.exclusive_locker('scheduler')
end
def run
@zk_locker.with_lock do
configure
Installing hitimes (1.1.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
creating Makefile
make
xcrun cc -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common -DUSE_INSTANT_OSX=1 -Wall -c hitimes_ext.c
xcrun cc -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common -DUSE_INSTANT_OSX=1 -Wall -c hiti
module Zookeeper
class BroadcastTrigger
def initialize(zk, path)
@zk = zk
@path = path
end
def trigger
@zk.set(@path, "#{$$}")
rescue ZK::Exceptions::NoNode
God.watch do |w|
w.name = 'remote_syslog'
w.interval = 7.seconds
w.log = File.join(RAILS_ROOT, 'log', "#{w.name}-god.log")
w.dir = RAILS_ROOT
w.start = "bundle exec remote_syslog --tls -D -c #{RAILS_ROOT}/config/remote_syslog.yml"
namespace :redis_failover do
task :monitor_client do
require 'redis_failover'
zookeepers = ENV['ZOOKEEPERS']
if !zookeepers && zookeepers_file = ENV['ZOOKEEPERS_FILE']
if File.exists?(zookeepers_file)
zookeepers = File.read(zookeepers_file).chomp
end
require 'lazy'
require 'system_timer'
class LibratoMetric
COUNT = 10
RESOLUTION = 1
def initialize(metric_name, timeout = 4)
@metric_name = metric_name
@timeout = timeout
@eric
eric / jobs.rb
Created July 16, 2012 19:17 — forked from ahoward/jobs.rb
./script/jobs
#!/usr/bin/env ruby
# encoding: utf-8
# setup
#
require 'fileutils'
script = File.expand_path(__FILE__).gsub(%r|\breleases/\d+\b|, 'current')
script_dir = File.dirname(script)
rails_root = File.dirname(script_dir)
#
# Simple Boundary client
#
class BoundaryClient
def initialize(orgid, apikey)
@orgid = orgid
@apikey = apikey
end
@eric
eric / cubism.papertrail.js
Created June 1, 2012 04:37
cubism.js source for Papertrail
/*
* Cubism source for Papertrail
* https://papertrailapp.com/
*/
cubism.context.prototype.papertrail = function(token) {
var source = {};
source.metric = function(expression, title) {
var lookup = {};