Greg,
Thanks for the quick response. The main thing is that I want to be able to call :rollback only if :validation fails or in a couple of other places where fatal errors can occur and just stopping is not good enough.
Cheers,
Florian
From: Greg Symons [mailto:
Sent: 09 October 2013 19:12
To:
Subject: [chef] Re: LWRPs and rolling back
On 10/09/13 09:32, Florian Hehlen wrote:
HI all,
I am writting my own LWRP for my server. So I have the following actions:
actions :stop, :db_backup, :update, :validate, :db_rollback, :server_rollback, :start
creating the resource/provider is working pretty well. I am wondering though how I can express the workflow logic in the recipe to roll-back only if the validation fails.
I see some possibilities with handlers, or with the only_if/not_if properties, notifiers/subscribers but none of them scream out as the way to go. Are there any suggestions on best practices here?
cheers,
Florian
Let the provider handle the sequencing. So, in your example, I'd define methods in the provider for each of the steps you currently have as actions, and then in the actual actions, call them in the right order:
action :stop do
doStop
end
action :backup do
doStop
doBackup
end
action :update do
doUpdate
doRollback unless doValidate
end
action :rollback do
doRollback
end
action :validate do
doValidate
end
action :start do
doStart
end
I don't actually know the rules of your workflow, so those may not be right. In fact, if there are things in your workflow you'd really never do separately from other things, then I wouldn't even expose those as separate actions.
Greg