Skip to content

Instantly share code, notes, and snippets.

@ulfurinn
Created June 19, 2013 08:33
Show Gist options
  • Save ulfurinn/5812658 to your computer and use it in GitHub Desktop.
Save ulfurinn/5812658 to your computer and use it in GitHub Desktop.
deploying with hooks and amqp
#!/usr/bin/env ruby
require "dante"
require "amqp"
require "oj"
$0 = "My project generator"
Dir.chdir "/var/www/my-project"
Dante.run "my-project", pid_path: '/var/www/my-project-generator.pid', user: 'www-data', group: 'www-data' do
EM.run do
connection = AMQP.connect host: "my.broker.host", vhost: "/my-vhost", user: "my-user", password: "my-password"
channel = AMQP::Channel.new connection
queue = channel.queue "my-project", auto_delete: true
queue.subscribe do |payload|
message = Oj.load payload
case message["action"]
when "generate"
`my-deploy-script`
end
end
end
end
#!/usr/bin/env ruby
require "amqp"
EM.run do
connection = AMQP.connect(host: 'my.broker.host', vhost: '/my-vhost', user: 'my-user', password: 'my-password')
channel = AMQP::Channel.new connection
ex = channel.direct ""
ex.publish '{"action":"generate"}', routing_key: "my-project" do
connection.disconnect { EM.stop }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment