This repository was archived by the owner on Jan 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Add callbacks to deployment events, refresh #176
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c37d698
Collect callbacks to run before stopping, and after starting an image
MarkBorcherding f6120ae
add before stopping callbacks
MarkBorcherding b51f313
add after starting callbacks
MarkBorcherding 7c49d17
converge on common names to store the callbacks
MarkBorcherding 285bbd2
make sure nil callbacks do not get added
MarkBorcherding 47f097c
add notes in the readme about the callbacks
MarkBorcherding a33712e
refactor callbacks
MarkBorcherding fac0cf5
collect after_health_check_ok callbacks
MarkBorcherding 6938de7
add test that it returns a list of all the callbacks
MarkBorcherding 2e533ba
Remove adding the callbacks by default in the deploy module
MarkBorcherding dfb7a24
create dry callback test
MarkBorcherding 474bf7b
add after health check ok callback
MarkBorcherding 076e5b9
dry up the callbacks helpers
MarkBorcherding 1389705
Mix the callbacks in before the deploy
MarkBorcherding bab5e53
add travis
MarkBorcherding 8b146f4
add after_health_check_ok to readme
MarkBorcherding 208155b
Emit events in a more generic manner
MarkBorcherding 4789be5
Rename callbacks to _container, add :before_starting_container hook.
b2514a4
Fixing merge issue in .travis.yml
f34ae8e
Fix outdated reference to before_starting_image
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { [] } | ||
|
Contributor
Author
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?
Collaborator
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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.