Path: blob/master/src/packages/conat/project/project-status.ts
1452 views
/*1Broadcast project status whenever it updates.2*/34import { projectSubject } from "@cocalc/conat/names";5import { conat } from "@cocalc/conat/client";6import { getLogger } from "@cocalc/conat/client";7import { type Subscription } from "@cocalc/conat/core/client";89const SERVICE_NAME = "project-status";10const logger = getLogger("project:project-status");1112function getSubject({ project_id, compute_server_id }) {13return projectSubject({14project_id,15compute_server_id,16service: SERVICE_NAME,17});18}1920// publishes status updates when they are emitted.21export async function createPublisher({22project_id,23compute_server_id,24projectStatusServer,25}) {26const client = await conat();27const subject = getSubject({ project_id, compute_server_id });28logger.debug("publishing status updates on ", { subject });29projectStatusServer.on("status", (status) => {30logger.debug("publishing updated status", status);31client.publishSync(subject, status);32});33}3435// async iterator over the status updates:36export async function get({37project_id,38compute_server_id,39}): Promise<Subscription> {40const client = await conat();41const subject = getSubject({ project_id, compute_server_id });42return await client.subscribe(subject);43}444546