Skip to content

Instantly share code, notes, and snippets.

@piclez
Forked from nickstenning/run.rb
Created July 21, 2008 21:18
Show Gist options
  • Save piclez/255 to your computer and use it in GitHub Desktop.
Save piclez/255 to your computer and use it in GitHub Desktop.
require 'rfc822'
class Demo < ActiveRecord::Base
validates_presence_of :client, :message => "can't be blank"
validates_format_of :contact_email,
:with => RFC822::EmailAddress,
:message => "is not a valid email address"
validates_date :expiry_date,
:after => Proc.new { Date.today },
:after_message => "must be in the future",
:allow_nil => true
serialize :manager, Outback::Manager
def before_create
write_attribute(:manager, Outback::YAML.load_file(File.join(RAILS_ROOT, 'lib', 'outback', 'tasks', 'sleepalot.yml')))
end
def busy?
['rolling_out', 'rolling_back'].include? state
end
def rolled_out?
['rolled_out'].include? state
end
def rolled_back?
['rolled_back', nil].include? state
end
def rollout!
raise "Cannot roll out if already rolled out!" if rolled_out?
raise "Cannot roll out if already busy!" if busy?
self.state = 'rolling_out'
options = { :logfile => logfile,
:command => :rollout,
:demo => id }
job = Bj.submit("./script/runner ./lib/outback/run.rb",
:stdin => YAML::dump(options)).first
self.job_id = job.id
save
end
def job
begin
Bj.table.job.find(job_id)
rescue ActiveRecord::RecordNotFound
return nil
end
end
def logfile
File.join(RAILS_ROOT, 'log', "outback_demo_#{id}.log")
end
end
Starting rollout.
Finished rollout.
#<Demo id: 2, client: "Client Name", url: nil, notes: nil, live: nil, created_at: "2008-07-21 20:52:21", updated_at: "2008-07-21 20:52:27", contact_email: "[email protected]", expiry_date: nil, state: "rolling_out", job_id: "2", manager: #<Outback::Manager:0x20c1064 @watcher=nil, @names={}, @direction=1, @tasks=[...stuff snipped...], @position=3>>
#<Demo id: 2, client: "Client Name", url: nil, notes: nil, live: nil, created_at: "2008-07-21 20:52:21", updated_at: "2008-07-21 20:52:27", contact_email: "[email protected]", expiry_date: nil, state: "rolling_out", job_id: "2", manager: #<Outback::Manager:0x20b816c @names={}, @tasks=[...stuff snipped...], @position=0>>
#!/usr/bin/env ruby -w
# This should be run through './script/runner'
options = YAML.load($stdin.read)
demo = Demo.find(options[:demo])
runner = Outback::Runner.new
runner.manager = demo.manager
runner.logger = Logger.new(options[:logfile])
command = options[:command]
runner.run(command)
# We don't need to serialize the runner.
demo.manager.watcher = nil
raise "Could not save demo with updated manager!" unless demo.save
p demo
demo.reload
p demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment