Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
fix(deploy): Fixed deploy callbacks launching order
Browse files Browse the repository at this point in the history
The issue was, that all driver callbacks (i.e. invoked from deploy_before_restart,
deploy_after_restart etc. methods) were launched after deploy was completely finished (instead at
proper callback time). However `deploy/after_restart.rb` etc. callbacks from projects were launched
during callback phase. This could lead to the problems, for example: `deploy/after_restart.rb` might
be dependant on `deploy_before_restart` action from the drivers and would crash if not fullified. Up
to this commit, this would happend. However this fix ensures, that both driver and app callbacks are
launched at the same time (first drivers, then app). It was resolved, by setting correct context to
the drivers. When driver is in "callback phase" it expects a "callback context", otherwise it would
assume, that action is fired up in deploy recipe context, and thus - move it down to the queue.
  • Loading branch information
ajgon committed Oct 21, 2016
1 parent 8fd017d commit 81d31c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libraries/drivers_base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true
module Drivers
class Base
attr_reader :context, :app, :options, :configuration_data_source
attr_reader :app, :options, :configuration_data_source
attr_accessor :context

def initialize(context, app, options = {})
@context = context
@app = app
Expand Down
3 changes: 3 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def globals

def fire_hook(name, options)
Array.wrap(options[:items]).each do |item|
old_context = item.context
item.context = options[:context] if options[:context].present?
item.send(name)
item.context = old_context
end
end

Expand Down
16 changes: 12 additions & 4 deletions recipes/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@
before_migrate do
perform_bundle_install(shared_path, bundle_env)

fire_hook(:deploy_before_migrate, items: databases + [scm, framework, appserver, worker, webserver])
fire_hook(
:deploy_before_migrate, context: self, items: databases + [scm, framework, appserver, worker, webserver]
)

run_callback_from_file(File.join(release_path, 'deploy', 'before_migrate.rb'))
end

before_symlink do
perform_bundle_install(shared_path, bundle_env) unless framework.out[:migrate]

fire_hook(:deploy_before_symlink, items: databases + [scm, framework, appserver, worker, webserver])
fire_hook(
:deploy_before_symlink, context: self, items: databases + [scm, framework, appserver, worker, webserver]
)

run_callback_from_file(File.join(release_path, 'deploy', 'before_symlink.rb'))
end
Expand All @@ -73,13 +77,17 @@
action :delete
end if scm.out[:remove_scm_files]

fire_hook(:deploy_before_restart, items: databases + [scm, framework, appserver, worker, webserver])
fire_hook(
:deploy_before_restart, context: self, items: databases + [scm, framework, appserver, worker, webserver]
)

run_callback_from_file(File.join(release_path, 'deploy', 'before_restart.rb'))
end

after_restart do
fire_hook(:deploy_after_restart, items: databases + [scm, framework, appserver, worker, webserver])
fire_hook(
:deploy_after_restart, context: self, items: databases + [scm, framework, appserver, worker, webserver]
)

run_callback_from_file(File.join(release_path, 'deploy', 'after_restart.rb'))
end
Expand Down

0 comments on commit 81d31c9

Please sign in to comment.