-
Notifications
You must be signed in to change notification settings - Fork 1
fix(worker): two-level fan-out for description generation (fixes #488) #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7585e8e
Fix #488: Two-level fan-out for description generation to avoid step …
6c74885
fix: simplify process-descriptions-group to avoid redundant batching
dd7567d
fix: resolve TypeScript errors
c9905ec
fix: use distinct step name for description group spawning
0170856
refactor: move description group spawning outside step.run for consis…
f82d839
perf: parallelize description batch spawning in process-descriptions-…
028039a
fix: register processDescriptionsGroups in worker.ts
173ffe4
perf: use Promise.allSettled in processDescriptionsGroups
9567732
fix: throw error when description batches fail in processDescriptions…
6240b5d
fix: throw on any description group failure, not just all-of-them
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { defineWorkflowSpec } from "openworkflow"; | ||
| import z from "zod"; | ||
|
|
||
| /** | ||
| * Maximum number of update-descriptions sub-workflow calls per group. | ||
| * Keep this low enough that the group workflow itself stays well under | ||
| * the OpenWorkflow step limit (1000), while ensuring the number of groups | ||
| * spawned by process-files also stays bounded. | ||
| */ | ||
| export const DESCRIPTION_BATCHES_PER_GROUP = 50; | ||
|
|
||
| export const processDescriptionsGroupsSpec = defineWorkflowSpec({ | ||
| name: "process-descriptions-groups", | ||
| version: "1.0.0", | ||
| retryPolicy: { | ||
| initialInterval: "1s", | ||
| backoffCoefficient: 2, | ||
| maximumInterval: "30s", | ||
| maximumAttempts: 3, | ||
| }, | ||
| schema: z.object({ | ||
| graphId: z.string(), | ||
| entityIds: z.array(z.string()), | ||
| relationshipIds: z.array(z.string()), | ||
| }), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { defineWorkflow } from "openworkflow"; | ||
| import { updateDescriptionsSpec } from "./update-descriptions-spec"; | ||
| import { processDescriptionsGroupsSpec } from "./process-descriptions-group-spec"; | ||
| import { chunkItems } from "../lib/chunk"; | ||
| import { DESCRIPTION_BATCH_SIZE } from "../lib/description-workflow"; | ||
|
|
||
| /** | ||
| * Spawns update-descriptions sub-workflows for a slice of entity/relationship IDs. | ||
| * Each process-descriptions-group call handles at most DESCRIPTION_BATCHES_PER_GROUP | ||
| * worth of IDs (pre-sliced by process-files), so this simply batches them for | ||
| * update-descriptions without additional grouping. | ||
| */ | ||
| export const processDescriptionsGroups = defineWorkflow( | ||
| processDescriptionsGroupsSpec, | ||
| async ({ input, step }) => { | ||
| const entityIdBatches = chunkItems(input.entityIds, DESCRIPTION_BATCH_SIZE); | ||
| const relationshipIdBatches = chunkItems(input.relationshipIds, DESCRIPTION_BATCH_SIZE); | ||
|
|
||
| const entityPromises = entityIdBatches.map((entityIds) => | ||
| step.runWorkflow(updateDescriptionsSpec, { | ||
| graphId: input.graphId, | ||
| entityIds, | ||
| relationshipIds: [], | ||
| }) | ||
| ); | ||
|
|
||
| const relationshipPromises = relationshipIdBatches.map((relationshipIds) => | ||
| step.runWorkflow(updateDescriptionsSpec, { | ||
| graphId: input.graphId, | ||
| entityIds: [], | ||
| relationshipIds, | ||
| }) | ||
| ); | ||
|
|
||
| const results = await Promise.allSettled([...entityPromises, ...relationshipPromises]); | ||
| const failures = results.filter((r) => r.status === "rejected"); | ||
| if (failures.length > 0) { | ||
| throw new Error(`${failures.length} of ${results.length} description batches failed`); | ||
| } | ||
| } | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.