Skip to content
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

Ensure after works correctly when multiple instances are used #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Four very basic primitives:

* Before: `before { ... }` will execute code before protected resources are converged. The block will receive the converged resource as argument.
* Cleanup: `cleanup { ... }` will execute code at the end of a successful chef-client run. The cleanup block will be executed at *each* chef-client run. This code should thus be efficient and safe to run at the end of all chef-client runs (for instance cleaning a file only if it exists).
* After: `after { ... }` will execute code at the end of choregraphie. The after block will be executed at the end of choregraphie but *might* be executed after some chef-client run. It does best-effort to avoid running when not necessary, code run in `after` must cope with useless run though.
* After: `after('name') { ... }` will execute code at the end of choregraphie. The after block will be executed at the end of choregraphie but *might* be executed after some chef-client run. It does best-effort to avoid running when not necessary, code run in `after` must cope with useless run though. It is important to give a unique name to this primitive (within the same choregraphie)
* Finish: `finish { ... }` will execute code after cleanup stage. There can be only one finish block.


Expand Down
11 changes: 8 additions & 3 deletions libraries/primitive_after.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

module Choregraphie
class After < Primitive
def initialize(&block)
def initialize(name, &block)
@block = block
@name = name
end

def register(choregraphie)
Expand Down Expand Up @@ -47,11 +48,15 @@ def set_installed
private

def inprogress_marker
File.join(Chef::Config[:file_cache_path], "choregraphie-#{@choregraphie_name.gsub(/[^a-zA-Z0-9]/, '_')}-inprogress")
File.join(Chef::Config[:file_cache_path], "#{marker_prefix}-inprogress")
end

def install_marker
File.join(Chef::Config[:file_cache_path], "choregraphie-#{@choregraphie_name.gsub(/[^a-zA-Z0-9]/, '_')}-installed")
File.join(Chef::Config[:file_cache_path], "#{marker_prefix}-installed")
end

def marker_prefix
"choregraphie-#{@choregraphie_name.gsub(/[^a-zA-Z0-9]/, '_')}-#{@name.gsub(/[^a-zA-Z0-9]/, '_')}"
end
end
end
4 changes: 2 additions & 2 deletions spec/unit/primitive_after_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:block) { proc {} }
let(:choregraphie) do
Choregraphie::Choregraphie.new('test') do
after(&block)
after('demo', &block)
end
end

Expand Down Expand Up @@ -76,7 +76,7 @@
end

describe 'invariants' do
subject { Choregraphie::After.new }
subject { Choregraphie::After.new('demo') }
before { subject.register(choregraphie) }

describe '.set_in_progress' do
Expand Down