runBg -> backend II

This commit is contained in:
Ruben Fiszel
2025-11-29 16:03:58 +00:00
parent a64a6eadd9
commit 732f23376a
5 changed files with 26 additions and 27 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ export { WebSocketServer, WebSocket } from "npm:ws";
export * as getPort from "npm:get-port@7.1.0";
export * as open from "npm:open";
export * as esMain from "npm:es-main";
export * as windmillUtils from "jsr:@windmill-labs/shared-utils@1.0.9";
export * as windmillUtils from "jsr:@windmill-labs/shared-utils@1.0.10";
import { OpenAPI } from "./gen/index.ts";
+18 -18
View File
@@ -407,23 +407,23 @@ async function dev(opts: DevOptions) {
runnableId,
args
);
log.info(colors.gray(`[runBg] Job started: ${uuid}`));
log.info(colors.gray(`[backend] Job started: ${uuid}`));
const result = await waitForJob(workspaceId, uuid);
return { uuid, result };
};
switch (type) {
case "runBg": {
case "backend": {
// Run a runnable synchronously and wait for result
log.info(colors.blue(`[runBg] Running runnable: ${runnable_id}`));
log.info(colors.blue(`[backend] Running runnable: ${runnable_id}`));
try {
const { result } = await runAndWaitForResult(runnable_id, v);
respond("runBgRes", result, false);
respond("backendRes", result, false);
} catch (error: any) {
log.error(colors.red(`[runBg] Error: ${error.message}`));
log.error(colors.red(`[backend] Error: ${error.message}`));
respond(
"runBgRes",
"backendRes",
{ message: error.message, stack: error.stack },
true
);
@@ -431,10 +431,10 @@ async function dev(opts: DevOptions) {
break;
}
case "runBgAsync": {
case "backendAsync": {
// Run a runnable asynchronously and return job ID immediately
log.info(
colors.blue(`[runBgAsync] Running runnable async: ${runnable_id}`)
colors.blue(`[backendAsync] Running runnable async: ${runnable_id}`)
);
try {
const runnables = await loadRunnables();
@@ -451,27 +451,27 @@ async function dev(opts: DevOptions) {
runnable_id,
v
);
log.info(colors.gray(`[runBgAsync] Job started: ${uuid}`));
log.info(colors.gray(`[backendAsync] Job started: ${uuid}`));
// Return job ID immediately
respond("runBgAsyncRes", uuid, false);
respond("backendAsyncRes", uuid, false);
// Wait for result in the background and send it when done
waitForJob(workspaceId, uuid)
.then((result) => {
respond("runBgRes", result, false);
respond("backendRes", result, false);
})
.catch((error: any) => {
respond(
"runBgRes",
"backendRes",
{ message: error.message, stack: error.stack },
true
);
});
} catch (error: any) {
log.error(colors.red(`[runBgAsync] Error: ${error.message}`));
log.error(colors.red(`[backendAsync] Error: ${error.message}`));
respond(
"runBgAsyncRes",
"backendAsyncRes",
{ message: error.message, stack: error.stack },
true
);
@@ -484,11 +484,11 @@ async function dev(opts: DevOptions) {
log.info(colors.blue(`[waitJob] Waiting for job: ${jobId}`));
try {
const result = await waitForJob(workspaceId, jobId);
respond("runBgRes", result, false);
respond("backendRes", result, false);
} catch (error: any) {
log.error(colors.red(`[waitJob] Error: ${error.message}`));
respond(
"runBgRes",
"backendRes",
{ message: error.message, stack: error.stack },
true
);
@@ -501,11 +501,11 @@ async function dev(opts: DevOptions) {
log.info(colors.blue(`[getJob] Getting job status: ${jobId}`));
try {
const result = await getJobStatus(workspaceId, jobId);
respond("runBgRes", result, false);
respond("backendRes", result, false);
} catch (error: any) {
log.error(colors.red(`[getJob] Error: ${error.message}`));
respond(
"runBgRes",
"backendRes",
{ message: error.message, stack: error.stack },
true
);
+6 -6
View File
@@ -19,8 +19,8 @@ function initWebSocket() {
ws.onmessage = (event) => {
const data = JSON.parse(event.data)
if (data.type === 'runBgRes' || data.type === 'runBgAsyncRes') {
console.log('Message from WebSocket runBg', data)
if (data.type === 'backendRes' || data.type === 'backendAsyncRes') {
console.log('Message from WebSocket backend', data)
const job = reqs[data.reqId]
if (job) {
const result = data.result
@@ -57,22 +57,22 @@ async function doRequest(type: string, o: object) {
})
}
export const runBg = new Proxy(
export const backend = new Proxy(
{},
{
get(_, runnable_id: string) {
return (v: any) => {
return doRequest('runBg', { runnable_id, v })
return doRequest('backend', { runnable_id, v })
}
}
})
export const runBgAsync = new Proxy(
export const backendAsync = new Proxy(
{},
{
get(_, runnable_id: string) {
return (v: any) => {
return doRequest('runBgAsync', { runnable_id, v })
return doRequest('backendAsync', { runnable_id, v })
}
}
})
@@ -5,7 +5,7 @@ import { exec } from 'child_process'
import { promisify } from 'util'
const execAsync = promisify(exec)
const VERSION = '1.0.9'
const VERSION = '1.0.10'
export default defineConfig({
build: {
@@ -1,7 +1,6 @@
import type { ScriptLang } from '../../gen/types.gen'
import type { Schema } from '../../common'
import { schemaToTsType } from '../../schema'
import { capitalize } from '../../sharedUtils'
import { isRunnableByName, isRunnableByPath, type RunnableWithFields } from '../apps/inputType'
import type { InlineScript } from '../apps/sharedTypes'