createRun method

  1. @override
Future<String> createRun({
  1. required String workflow,
  2. required Map<String, Object?> params,
  3. String? runId,
  4. String? parentRunId,
  5. Duration? ttl,
  6. WorkflowCancellationPolicy? cancellationPolicy,
})
override

Creates a new workflow run and returns its generated id.

Implementation

@override
/// Creates a new workflow run and returns its generated id.
Future<String> createRun({
  required String workflow,
  required Map<String, Object?> params,
  String? runId,
  String? parentRunId,
  Duration? ttl,
  WorkflowCancellationPolicy? cancellationPolicy,
}) async {
  final now = _clock.now();
  final id = (runId != null && runId.trim().isNotEmpty)
      ? runId.trim()
      : 'wf-${now.microsecondsSinceEpoch}-${_counter++}';
  if (_runs.containsKey(id)) {
    throw StateError('Workflow run "$id" already exists.');
  }
  _runs[id] = RunState(
    id: id,
    workflow: workflow,
    status: WorkflowStatus.running,
    cursor: 0,
    params: Map.unmodifiable(params),
    createdAt: now,
    updatedAt: now,
    suspensionData: const <String, Object?>{},
    cancellationPolicy: cancellationPolicy,
  );
  _steps[id] = {};
  return id;
}