@@ -74,16 +74,20 @@ impl WorkTask {
7474 }
7575}
7676
77- let checkpoint_store = Arc :: new (RedbCheckpointStore :: new (" workflow.redb" )? );
78-
79- let workflow = Workflow :: bare ()
80- . register (Step :: Start , StartTask )
81- . register (Step :: Work , WorkTask )
82- . add_exit_state (Step :: Done )
83- . with_checkpoint_store (checkpoint_store )
84- . with_workflow_id (" run-42" );
85-
86- workflow . orchestrate (Step :: Start ). await ? ;
77+ #[tokio:: main]
78+ async fn main () -> Result <(), CanoError > {
79+ let checkpoint_store = Arc :: new (RedbCheckpointStore :: new (" workflow.redb" )? );
80+
81+ let workflow = Workflow :: bare ()
82+ . register (Step :: Start , StartTask )
83+ . register (Step :: Work , WorkTask )
84+ . add_exit_state (Step :: Done )
85+ . with_checkpoint_store (checkpoint_store )
86+ . with_workflow_id (" run-42" );
87+
88+ workflow . orchestrate (Step :: Start ). await ? ;
89+ Ok (())
90+ }
8791```
8892<hr class =" section-divider " >
8993
@@ -161,16 +165,20 @@ use cano::prelude::*;
161165use cano :: RedbCheckpointStore ;
162166use std :: sync :: Arc ;
163167
164- let checkpoint_store = Arc :: new (RedbCheckpointStore :: new (" workflow.redb" )? );
165- let workflow = Workflow :: bare ()
166- . register (Step :: Start , StartTask )
167- . register (Step :: Work , WorkTask )
168- . add_exit_state (Step :: Done )
169- . with_checkpoint_store (checkpoint_store );
170-
171- // Some earlier process crashed mid-run; pick up where it left off.
172- let final_state = workflow . resume_from (" run-42" ). await ? ;
173- assert_eq! (final_state , Step :: Done );
168+ #[tokio:: main]
169+ async fn main () -> Result <(), CanoError > {
170+ let checkpoint_store = Arc :: new (RedbCheckpointStore :: new (" workflow.redb" )? );
171+ let workflow = Workflow :: bare ()
172+ . register (Step :: Start , StartTask )
173+ . register (Step :: Work , WorkTask )
174+ . add_exit_state (Step :: Done )
175+ . with_checkpoint_store (checkpoint_store );
176+
177+ // Some earlier process crashed mid-run; pick up where it left off.
178+ let final_state = workflow . resume_from (" run-42" ). await ? ;
179+ assert_eq! (final_state , Step :: Done );
180+ Ok (())
181+ }
174182```
175183
176184<p >
@@ -414,27 +422,31 @@ impl FinalizeTask {
414422 }
415423}
416424
417- let checkpoint_store = Arc :: new (RedbCheckpointStore :: new (" recovery.redb" )? );
418- let resources = Resources :: new (). insert (" crash" , CrashOnce :: default ());
419- let workflow = Workflow :: new (resources )
420- . register (Step :: Start , StartTask )
421- . register (Step :: Process , ProcessTask )
422- . register (Step :: Finalize , FinalizeTask )
423- . add_exit_state (Step :: Done )
424- . with_checkpoint_store (checkpoint_store . clone ())
425- . with_workflow_id (" demo-run" );
426-
427- // Run 1: crashes inside ProcessTask. The Start and Process rows are already durable.
428- let _ = workflow . orchestrate (Step :: Start ). await ;
429-
430- // Run 2: resume — re-runs ProcessTask (now it succeeds) and finishes at Done.
431- let final_state = workflow . resume_from (" demo-run" ). await ? ;
432- assert_eq! (final_state , Step :: Done );
433-
434- // The append-only log: Start, Process (crash), Process (re-run), Finalize, Done —
435- // all RowKind::StateEntry here, since this workflow has no compensatable or stepped states.
436- for row in checkpoint_store . load_run (" demo-run" ). await ? {
437- println! (" #{} {:?} {} {}" , row . sequence, row . kind, row . state, row . task_id);
425+ #[tokio:: main]
426+ async fn main () -> Result <(), CanoError > {
427+ let checkpoint_store = Arc :: new (RedbCheckpointStore :: new (" recovery.redb" )? );
428+ let resources = Resources :: new (). insert (" crash" , CrashOnce :: default ());
429+ let workflow = Workflow :: new (resources )
430+ . register (Step :: Start , StartTask )
431+ . register (Step :: Process , ProcessTask )
432+ . register (Step :: Finalize , FinalizeTask )
433+ . add_exit_state (Step :: Done )
434+ . with_checkpoint_store (checkpoint_store . clone ())
435+ . with_workflow_id (" demo-run" );
436+
437+ // Run 1: crashes inside ProcessTask. The Start and Process rows are already durable.
438+ let _ = workflow . orchestrate (Step :: Start ). await ;
439+
440+ // Run 2: resume — re-runs ProcessTask (now it succeeds) and finishes at Done.
441+ let final_state = workflow . resume_from (" demo-run" ). await ? ;
442+ assert_eq! (final_state , Step :: Done );
443+
444+ // The append-only log: Start, Process (crash), Process (re-run), Finalize, Done —
445+ // all RowKind::StateEntry here, since this workflow has no compensatable or stepped states.
446+ for row in checkpoint_store . load_run (" demo-run" ). await ? {
447+ println! (" #{} {:?} {} {}" , row . sequence, row . kind, row . state, row . task_id);
448+ }
449+ Ok (())
438450}
439451```
440452</div >
0 commit comments