heroku addons API • create servers • install postgres service • create databases for users - a “Resource” • Sequel talks to postgres • stem talks to AWS 12 Saturday, July 28, 12
def state(name, &block) states[name] = block end def states; @states ||= {}; end end def tick self.instance_eval( &self.class.states[self.state.to_sym] ) end def transition(state) # log and assign new state end end workflow 26 Saturday, July 28, 12
= Worker.new(params) begin worker.lift_things_up worker.put_them_down rescue WorkerError => e puts “Fail :( #{e.message}” status 500 end puts “done doing work” status 200 end 62 Saturday, July 28, 12
work 2012-07-28T02:43:35 [web.4] Fail :( invalid worker, nothing to do 2012-07-28T02:43:35 heroku[router] POST myapp.com/work dyno=web.4 queue=0 wait=0ms service=14ms status=500 bytes=643 63 Saturday, July 28, 12
= Worker.new(params.merge(uuid: uuid)) begin worker.lift_things_up worker.put_them_down rescue WorkerError => e log_exception(e, create_work: true) end end end helpers do def uuid SecureRandom.uuid end end 65 Saturday, July 28, 12
log(data, &block) Scrolls.log(with_env(data), &block) end def log_exception(exception, data, &block) Scrolls.log_exception(with_env(data), &block) end def with_env(hash) { environment: ENV[‘RACK_ENV’] }.merge(data) end end end 66 Saturday, July 28, 12
fog displaced stem • backbone.js for web UIs • fernet for auth tokens, valcro for simple validations, QueueClassic for job queues • Wal-e for durability • python, go and bash in some subsystems 74 Saturday, July 28, 12
(and share) reusable code • separate concerns into services • use the right tool (framework, library, language) • learn to love your event stream, metrics for everything 75 lessons 75 Saturday, July 28, 12