diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-18 00:15:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-18 00:15:21 +0300 |
commit | 513726cb739b0e3f73d85b02e5283ad89bd33814 (patch) | |
tree | f18872dbf13948654bb94535cb59044f16f75f22 /app/models/clusters | |
parent | d409d12963ae433979c54a8ba54f3a1dd4455e52 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/clusters')
-rw-r--r-- | app/models/clusters/agent_token.rb | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/app/models/clusters/agent_token.rb b/app/models/clusters/agent_token.rb index acf13c55ba3..691d628524f 100644 --- a/app/models/clusters/agent_token.rb +++ b/app/models/clusters/agent_token.rb @@ -10,9 +10,6 @@ module Clusters self.table_name = 'cluster_agent_tokens' - # The `UPDATE_USED_COLUMN_EVERY` defines how often the token DB entry can be updated - UPDATE_USED_COLUMN_EVERY = (40.minutes..55.minutes).freeze - belongs_to :agent, class_name: 'Clusters::Agent', optional: false belongs_to :created_by_user, class_name: 'User', optional: true @@ -28,41 +25,5 @@ module Clusters active: 0, revoked: 1 } - - def track_usage - track_values = { last_used_at: Time.current.utc } - - cache_attributes(track_values) - - if can_update_track_values? - log_activity_event!(track_values[:last_used_at]) unless agent.connected? - - # Use update_column so updated_at is skipped - update_columns(track_values) - end - end - - private - - def can_update_track_values? - # Use a random threshold to prevent beating DB updates. - last_used_at_max_age = Random.rand(UPDATE_USED_COLUMN_EVERY) - - real_last_used_at = read_attribute(:last_used_at) - - # Handle too many updates from high token traffic - real_last_used_at.nil? || - (Time.current - real_last_used_at) >= last_used_at_max_age - end - - def log_activity_event!(recorded_at) - Clusters::Agents::CreateActivityEventService.new( # rubocop: disable CodeReuse/ServiceClass - agent, - kind: :agent_connected, - level: :info, - recorded_at: recorded_at, - agent_token: self - ).execute - end end end |