Commit c457d53e authored by Mark Chao's avatar Mark Chao

Have timestamp fallback to current time

If historical data is absent, we still want to report the time this
happens.
parent b8fcf994
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
# like for SyncSeatLinkRequestWorker, the params are passed because the values from when # like for SyncSeatLinkRequestWorker, the params are passed because the values from when
# the job was enqueued are necessary. # the job was enqueued are necessary.
def initialize(timestamp: nil, key: default_key, max_users: nil, active_users: nil) def initialize(timestamp: nil, key: default_key, max_users: nil, active_users: nil)
@timestamp = timestamp || historical_data&.recorded_at @timestamp = timestamp || historical_data&.recorded_at || current_time
@key = key @key = key
@max_users = max_users || default_max_count @max_users = max_users || default_max_count
@active_users = active_users || default_active_count @active_users = active_users || default_active_count
...@@ -39,8 +39,8 @@ module Gitlab ...@@ -39,8 +39,8 @@ module Gitlab
def data def data
{ {
timestamp: timestamp&.iso8601, timestamp: timestamp.iso8601,
date: timestamp&.to_date&.to_s, date: timestamp.to_date.to_s,
license_key: key, license_key: key,
max_historical_user_count: max_users, max_historical_user_count: max_users,
active_users: active_users active_users: active_users
...@@ -61,12 +61,16 @@ module Gitlab ...@@ -61,12 +61,16 @@ module Gitlab
def historical_data def historical_data
strong_memoize(:historical_data) do strong_memoize(:historical_data) do
to_timestamp = timestamp || Time.current to_timestamp = timestamp || current_time
license&.historical_data(to: to_timestamp)&.order(:recorded_at)&.last license&.historical_data(to: to_timestamp)&.order(:recorded_at)&.last
end end
end end
def current_time
strong_memoize(:current_time) { Time.current }
end
def default_active_count def default_active_count
historical_data&.active_user_count historical_data&.active_user_count
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment