Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moves rollback logic to capistrano support lib

  • Loading branch information...
commit aa9ba247482c907b7fc93efdc53cf09c84438205 1 parent 3236be4
@jeroenj jeroenj authored
View
22 lib/whenever/capistrano/recipes.rb
@@ -22,29 +22,11 @@
}
if whenever_servers.any?
- if task_call_frames[0].task.fully_qualified_name == 'deploy:rollback'
- if fetch(:previous_release)
- # rollback to the previous release's crontab
- args[:path] = fetch(:previous_release)
- else
- # clear the crontab if no previous release
- args[:path] = fetch(:release_path)
- args[:flags] = fetch(:whenever_clear_flags)
- end
- end
-
+ args = whenever_prepare_for_rollback(args) if task_call_frames[0].task.fully_qualified_name == 'deploy:rollback'
whenever_run_commands(args)
on_rollback do
- if fetch(:previous_release)
- # rollback to the previous release's crontab
- args[:path] = fetch(:previous_release)
- else
- # clear the crontab if no previous release
- args[:path] = fetch(:release_path)
- args[:flags] = fetch(:whenever_clear_flags)
- end
-
+ args = whenever_prepare_for_rollback(args)
whenever_run_commands(args)
end
end
View
12 lib/whenever/capistrano/support.rb
@@ -22,6 +22,18 @@ def whenever_server_roles
end
end
+ def whenever_prepare_for_rollback args
+ if fetch(:previous_release)
+ # rollback to the previous release's crontab
+ args[:path] = fetch(:previous_release)
+ else
+ # clear the crontab if no previous release
+ args[:path] = fetch(:release_path)
+ args[:flags] = fetch(:whenever_clear_flags)
+ end
+ args
+ end
+
def whenever_run_commands(args)
unless [:command, :path, :flags].all? { |a| args.include?(a) }
raise ArgumentError, ":command, :path, & :flags are required"
View
16 test/unit/capistrano_support_test.rb
@@ -78,6 +78,22 @@ class CapistranoSupportTest < Test::Unit::TestCase
end
end
+ context "#whenever_prepare_for_rollback" do
+ should "set path to previous_release if there is a previous release" do
+ args = {}
+ @capistrano.stubs(:fetch).with(:previous_release).returns("/some/path/20121221010000")
+ assert_equal({:path => "/some/path/20121221010000"}, @capistrano.whenever_prepare_for_rollback(args))
+ end
+
+ should "set path to release_path and flags to whenever_clear_flags if there is no previous release" do
+ args = {}
+ @capistrano.stubs(:fetch).with(:previous_release).returns(nil)
+ @capistrano.stubs(:fetch).with(:release_path).returns("/some/path/20121221010000")
+ @capistrano.stubs(:fetch).with(:whenever_clear_flags).returns("--clear-crontab whenever_identifier")
+ assert_equal({:path => "/some/path/20121221010000", :flags => "--clear-crontab whenever_identifier"}, @capistrano.whenever_prepare_for_rollback(args))
+ end
+ end
+
context "#whenever_run_commands" do
should "require :command arg" do
assert_raise ArgumentError do
Please sign in to comment.
Something went wrong with that request. Please try again.