Add skype notifications

This commit is contained in:
Alexander Machehin 2014-03-06 21:45:33 +06:00
parent afc01cfe96
commit 2e4112e6a4
4 changed files with 89 additions and 0 deletions

View File

@ -112,6 +112,8 @@ group :development do
gem 'binding_of_caller'
gem 'meta_request'
gem 'localeapp'
gem 'skype'
gem 'ruby-dbus' if RUBY_PLATFORM =~ /linux/i
end
group :test do

View File

@ -411,6 +411,8 @@ GEM
skinny (0.2.3)
eventmachine (~> 1.0.0)
thin (~> 1.5.0)
skype (0.2.7)
tmp_cache
soundmanager-rails (1.0.0)
sprockets (2.2.2)
hike (~> 1.2)
@ -433,6 +435,7 @@ GEM
time_diff (0.3.0)
activesupport
i18n
tmp_cache (0.1.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
@ -540,6 +543,7 @@ DEPENDENCIES
sass-rails (~> 3.2.5)
shotgun
shoulda
skype
soundmanager-rails
state_machine
therubyracer (~> 0.12.1)

View File

@ -33,6 +33,9 @@ require 'puma/capistrano'
set :workers_count, 4
require './lib/recipes/resque'
require './lib/recipes/skype'
set :skype_topic, 'ABF' # Skype chat topic name
namespace :deploy do
task :symlink_all, :roles => :app do
run "mkdir -p #{fetch :shared_path}/config"

80
lib/recipes/skype.rb Normal file
View File

@ -0,0 +1,80 @@
require 'skype'
Capistrano::Configuration.instance(:must_exist).load do
Skype.config app_name: 'test-message'
set :skype_send_notification, true
namespace :skype do
task :trigger_notification do
set :skype_send_notification, true if !dry_run
end
task :configure_for_migrations do
set :skype_with_migrations, ' (with migrations)'
end
task :notify_deploy_started do
if skype_send_notification
environment_string = env
if self.respond_to?(:stage)
environment_string = "#{stage} (#{env})"
end
on_rollback do
send("Cancelled deployment of #{deployment_name} to #{environment_string}.")
send('#'*60)
end
send('#'*60)
send("Deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.")
end
end
task :notify_deploy_finished do
if skype_send_notification
environment_string = env
if self.respond_to?(:stage)
environment_string = "#{stage} (#{env})"
end
send("Finished deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.")
send('#'*60)
end
end
def send(message)
set :skype_client, Skype.chats.find { |c| c.topic == fetch(:skype_topic, '') } if fetch(:skype_client, nil).nil?
begin
skype_client.post(message)
rescue => e
puts e.message
puts e.backtrace
end
end
def deployment_name
if fetch(:branch, nil)
name = "#{application}/#{branch}"
name += " (revision #{real_revision[0..7]})" if real_revision
name
else
application
end
end
def message_notification
fetch(:skype_announce, false)
end
def env
fetch(:skype_env, fetch(:rack_env, fetch(:rails_env, "production")))
end
end
before "deploy", "skype:trigger_notification"
before "deploy:update_code", "skype:notify_deploy_started"
after "deploy", "skype:notify_deploy_finished"
after "deploy:migrations", "skype:notify_deploy_finished"
end