Skip to content

Commit

Permalink
chore: support runner ip display (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
thezzisu authored Apr 20, 2024
1 parent aacab4d commit dc81b4d
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .yarn/versions/61c36991.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
releases:
"@aoi-js/common": minor
"@aoi-js/frontend": patch
"@aoi-js/server": patch
20 changes: 12 additions & 8 deletions apps/frontend/src/components/solution/SolutionDetailsRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<VCard variant="flat">
<VCardSubtitle>{{ t('term.jobs') }}</VCardSubtitle>
<VCardText>
<VExpansionPanels variant="accordion">
<VExpansionPanels v-if="value.jobs" variant="accordion">
<VExpansionPanel v-for="(job, i) in value.jobs" :key="i">
<!-- A Job named 'job' -->
<VExpansionPanelTitle>
Expand All @@ -21,7 +21,7 @@
</VExpansionPanelTitle>
<VExpansionPanelText>
<VCardSubtitle>{{ t('term.tests') }}</VCardSubtitle>
<VExpansionPanels class="pb-4">
<VExpansionPanels v-if="job.tests" class="pb-4">
<VExpansionPanel v-for="(test, i) in job.tests" :key="i">
<!-- A Subtask named 'subtask' -->
<VExpansionPanelTitle>
Expand All @@ -40,20 +40,24 @@
</VCol>
</VRow>
</VExpansionPanelTitle>
<VExpansionPanelText>
<VExpansionPanelText v-if="test.summary">
<MarkdownRenderer :md="test.summary" />
</VExpansionPanelText>
</VExpansionPanel>
</VExpansionPanels>
<VDivider />
<VCardSubtitle>{{ t('term.summary') }}</VCardSubtitle>
<MarkdownRenderer :md="job.summary" class="pa-4" />
<template v-if="job.summary">
<VDivider />
<VCardSubtitle>{{ t('term.summary') }}</VCardSubtitle>
<MarkdownRenderer :md="job.summary" class="pa-4" />
</template>
</VExpansionPanelText>
</VExpansionPanel>
</VExpansionPanels>
</VCardText>
<VCardSubtitle>{{ t('term.summary') }}</VCardSubtitle>
<MarkdownRenderer :md="value.summary" class="pa-4" />
<template v-if="value.summary">
<VCardSubtitle>{{ t('term.summary') }}</VCardSubtitle>
<MarkdownRenderer :md="value.summary" class="pa-4" />
</template>
</VCard>
</template>

Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ term:
filter: Filter
access-level: Access Level
rules: Rules
ip: IP

common:
created-at: Created at
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/locales/zh-Hans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ term:
filter: 过滤
access-level: 访问等级
rules: 规则
ip: IP 地址

common:
created-at: 创建于
Expand Down
5 changes: 4 additions & 1 deletion apps/frontend/src/pages/org/[orgId]/admin/runner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<code>{{ item._id }}</code>
</template>
<template v-slot:[`item.createdAt`]="{ item }">
<VChip :text="new Date(item.createdAt).toLocaleString()" />
<VChip :text="denseDateString(item.createdAt)" />
</template>
<template v-slot:[`item.accessedAt`]="{ item }">
<VChip v-bind="runnerLastAccessAttrs(item.accessedAt)" />
Expand Down Expand Up @@ -67,6 +67,7 @@
</VCardText>
<SettingsEditor
:endpoint="`org/${orgId}/admin/runner/${editRunnerId}`"
allow-delete
@updated="(editDialog = false), runners.execute()"
>
<template v-slot="scoped">
Expand All @@ -90,6 +91,7 @@ import type { IRunner } from '@/types'
import { useAsyncTask } from '@/utils/async'
import { http } from '@/utils/http'
import { runnerLastAccessAttrs } from '@/utils/org/runner'
import { denseDateString } from '@/utils/time'
const props = defineProps<{
orgId: string
Expand All @@ -116,6 +118,7 @@ const headers = [
{ title: t('term.name'), key: 'name' },
{ title: t('term.version'), key: 'version' },
{ title: t('term.message'), key: 'message' },
{ title: t('term.ip'), key: 'ip' },
{ title: t('common.created-at'), key: 'createdAt' },
{ title: t('common.accessed-at'), key: 'accessedAt' },
{ title: t('term.labels'), key: '_labels' },
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/utils/org/runner.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { prettyMs } from '../time'
import { denseDateString, prettyMs } from '../time'

export function runnerLastAccessAttrs(accessedAt: number) {
const now = Date.now()
const offline = now - accessedAt > 1000 * 60 * 5
const color = offline ? 'red' : 'green'
const text = offline ? new Date(accessedAt).toLocaleString() : prettyMs(now - accessedAt)
const text = offline ? denseDateString(accessedAt) : prettyMs(now - accessedAt)
return { text, color }
}
1 change: 1 addition & 0 deletions apps/server/src/db/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IRunner {
key: string
version: string
message: string
ip: string

createdAt: number
accessedAt: number
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/routes/org/admin/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const orgAdminRunnerRoutes = defineRoutes(async (s) => {
name: T.String(),
version: T.String(),
message: T.String(),
ip: T.String(),
createdAt: T.Number(),
accessedAt: T.Number()
})
Expand Down Expand Up @@ -68,6 +69,7 @@ export const orgAdminRunnerRoutes = defineRoutes(async (s) => {
name: T.String(),
version: T.String(),
message: T.String(),
ip: T.String(),
createdAt: T.Number(),
accessedAt: T.Number()
})
Expand Down
16 changes: 13 additions & 3 deletions apps/server/src/routes/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function updateAccessedAt(req: FastifyRequest, runner: IRunner) {
{
$set: {
accessedAt: now,
version: req.headers['user-agent']
version: req.headers['user-agent'],
ip: req.ip
}
},
{ ignoreUndefined: true }
Expand Down Expand Up @@ -98,6 +99,7 @@ export const runnerRoutes = defineRoutes(async (s) => {
labels: req.body.labels,
version: req.body.version,
message: '',
ip: req.ip,
key: runnerKey,
createdAt: Date.now(),
accessedAt: Date.now()
Expand All @@ -112,14 +114,22 @@ export const runnerRoutes = defineRoutes(async (s) => {
schema: {
body: T.Partial(
T.StrictObject({
version: T.String(),
message: T.String()
})
)
}
},
async (req) => {
await runners.updateOne({ _id: req.inject(kRunnerContext)._runner._id }, { $set: req.body })
await runners.updateOne(
{ _id: req.inject(kRunnerContext)._runner._id },
{
$set: {
version: req.headers['user-agent'],
message: req.body.message,
ip: req.ip
}
}
)
return {}
}
)
Expand Down
10 changes: 5 additions & 5 deletions libs/common/src/schemas/solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const SSolutionDetailsTestSchema = Type.Object({
score: Type.Number(),
scoreScale: Type.Optional(Type.Number()),
status: Type.String(),
summary: Type.String()
summary: Type.Optional(Type.String())
})

export type SolutionDetailsTest = Static<typeof SSolutionDetailsTestSchema>
Expand All @@ -15,16 +15,16 @@ export const SSolutionDetailsJobSchema = Type.Object({
score: Type.Number(),
scoreScale: Type.Optional(Type.Number()),
status: Type.String(),
tests: Type.Array(SSolutionDetailsTestSchema),
summary: Type.String()
tests: Type.Optional(Type.Array(SSolutionDetailsTestSchema)),
summary: Type.Optional(Type.String())
})

export type SolutionDetailsJob = Static<typeof SSolutionDetailsJobSchema>

export const SSolutionDetailsSchema = Type.Object({
version: Type.Integer({ minimum: 1 }),
jobs: Type.Array(SSolutionDetailsJobSchema),
summary: Type.String()
jobs: Type.Optional(Type.Array(SSolutionDetailsJobSchema)),
summary: Type.Optional(Type.String())
})

export type SolutionDetails = Static<typeof SSolutionDetailsSchema>

0 comments on commit dc81b4d

Please sign in to comment.