Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Regeration script #45

Merged
merged 3 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Institution < ApplicationRecord
include PgSearch::Model

pg_search_scope :search_by_name, against: :name, using: :dmetaphone
pg_search_scope :search_by_area, against: %i[county municipality town], using: :dmetaphone
pg_search_scope :search_by_area, against: %i[county municipality town]
pg_search_scope :search_by_class_profiles, against: :class_profiles, using: {tsearch: {any_word: true} }
pg_search_scope :search_by_sports, against: :sports, using: {tsearch: {any_word: true} }
pg_search_scope :search_by_foreign_languages, against: :foreign_languages, using: {tsearch: {any_word: true} }
Expand Down
55 changes: 55 additions & 0 deletions regeneration_script.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#This script should be run using rails runner not ruby

#we don't want to log from queries we are running in this scirpt
ActiveRecord::Base.logger = nil


#This function waits until all jobs have finished and we can proceed to the next step of the process.
def wait_for_all_jobs_to_finish(job_name)

counter = 0
loop {
jobs_left = GoodJob::Execution.display_all.size
if jobs_left == 0
puts "#{job_name} finished and took #{1 * counter} seconds"
break
else
puts "waiting for #{job_name} to finish, #{1 * counter} seconds elapsed, there are #{jobs_left} jobs to be finished"
sleep(1)
end

counter += 1
}
end

puts "started running migrations"

#run all migrations
system("rails", "db:migrate")

puts "finished running migrations"

#First delete all existing institution types and institutions
puts "deleted all institutions and insitutions types"
Institution.delete_all
InstitutionType.delete_all

puts "started CreateInstitutionTypesJob job"
#Create new types from the RSPO API
CreateInstitutionTypesJob.perform_now
wait_for_all_jobs_to_finish("CreateInstitutionTypesJob")

puts "started EnqueParallelInstitutionCreateJob job"

#Create Instituions from RSPO API
EnqueParallelInstitutionCreateJob.perform_now
wait_for_all_jobs_to_finish("EnqueParallelInstitutionCreateJob")

puts "started CreateGdyniaExtraDataRecordsJob jobs"

#Fill the existing records with extra data from Gdynia API
CreateGdyniaExtraDataRecordsJob.perform_now
wait_for_all_jobs_to_finish("CreateGdyniaExtraDataRecordsJob")


puts "finished"