Skip to content

Commit

Permalink
We should have some error handling
Browse files Browse the repository at this point in the history
https://cloud.google.com/bigquery/docs/error-messages#errortable

If the cache expires and we can't fetch fresh data we should fall back
to a registry that is rebuilt via a nightly job.
  • Loading branch information
hannako committed Sep 20, 2024
1 parent 6abac69 commit be16af9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/services/popular_tasks/data_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ def sql_query(browse_page, raw_date)
SQL
end

def popular_task_data(page, date)
def fresh_popular_task_data(page, date)
todays_popular_tasks_query = sql_query(page, date)

Rails.cache.fetch("popular_tasks_for_#{page}", expires_in: 12.hours) do
client.query(todays_popular_tasks_query).all
end
rescue SomeBigQueryErrorCodes
to_be_implemented_report_error
[]
end

def popular_task_data(page, date)
fresh_popular_task_data(page, date) || to_be_implemented_popular_tasks_registry(page)
end
end
end

0 comments on commit be16af9

Please sign in to comment.