Skip to content

Commit

Permalink
prep target hook should be run before queueing job
Browse files Browse the repository at this point in the history
  • Loading branch information
kavyasukumar committed Sep 4, 2018
1 parent 797e438 commit 2399e41
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions app/models/autotune/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def live?
end

# Updates blueprint version and builds the project.
# Queues jobs to sync latest verison of blueprint, update it on the project
# Queues jobs to sync latest version of blueprint, update it on the project
# and build the new project.
# It publishes updates on projects already published.
# @raise The original exception when the update fails
Expand All @@ -112,6 +112,19 @@ def build(current_user, update: false, publish: false,
repeat_until: nil, wait_until: nil, convert_to_blueprint: nil)
# First check to see if there already is a lock on this job
target = publishable? && !publish ? 'preview' : 'publish'
self.status = 'building'

# If this is a blueprint-based project and an update is requested, update
# the version and config data from the blueprint
if update && !bespoke? && blueprint_version != blueprint.version
self.blueprint_version = blueprint.version
self.blueprint_config = blueprint.config
end

dep = deployer(target, :user => current_user)
dep.prep_target
dep.after_prep_target

job = ProjectJob.new(
self,
:update => update,
Expand All @@ -121,33 +134,18 @@ def build(current_user, update: false, publish: false,
)
raise 'Build cancelled, another build is already queued or running' if job.unique_lock?

begin
self.status = 'building'
save!

# If this is a blueprint-based project and an update is requested, update
# the version and config data from the blueprint
if update && !bespoke? && blueprint_version != blueprint.version
self.blueprint_version = blueprint.version
self.blueprint_config = blueprint.config
end

dep = deployer(target, :user => current_user)
dep.prep_target
dep.after_prep_target

save!
repeat_build!(Time.zone.at(repeat_until.to_i)) if repeat_until.present?

repeat_build!(Time.zone.at(repeat_until.to_i)) if repeat_until.present?

if wait_until
job.enqueue(:wait_until => wait_until)
else
job.enqueue
end
rescue StandardError
update!(:status => 'broken')
raise
if wait_until
job.enqueue(:wait_until => wait_until)
else
job.enqueue
end
rescue StandardError
update!(:status => 'broken')
raise
end
# rubocop:enable Metrics/ParameterLists

Expand Down

0 comments on commit 2399e41

Please sign in to comment.