diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /app/models/clusters/agent.rb | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'app/models/clusters/agent.rb')
-rw-r--r-- | app/models/clusters/agent.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/clusters/agent.rb b/app/models/clusters/agent.rb index cf6d95fc6df..98490a13351 100644 --- a/app/models/clusters/agent.rb +++ b/app/models/clusters/agent.rb @@ -4,6 +4,8 @@ module Clusters class Agent < ApplicationRecord self.table_name = 'cluster_agents' + INACTIVE_AFTER = 1.hour.freeze + belongs_to :created_by_user, class_name: 'User', optional: true belongs_to :project, class_name: '::Project' # Otherwise, it will load ::Clusters::Project @@ -16,6 +18,8 @@ module Clusters has_many :project_authorizations, class_name: 'Clusters::Agents::ProjectAuthorization' has_many :authorized_projects, class_name: '::Project', through: :project_authorizations, source: :project + has_many :activity_events, -> { in_timeline_order }, class_name: 'Clusters::Agents::ActivityEvent', inverse_of: :agent + scope :ordered_by_name, -> { order(:name) } scope :with_name, -> (name) { where(name: name) } @@ -31,5 +35,9 @@ module Clusters def has_access_to?(requested_project) requested_project == project end + + def active? + agent_tokens.where("last_used_at > ?", INACTIVE_AFTER.ago).exists? + end end end |