Skip to content

Commit d0f1fde

Browse files
committed
restore workflows
1 parent d8b8c39 commit d0f1fde

9 files changed

Lines changed: 335 additions & 78 deletions

File tree

packages/config/src/bindings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ export interface WorkerLoaderBinding {
606606
}
607607

608608
interface WorkflowBindingOptions {
609+
/** The user-chosen name of the Workflow. */
610+
name: string;
609611
/** The name of the Worker that defines the Workflow. */
610612
workerName: string;
611613
/** The exported class name of the Workflow. */

packages/config/src/convert.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,18 @@ function convertBindingsAndAssets(
561561
break;
562562
}
563563
// TODO: re-enable when workflow bindings return.
564-
// case "workflow": {
565-
// workflows.push(
566-
// omitUndefined({
567-
// binding: name,
568-
// class_name: binding.exportName,
569-
// script_name: binding.workerName,
570-
// remote: binding.remote,
571-
// })
572-
// );
573-
// break;
574-
// }
564+
case "workflow": {
565+
workflows.push(
566+
omitUndefined({
567+
binding: name,
568+
name: binding.name,
569+
class_name: binding.exportName,
570+
script_name: binding.workerName,
571+
remote: binding.remote,
572+
})
573+
);
574+
break;
575+
}
575576
}
576577
}
577578

packages/config/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export {
2323
UnsafeBindingSchema,
2424
WorkerBindingSchema,
2525
WorkerEntrypointExportSchema,
26+
WorkflowExportSchema,
2627
} from "./schema";
2728
export { generateTypes } from "./generate";
2829
export { convertToWranglerConfig } from "./convert";

packages/config/src/schema.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,14 @@ export const KnownBindingSchema = z.discriminatedUnion("type", [
201201
WorkerBindingSchema,
202202
z.strictObject({ type: z.literal("worker-loader") }),
203203
// TODO: support Workflows
204-
// z.strictObject({
205-
// type: z.literal("workflow"),
206-
// workerName: z.string(),
207-
// exportName: z.string(),
208-
// remote: z.boolean().optional(),
209-
// }),
204+
// (MAY HAVE TO REVERT PARTIALLY OR PRETEND IT IS A MINIFLARE ONLY BINDING)
205+
z.strictObject({
206+
type: z.literal("workflow"),
207+
name: z.string(),
208+
workerName: z.string(),
209+
exportName: z.string(),
210+
remote: z.boolean().optional(),
211+
}),
210212
]);
211213

212214
export const UnsafeBindingSchema = z.looseObject({
@@ -340,6 +342,14 @@ export const WorkerEntrypointExportSchema = z.strictObject({
340342
cache: z.strictObject({ enabled: z.boolean() }).optional(),
341343
});
342344

345+
// Exported for Miniflare's `MiniflareExportSchema`. Not yet added to the shared
346+
// `ExportSchema` union / public `Export` type — see "TODO: support Workflows".
347+
export const WorkflowExportSchema = z.strictObject({
348+
type: z.literal("workflow"),
349+
name: z.string(),
350+
limits: z.strictObject({ steps: z.number().optional() }).optional(),
351+
});
352+
343353
export const ExportSchema = z.union([
344354
DurableObjectCreatedExportSchema,
345355
DurableObjectDeletedExportSchema,
@@ -348,11 +358,6 @@ export const ExportSchema = z.union([
348358
DurableObjectExpectingTransferExportSchema,
349359
WorkerEntrypointExportSchema,
350360
// TODO: support Workflows
351-
// z.strictObject({
352-
// type: z.literal("workflow"),
353-
// name: z.string(),
354-
// limits: z.strictObject({ steps: z.number().optional() }).optional(),
355-
// }),
356361
]);
357362

358363
const LimitsSchema = z.strictObject({

packages/miniflare/src/config/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
UnsafeBindingSchema,
1313
WorkerBindingSchema,
1414
WorkerEntrypointExportSchema,
15+
WorkflowExportSchema,
1516
KVBindingSchema,
1617
D1BindingSchema,
1718
R2BindingSchema,
@@ -344,6 +345,7 @@ const MiniflareExportSchema = z.union([
344345
DurableObjectTransferredExportSchema,
345346
DurableObjectExpectingTransferExportSchema,
346347
WorkerEntrypointExportSchema,
348+
WorkflowExportSchema,
347349
]);
348350

349351
// ---------------------------------------------------------------------------

packages/miniflare/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
getExportsOfType,
4545
getGlobalServices,
4646
getPersistPath,
47+
getRemoteProxyConnectionString,
4748
getTriggersOfType,
4849
HELLO_WORLD_PLUGIN_NAME,
4950
HOST_CAPNP_CONNECT,
@@ -475,6 +476,21 @@ function getExternalServiceEntrypoints(allWorkerOpts: ParsedWorkerOptions[]) {
475476
getEntrypoints(workerName).classNames.add(exportName);
476477
}
477478
}
479+
480+
// Cross-worker workflow bindings: when `workerName` refers to a worker
481+
// outside this Miniflare instance (registered in the dev registry), record
482+
// its entrypoint so the dev-registry proxy exposes it. The workflows plugin
483+
// reroutes the engine's USER_WORKFLOW binding through the proxy itself; here
484+
// we only register the external entrypoint. Mirrors the DO block above.
485+
for (const [, binding] of getEnvBindingsOfType(config, "workflow")) {
486+
const { workerName, exportName } = binding;
487+
if (
488+
getRemoteProxyConnectionString(binding, dev) === undefined &&
489+
!allWorkerNames.includes(workerName)
490+
) {
491+
getEntrypoints(workerName).entrypoints.add(exportName);
492+
}
493+
}
478494
}
479495

480496
return externalServices;

packages/miniflare/src/plugins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const PLUGINS = {
6060
[HYPERDRIVE_PLUGIN_NAME]: HYPERDRIVE_PLUGIN,
6161
[RATELIMIT_PLUGIN_NAME]: RATELIMIT_PLUGIN,
6262
[ASSETS_PLUGIN_NAME]: ASSETS_PLUGIN,
63-
// [WORKFLOWS_PLUGIN_NAME]: WORKFLOWS_PLUGIN,
63+
[WORKFLOWS_PLUGIN_NAME]: WORKFLOWS_PLUGIN,
6464
[PIPELINES_PLUGIN_NAME]: PIPELINE_PLUGIN,
6565
[SECRET_STORE_PLUGIN_NAME]: SECRET_STORE_PLUGIN,
6666
[EMAIL_PLUGIN_NAME]: EMAIL_PLUGIN,

0 commit comments

Comments
 (0)