Class: Clusters::Agent

Inherits:
ApplicationRecord show all
Defined in:
app/models/clusters/agent.rb

Constant Summary collapse

INACTIVE_AFTER =
1.hour.freeze
ACTIVITY_EVENT_LIMIT =
200

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Instance Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#activity_event_deletion_cutoffObject


44
45
46
47
48
49
# File 'app/models/clusters/agent.rb', line 44

def activity_event_deletion_cutoff
  # Order is defined by the association
  activity_events
    .offset(ACTIVITY_EVENT_LIMIT - 1)
    .pick(:recorded_at)
end

#connected?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'app/models/clusters/agent.rb', line 40

def connected?
  agent_tokens.active.where("last_used_at > ?", INACTIVE_AFTER.ago).exists?
end

#has_access_to?(requested_project) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/models/clusters/agent.rb', line 36

def has_access_to?(requested_project)
  requested_project == project
end