Skip to content

Instantly share code, notes, and snippets.

@pnispel
Last active October 23, 2017 21:09
Show Gist options
  • Save pnispel/1e867bba153072b6f5843eae0e624c96 to your computer and use it in GitHub Desktop.
Save pnispel/1e867bba153072b6f5843eae0e624c96 to your computer and use it in GitHub Desktop.
Rebuild DrawingRevision.zip_url for company
class RebuildDrawingRevisionZipUrls
def self.rebuild_drawing_revision_zip_urls_for_companies(company_ids)
Company.where(id: company_ids, use_govcloud: true).each do |company|
DrawingRevision.joins(drawing_area: {project: :company}).
where("drawing_revisions.zip_url IS NOT NULL AND companies.id = ?", company.id).
find_each do | drawing_revision |
zip_url = build_url(drawing_revision.s3_zip_key, drawing_revision.zip_profile)
drawing_revision.update_column('zip_url', zip_url) if zip_url
end
end
end
def self.build_url(key, zip_profile)
binder_client.signed_url(
profile: 'govcloud',
key: key,
bucket: zip_profile.present? ? 'lambda' : 'pro-core.com',
)
end
def self.binder_client
Binder::Client.new(
secret: Rails.application.secrets.binder_secret,
base_url: Rails.application.config.binder_host,
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment