diff options
Diffstat (limited to 'app/assets/javascripts/clusters_list')
-rw-r--r-- | app/assets/javascripts/clusters_list/clusters_util.js | 23 | ||||
-rw-r--r-- | app/assets/javascripts/clusters_list/components/agents.vue | 34 |
2 files changed, 27 insertions, 30 deletions
diff --git a/app/assets/javascripts/clusters_list/clusters_util.js b/app/assets/javascripts/clusters_list/clusters_util.js index e2d01723dde..ee36a295513 100644 --- a/app/assets/javascripts/clusters_list/clusters_util.js +++ b/app/assets/javascripts/clusters_list/clusters_util.js @@ -1,3 +1,5 @@ +import { ACTIVE_CONNECTION_TIME } from './constants'; + export function generateAgentRegistrationCommand({ name, token, version, address }) { return `helm repo add gitlab https://charts.gitlab.io helm repo update @@ -12,3 +14,24 @@ helm upgrade --install ${name} gitlab/gitlab-agent \\ export function getAgentConfigPath(clusterAgentName) { return `.gitlab/agents/${clusterAgentName}`; } + +export function getAgentLastContact(tokens = []) { + let lastContact = null; + tokens.forEach((token) => { + const lastContactToDate = new Date(token.lastUsedAt).getTime(); + if (lastContactToDate > lastContact) { + lastContact = lastContactToDate; + } + }); + return lastContact; +} + +export function getAgentStatus(lastContact) { + if (lastContact) { + const now = new Date().getTime(); + const diff = now - lastContact; + + return diff >= ACTIVE_CONNECTION_TIME ? 'inactive' : 'active'; + } + return 'unused'; +} diff --git a/app/assets/javascripts/clusters_list/components/agents.vue b/app/assets/javascripts/clusters_list/components/agents.vue index 8a4a81d3e96..36f0f8e61ba 100644 --- a/app/assets/javascripts/clusters_list/components/agents.vue +++ b/app/assets/javascripts/clusters_list/components/agents.vue @@ -3,13 +3,9 @@ import { GlAlert, GlKeysetPagination, GlLoadingIcon, GlBanner } from '@gitlab/ui import { s__ } from '~/locale'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; -import { - MAX_LIST_COUNT, - ACTIVE_CONNECTION_TIME, - AGENT_FEEDBACK_ISSUE, - AGENT_FEEDBACK_KEY, -} from '../constants'; +import { MAX_LIST_COUNT, AGENT_FEEDBACK_ISSUE, AGENT_FEEDBACK_KEY } from '../constants'; import getAgentsQuery from '../graphql/queries/get_agents.query.graphql'; +import { getAgentLastContact, getAgentStatus } from '../clusters_util'; import AgentEmptyState from './agent_empty_state.vue'; import AgentTable from './agent_table.vue'; @@ -88,8 +84,8 @@ export default { if (list) { list = list.map((agent) => { const configFolder = this.folderList[agent.name]; - const lastContact = this.getLastContact(agent); - const status = this.getStatus(lastContact); + const lastContact = getAgentLastContact(agent?.tokens?.nodes); + const status = getAgentStatus(lastContact); return { ...agent, configFolder, lastContact, status }; }); } @@ -141,28 +137,6 @@ export default { }); } }, - getLastContact(agent) { - const tokens = agent?.tokens?.nodes; - let lastContact = null; - if (tokens?.length) { - tokens.forEach((token) => { - const lastContactToDate = new Date(token.lastUsedAt).getTime(); - if (lastContactToDate > lastContact) { - lastContact = lastContactToDate; - } - }); - } - return lastContact; - }, - getStatus(lastContact) { - if (lastContact) { - const now = new Date().getTime(); - const diff = now - lastContact; - - return diff > ACTIVE_CONNECTION_TIME ? 'inactive' : 'active'; - } - return 'unused'; - }, emitAgentsLoaded() { const count = this.agents?.project?.clusterAgents?.count; this.$emit('onAgentsLoad', count); |