Druwerd/caplock — pull request #3 by giosh94mhz (2014-05-26 15:50:27+00:00)
Title: Improved locking: use raise instead of abort, create lock before update_...

...code

Hi!
I've made a few changes to the locking/unlocking task so that it is very rare to have a stale lock file. I know that Capistrano 2 is now considered legacy code, but I think that a 0.3.0 version will not hurt. :)

The main changes is that the code is not triggered before deploy, but before update_code, which is actually inside the deploy task. By doing so, (almost) nothing change in the deploy flow, but the lock:check task is called inside a transaction, which enable the use of exceptions and the on_rollback trigger.

So the improvements are:
* Backward compatible (some fancy configuration may need tweaking though);
* On failure/ctrl-c/... on_rollback ensure proper cleanup of lock file;
* avoid abort function, use LockedDeployError exception instead.

I've added all the required test case and removed the FIXME you left behind. :)

What do you think about it?