chore(geo_area): normalize all geo_areas
This commit is contained in:
parent
8b74a6f39b
commit
f6b528e497
2 changed files with 30 additions and 0 deletions
11
app/jobs/migrations/normalize_geo_area_job.rb
Normal file
11
app/jobs/migrations/normalize_geo_area_job.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class Migrations::NormalizeGeoAreaJob < ApplicationJob
|
||||
def perform(ids)
|
||||
GeoArea.where(id: ids).find_each do |geo_area|
|
||||
geojson = RGeo::GeoJSON.decode(geo_area.geometry.to_json, geo_factory: RGeo::Geographic.simple_mercator_factory)
|
||||
geometry = RGeo::GeoJSON.encode(geojson)
|
||||
geo_area.update_column(:geometry, geometry)
|
||||
rescue RGeo::Error::InvalidGeometry
|
||||
geo_area.destroy
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: normalize_geometries'
|
||||
task normalize_geometries: :environment do
|
||||
puts "Running deploy task 'normalize_geometries'"
|
||||
|
||||
progress = ProgressReport.new(GeoArea.count)
|
||||
GeoArea.in_batches(of: 100) do |geo_areas|
|
||||
ids = geo_areas.ids
|
||||
Migrations::NormalizeGeoAreaJob.perform_later(ids)
|
||||
progress.inc(ids.size)
|
||||
end
|
||||
progress.finish
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord
|
||||
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue