-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callbacks to deployment events, refresh #176
base: master
Are you sure you want to change the base?
Changes from all commits
c37d698
f6120ae
b51f313
7c49d17
285bbd2
47f097c
a33712e
fac0cf5
6938de7
2e533ba
dfb7a24
474bf7b
076e5b9
1389705
bab5e53
8b146f4
208155b
4789be5
b2514a4
f34ae8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ language: ruby | |
before_install: | ||
- gem update | ||
- gem install bundler | ||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
- 2.1.0 | ||
- 2.2.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Centurion | ||
# Callbacks to allow hooking into the deploy lifecycle. This could | ||
# be useful to communicate with a loadbalancer, chat room, etc. | ||
module DeployCallbacks | ||
def stop_containers(server, service, timeout = 30) | ||
emit :before_stopping_container, server, service | ||
super server, service, timeout | ||
end | ||
|
||
def before_starting_container(server, service) | ||
emit :before_starting_container, server, service | ||
end | ||
|
||
def start_new_container(server, service, restart_policy) | ||
super(server, service, restart_policy).tap { emit :after_starting_container, server, service } | ||
end | ||
|
||
def wait_for_health_check_ok(health_check_method, server, port, endpoint, image_id, tag, sleep_time=5, retries=12) | ||
super(health_check_method, | ||
server, | ||
port, | ||
endpoint, | ||
image_id, | ||
tag, | ||
sleep_time, | ||
retries).tap { emit :after_health_check_ok, server } | ||
end | ||
|
||
private | ||
|
||
def emit(name, *args) | ||
callbacks[name].each do |callback| | ||
callback.call(*args) | ||
end | ||
end | ||
|
||
def callbacks | ||
fetch 'callbacks', Hash.new { [] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently this fails with:
I'm not sure how it was supposed to work given the history - @relistan any ideas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well the idea had been to keep |
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
require 'spec_helper' | ||
require 'centurion' | ||
|
||
RSpec.describe Centurion::DeployCallbacks do | ||
shared_examples_for 'a callback' do | ||
let(:server) { double :server } | ||
let(:service) { double :service } | ||
|
||
let(:klass) do | ||
Class.new do | ||
include Centurion::DeployCallbacks | ||
def method_missing(method_name, *_args) | ||
doing method_name | ||
end | ||
end | ||
end | ||
|
||
let(:object) do | ||
klass.new | ||
end | ||
|
||
before do | ||
allow(object).to receive(:emit) | ||
end | ||
end | ||
|
||
shared_examples_for 'the before_stopping_container callbacks' do |callback, method_name| | ||
include_examples 'a callback' | ||
|
||
it 'invokes all the callbacks' do | ||
expect(object).to receive(:emit).with(callback, server, service).ordered | ||
expect(object).to receive(:doing).with(method_name).ordered | ||
subject | ||
end | ||
end | ||
|
||
shared_examples_for 'the before_starting_container callbacks' do |callback| | ||
include_examples 'a callback' | ||
|
||
it 'invokes all the callbacks' do | ||
expect(object).to receive(:emit).with(callback, server, service).ordered | ||
subject | ||
end | ||
end | ||
|
||
shared_examples_for 'the after_starting_container callbacks' do |callback, method_name| | ||
include_examples 'a callback' | ||
|
||
it 'invokes all the callbacks' do | ||
expect(object).to receive(:doing).with(method_name).ordered | ||
expect(object).to receive(:emit).with(callback, server, service).ordered | ||
subject | ||
end | ||
end | ||
|
||
shared_examples_for 'the after_health_check_ok callbacks' do |callback, method_name| | ||
include_examples 'a callback' | ||
|
||
it 'invokes all the callbacks' do | ||
expect(object).to receive(:doing).with(method_name).ordered | ||
expect(object).to receive(:emit).with(callback, server).ordered | ||
subject | ||
end | ||
end | ||
|
||
describe 'the before_stopping_container callback' do | ||
subject { object.stop_containers server, service } | ||
it_behaves_like 'the before_stopping_container callbacks', | ||
:before_stopping_container, | ||
:stop_containers | ||
end | ||
|
||
describe 'before_starting_container callback' do | ||
subject { object.before_starting_container server, service } | ||
it_behaves_like 'the before_starting_container callbacks', | ||
:before_starting_container | ||
end | ||
|
||
describe 'after started callback' do | ||
subject { object.start_new_container server, service, double } | ||
it_behaves_like 'the after_starting_container callbacks', | ||
:after_starting_container, | ||
:start_new_container | ||
end | ||
|
||
describe 'after health check ok callback' do | ||
let(:args) do | ||
[ | ||
double(:health_check_method), | ||
server, | ||
double(:port), | ||
double(:endpoint), | ||
double(:image_id), | ||
double(:tag), | ||
double(:sleep), | ||
double(:retries) | ||
] | ||
end | ||
subject { object.wait_for_health_check_ok(*args) } | ||
it_behaves_like 'the after_health_check_ok callbacks', | ||
:after_health_check_ok, | ||
:wait_for_health_check_ok | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain this actually gets called.