Skip to content

Commit

Permalink
feat: use feature flag for monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlin-sfgov committed Jan 8, 2025
1 parent 50156f5 commit d818c17
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion app/services/force/listing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) || {}
Expand Down
15 changes: 9 additions & 6 deletions app/services/google_translation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
7 changes: 5 additions & 2 deletions lib/tasks/translate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d818c17

Please sign in to comment.