mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Merge branch 'feat/tool-first-workflow'
Resolved conflict in worker.ts: kept remote refactored worker (v2 process, scratch paths, extra outputs, metrics) and re-applied the auto-save removal from the feature branch.
This commit is contained in:
@@ -18,7 +18,7 @@ import sharp from "sharp";
|
||||
import { env } from "../config.js";
|
||||
import { db, schema } from "../db/index.js";
|
||||
import { recordChildOutcome } from "../jobs/batch-progress.js";
|
||||
import { getFlowProducer, waitForJob } from "../jobs/enqueue.js";
|
||||
import { getFlowProducer, injectTraceContext, waitForJob } from "../jobs/enqueue.js";
|
||||
import { type Pool, queueName, type ToolJobData } from "../jobs/types.js";
|
||||
import { autoOrient } from "../lib/auto-orient.js";
|
||||
import { getSecurityHeaders } from "../lib/csp.js";
|
||||
@@ -39,6 +39,16 @@ interface ParsedFile {
|
||||
filename: string;
|
||||
}
|
||||
|
||||
/** Recursively inject OTel trace context into every node of a FlowJob tree. */
|
||||
function injectTraceContextIntoFlow(node: FlowJob): void {
|
||||
injectTraceContext(node.data as ToolJobData);
|
||||
if (node.children) {
|
||||
for (const child of node.children) {
|
||||
injectTraceContextIntoFlow(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function registerBatchRoutes(app: FastifyInstance): Promise<void> {
|
||||
app.post(
|
||||
"/api/v1/tools/:toolId/batch",
|
||||
@@ -297,6 +307,9 @@ export async function registerBatchRoutes(app: FastifyInstance): Promise<void> {
|
||||
.set({ settings: { flowChildCount: flowChildren.length } })
|
||||
.where(eq(schema.jobs.id, parentId));
|
||||
|
||||
// Inject OTel trace context into every node of the batch flow tree
|
||||
injectTraceContextIntoFlow(batchTree);
|
||||
|
||||
await getFlowProducer().add(batchTree);
|
||||
|
||||
// ── Wait for completion and stream ZIP ─────────────────────────
|
||||
|
||||
@@ -17,7 +17,7 @@ import { z } from "zod";
|
||||
import { env } from "../config.js";
|
||||
import { db, schema } from "../db/index.js";
|
||||
import { recordChildOutcome } from "../jobs/batch-progress.js";
|
||||
import { getFlowProducer, waitForJob } from "../jobs/enqueue.js";
|
||||
import { getFlowProducer, injectTraceContext, waitForJob } from "../jobs/enqueue.js";
|
||||
import { type Pool, queueName, type ToolJobData } from "../jobs/types.js";
|
||||
import { trackEvent } from "../lib/analytics.js";
|
||||
import { autoOrient } from "../lib/auto-orient.js";
|
||||
@@ -78,6 +78,16 @@ interface ParsedStep {
|
||||
*/
|
||||
const PASSWORD_TOOLS = new Set(["protect-pdf", "unlock-pdf"]);
|
||||
|
||||
/** Recursively inject OTel trace context into every node of a FlowJob tree. */
|
||||
function injectTraceContextIntoFlow(node: FlowJob): void {
|
||||
injectTraceContext(node.data as ToolJobData);
|
||||
if (node.children) {
|
||||
for (const child of node.children) {
|
||||
injectTraceContextIntoFlow(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a FlowJob tree for a single-file pipeline.
|
||||
*
|
||||
@@ -405,6 +415,9 @@ export async function registerPipelineRoutes(app: FastifyInstance): Promise<void
|
||||
settings: {},
|
||||
});
|
||||
|
||||
// Inject OTel trace context into every node of the flow tree
|
||||
injectTraceContextIntoFlow(tree);
|
||||
|
||||
// Add the flow to BullMQ
|
||||
await getFlowProducer().add(tree);
|
||||
|
||||
@@ -913,6 +926,9 @@ export async function registerPipelineRoutes(app: FastifyInstance): Promise<void
|
||||
.set({ settings: { flowChildCount: perFileChildren.length } })
|
||||
.where(eq(schema.jobs.id, parentId));
|
||||
|
||||
// Inject OTel trace context into every node of the batch flow tree
|
||||
injectTraceContextIntoFlow(batchTree);
|
||||
|
||||
await getFlowProducer().add(batchTree);
|
||||
|
||||
// Wait for batch completion
|
||||
|
||||
Reference in New Issue
Block a user