diff --git a/Procfile b/Procfile index 4fbca5566..08cf2001c 100644 --- a/Procfile +++ b/Procfile @@ -1,4 +1,6 @@ web: bundle exec puma -C config/puma.rb worker: bundle exec sidekiq -C config/sidekiq.yml -listener: bundle exec rake translate:subscribe +# TODO: switch listener task back to `subscribe` after we are done logging translate usage +# listener: bundle exec rake translate:subscribe +listener: bundle exec rake translate:log_usage release: bundle exec rake db:migrate diff --git a/app/services/force/listing_service.rb b/app/services/force/listing_service.rb index 4a3668161..9d26a52ac 100644 --- a/app/services/force/listing_service.rb +++ b/app/services/force/listing_service.rb @@ -40,7 +40,9 @@ def self.listing(id, opts = {}) results = Request.new(parse_response: true).cached_get(endpoint, nil, force) listing = process_listing_images(results) - listing['translations'] = log_listing_translations(listing, opts[:rake_task]) + if Rails.configuration.unleash.is_enabled? 'LogGoogleCloudTranslateUsage' + listing['translations'] = log_listing_translations(listing, opts[:rake_task]) + end if Rails.configuration.unleash.is_enabled? 'GoogleCloudTranslate' listing['translations'] = get_listing_translations(listing) || {} diff --git a/app/services/google_translation_service.rb b/app/services/google_translation_service.rb index 6745da0e5..7bc838ccb 100644 --- a/app/services/google_translation_service.rb +++ b/app/services/google_translation_service.rb @@ -82,12 +82,15 @@ def transform_translations_for_caching(listing_id, keys, translations, last_modi # uses the values from that object and the api returns 1 for each key return_value = { LastModifiedDate: last_modified } - # additional timestamps to log potential usage of translating during prefetch rake tasks - return_value = { - **return_value, - LastModifiedDateForPrefetch10Min: last_modified, - LastModifiedDateForPrefetchDaily: last_modified, - } + # additional timestamps to log potential usage of + # translating during prefetch rake tasks + if Rails.configuration.unleash.is_enabled? 'LogGoogleCloudTranslateUsage' + return_value = { + **return_value, + LastModifiedDateForPrefetch10Min: last_modified, + LastModifiedDateForPrefetchDaily: last_modified, + } + end translations.each do |target| target[:translation].each_with_index do |value, i| diff --git a/lib/tasks/translate.rake b/lib/tasks/translate.rake index ad4b42e13..a92f6604d 100644 --- a/lib/tasks/translate.rake +++ b/lib/tasks/translate.rake @@ -46,8 +46,11 @@ namespace :translate do # rubocop:disable Metrics/BlockLength task subscribe: :environment do subscriber = Force::EventSubscriberTranslateService.new - # TODO: re-enable after we have logged enough data - # subscriber.listen_and_process_events + subscriber.listen_and_process_events + end + + task log_usage: :environment do + subscriber = Force::EventSubscriberTranslateService.new subscriber.listen_and_log_events end end