Skip to content

Commit

Permalink
feat: show pid, version and dagger version in agent list
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jan 12, 2024
1 parent 435bd8a commit 6589af0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fluentci # Run the pipeline
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.10.7
Version: 0.10.8

Description:

Expand Down
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import publish from "./src/cmd/publish.ts";
import startAgent, { listAgents } from "./src/cmd/agent.ts";
import whoami from "./src/cmd/whoami.ts";
import { brightGreen } from "./deps.ts";
import { VERSION } from "./src/consts.ts";

export async function main() {
await new Command()
.name("fluentci")
.version("0.10.7")
.version(VERSION)
.description(
`
.
Expand Down
38 changes: 29 additions & 9 deletions src/cmd/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ import {
RUNNER_URL,
FLUENTCI_EVENTS_URL,
BUILD_DIR,
VERSION,
} from "../consts.ts";
import { formatBytes, getAccessToken, isLogged } from "../utils.ts";
import {
formatBytes,
getAccessToken,
getDaggerVersion,
isLogged,
} from "../utils.ts";
import { hostname, release, cpus, arch, totalmem, platform } from "node:os";
import { Agent } from "../types.ts";
import O from "https://esm.sh/v133/mimic-fn@4.0.0/denonext/mimic-fn.mjs";

async function startAgent() {
console.log(`
Expand Down Expand Up @@ -201,10 +208,13 @@ async function spawnFluentCI(

async function getWebSocketUuid(agentId: string) {
const accessToken = await getAccessToken();
const daggerVersion = await getDaggerVersion();
const uuid = await fetch(
`${FLUENTCI_EVENTS_URL}/auth?agent_id=${agentId}&hostname=${hostname()}&release=${release()}&cpus=${
cpus().length
}&arch=${arch()}&totalmem=${totalmem()}&platform=${platform()}`,
}&arch=${arch()}&totalmem=${totalmem()}&platform=${platform()}&version=${VERSION}&pid=${
Deno.pid
}&daggerversion=${daggerVersion}`,
{
method: "GET",
headers: {
Expand All @@ -221,7 +231,7 @@ export async function listAgents() {
`https://api.fluentci.io/validate?token=${accessToken}`
).then((res) => res.text());
const agents: Agent[] = await fetch(
`${FLUENTCI_EVENTS_URL}?id=${userId}`
`${FLUENTCI_EVENTS_URL}/agents?id=${userId}`
).then((res) => res.json());

if (!agents.length) {
Expand All @@ -233,19 +243,29 @@ export async function listAgents() {
table.header([
"NAME",
"HOSTNAME",
"RELEASE",
"CPUs",
"ARCH",
"RAM",
"OS",
"VERSION",
"PID",
"DAGGER",
"STARTED AT",
]);

for (const agent of agents) {
const rows = Object.values(agent);
rows[5] = formatBytes(rows[5] as number);
rows[7] = dayjs(rows[7]).fromNow();
table.push(rows.map((x) => (x === 0 || x === "0 Bytes" ? "" : x)));
const totalmem = agent.totalmem === 0 ? "" : formatBytes(agent.totalmem);
table.push([
agent.agent_id,
agent.hostname,
agent.cpus,
agent.arch,
totalmem,
agent.platform,
agent.version,
agent.pid,
agent.daggerVersion,
dayjs(agent.startedAt).fromNow(),
]);
}

table.render();
Expand Down
2 changes: 2 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { dir } from "../deps.ts";

export const VERSION = "0.10.8";

export const BASE_URL = "https://api.fluentci.io/v1";

const FLUENTCI_HOST = Deno.env.get("FLUENTCI_HOST") || "vm.fluentci.io";
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ export const LogEventSchema = z.object({
export const AgentSchema = z.object({
agent_id: z.string(),
hostname: z.string(),
release: z.string(),
cpus: z.number(),
arch: z.string(),
totalmem: z.number(),
platform: z.string(),
release: z.string(),
version: z.string(),
pid: z.number(),
daggerVersion: z.string(),
startedAt: z.string(),
});

Expand Down
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ export function extractVersion(name: string): string {
}
return "latest";
}

export async function getDaggerVersion(): Promise<string> {
const command = new Deno.Command("dagger", {
args: ["version"],
stdout: "piped",
stderr: "piped",
});
const { stdout } = await command.output();
const version = new TextDecoder().decode(stdout).trim().split(" ")[1];
return version;
}

0 comments on commit 6589af0

Please sign in to comment.