Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/jobs/communication/website/deuxfleurs/golive_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Communication::Website::Deuxfleurs::GoliveJob < Communication::Website::BaseJob
queue_as :mice

def execute
website.deuxfleurs_golive_safely
end
end
33 changes: 18 additions & 15 deletions app/models/communication/website/with_deuxfleurs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Communication::Website::WithDeuxfleurs
extend ActiveSupport::Concern

included do
before_save :deuxfleurs_golive, if: :hosted_with_deuxfleurs?
after_save :deuxfleurs_setup, if: :hosted_with_deuxfleurs?
after_save :deuxfleurs_setup, if: -> { hosted_with_deuxfleurs? && !deuxfleurs_setup_done? }
after_save :deuxfleurs_golive, if: -> { hosted_with_deuxfleurs? && saved_change_to_in_production? && in_production }
end

# 4 options:
Expand All @@ -12,11 +12,13 @@ module Communication::Website::WithDeuxfleurs
# 3. repo exists, deuxfleurs hosting : only create deuxfleurs hosting
# 4. both exists, deuxfleurs hosting needs to change identifier (Waiting for API possibility)
def deuxfleurs_setup
return unless hosted_with_deuxfleurs?
return if deuxfleurs_setup_done?
Communication::Website::Deuxfleurs::SetupJob.perform_later(id)
end

def deuxfleurs_golive
Communication::Website::Deuxfleurs::GoliveJob.perform_later(id)
end

# Appelé par Communication::Website::Deuxfleurs::SetupJob
def deuxfleurs_setup_safely
return unless hosted_with_deuxfleurs?
Expand All @@ -34,6 +36,18 @@ def deuxfleurs_setup_safely
end
end

def deuxfleurs_golive_safely
return unless hosted_with_deuxfleurs? && in_production?
# https://www.test.com -> www.test.com
new_identifier = URI(url).host
should_rename = self.deuxfleurs_identifier != new_identifier

if should_rename && !deuxfleurs.rename_bucket(self.deuxfleurs_identifier, new_identifier)
raise "Failed to rename bucket from #{self.deuxfleurs_identifier} to #{new_identifier}"
end
update(deuxfleurs_identifier: new_identifier)
end

def deuxfleurs_destroy_bucket
return unless hosted_with_deuxfleurs?
deuxfleurs.empty_and_delete_bucket(deuxfleurs_identifier)
Expand All @@ -45,17 +59,6 @@ def deuxfleurs_setup_done?
hosted_with_deuxfleurs? && repository.present? && deuxfleurs_identifier.present?
end

def deuxfleurs_golive
return unless in_production_changed? && in_production
# https://www.test.com -> www.test.com
new_identifier = URI(url).host
if deuxfleurs.rename_bucket(self.deuxfleurs_identifier, new_identifier)
self.deuxfleurs_identifier = new_identifier
else
errors.add :url
end
end

def deuxfleurs_create_bucket
bucket_info = deuxfleurs.create_bucket(deuxfleurs_default_identifier)
update_columns deuxfleurs_identifier: bucket_info[:identifier],
Expand Down
Loading