cpn_batch_processing

command
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 3 Imported by: 0

README

CPN Batch Processing Example

Demonstrates the Colored Petri Net (CPN) features of the workflow engine using a batch of orders that flow pending → processing → done. Each order is a token carrying its own data (id, amount).

Run it:

go run ./examples/cpn_batch_processing/

What it shows

Feature API
Seed data-carrying tokens wf.CreateTokens("pending", []workflow.TokenData{...})
Start a place from a clean slate wf.ClearPlace("pending")
Aggregate over a numeric field wf.AggregateTokens(nil, "amount")
Rewrite matching tokens' data wf.TransformTokens(place, pred, fn)
Advance one token out of a batch wf.ApplyTransitionForToken(ctx, "start", id)
Advance every token at once wf.ApplyTransition("start")
Read tokens at a place wf.GetTokens("done")

A plain (boolean) workflow is just the special case where places hold a single uncolored token — the same ApplyTransition calls work unchanged. See docs/guides/CPN_GUIDE.md for the full model.

Declarative equivalent

The same initial batch can be declared in YAML with initial_marking (its map form seeds colored tokens per place):

workflow:
  name: batch
  initial_marking:
    pending:
      - {id: "A", amount: 100}
      - {id: "B", amount: 250}
      - {id: "C", amount: 40}
  places: [{name: pending}, {name: processing}, {name: done}]
  transitions:
    - {name: start,  from: [pending],    to: [processing]}
    - {name: finish, from: [processing], to: [done]}

Documentation

Overview

Command cpn_batch_processing demonstrates Colored Petri Net (CPN) features of the workflow engine: data-carrying tokens, whole-batch and per-token firing, and token queries / aggregation / transformation.

The workflow models a batch of orders flowing pending -> processing -> done, where each order is a token carrying its own data (id, amount).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL