Created
May 27, 2022 09:23
-
-
Save donrestarone/489e8628ea496bada7f9b940ea6a8e48 to your computer and use it in GitHub Desktop.
example of subdomain based multi-tenancy in Violet Rails: how to access subdomains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :clear_old_ahoy_visits => [:environment] do | |
Subdomain.all.each do |subdomain| | |
Apartment::Tenant.switch subdomain.name do | |
if subdomain.purge_visits_every != Subdomain::TRACKING_PURGE_MAPPING[:never] | |
p "clearing old ahoy visits for [#{subdomain.name}] @ #{Time.now}" | |
visits = Ahoy::Visit.where("started_at < ?", eval("#{subdomain.purge_visits_every}.ago")) | |
p "#{visits.size} visits eligible for deletion" | |
visits.in_batches do |batch| | |
p "cleared old ahoy visits @ #{Time.now}" | |
batch.destroy_all | |
end | |
p "clearing old ahoy events @ #{Time.now}" | |
events = Ahoy::Event.where("time < ?", eval("#{subdomain.purge_visits_every}.ago")) | |
p "#{events.size} events eligible for deletion" | |
events.in_batches do |batch| | |
batch.destroy_all | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment