Skip to content

Commit

Permalink
Ensure to update job status on error cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed Apr 6, 2017
1 parent b2ad10f commit e6de791
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/service_ansible_playbook.rb
Expand Up @@ -49,6 +49,7 @@ def postprocess(action)
def on_error(action)
_log.info("on_error called for service action: #{action}")
update_attributes(:retirement_state => 'error') if action == "Retirement"
job(action).try(:refresh_ems)
postprocess(action)
end

Expand Down
5 changes: 4 additions & 1 deletion spec/models/service_ansible_playbook_spec.rb
Expand Up @@ -22,7 +22,8 @@

let(:executed_service) do
FactoryGirl.create(:service_ansible_playbook, :options => provision_options).tap do |service|
allow(service).to receive(:job).with(action).and_return(tower_job)
regex = /(#{ResourceAction::PROVISION})|(#{ResourceAction::RETIREMENT})/
allow(service).to receive(:job).with(regex).and_return(tower_job)
end
end

Expand Down Expand Up @@ -210,12 +211,14 @@
describe '#on_error' do
it 'handles retirement error' do
executed_service.update_attributes(:retirement_state => 'Retiring')
expect(tower_job).to receive(:refresh_ems)
expect(executed_service).to receive(:postprocess)
executed_service.on_error(ResourceAction::RETIREMENT)
expect(executed_service.retirement_state).to eq('error')
end

it 'handles provisioning error' do
expect(tower_job).to receive(:refresh_ems)
expect(executed_service).to receive(:postprocess)
executed_service.on_error(action)
expect(executed_service.retirement_state).to be_nil
Expand Down

0 comments on commit e6de791

Please sign in to comment.